Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/apoorvam/goterminal
A cross-platform Go-library for updating progress in terminal.
https://github.com/apoorvam/goterminal
color command-line cross-platform go golang progressbar terminal
Last synced: 28 days ago
JSON representation
A cross-platform Go-library for updating progress in terminal.
- Host: GitHub
- URL: https://github.com/apoorvam/goterminal
- Owner: apoorvam
- License: mit
- Created: 2015-12-12T03:11:44.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-03-12T21:48:30.000Z (almost 6 years ago)
- Last Synced: 2024-08-03T23:27:22.125Z (4 months ago)
- Topics: color, command-line, cross-platform, go, golang, progressbar, terminal
- Language: Go
- Size: 454 KB
- Stars: 58
- Watchers: 3
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-golang-repositories - goterminal - platform Go-library for updating progress in terminal. (Repositories)
README
# goterminal [![GoDoc](https://godoc.org/github.com/apoorvam/goterminal?status.svg)](https://godoc.org/github.com/apoorvam/goterminal)
A cross-platform Go-library for updating progress in terminal.## Installation
````
go get -u github.com/apoorvam/goterminal
````## Usage
```go
func main() {
// get an instance of writer
writer := goterminal.New()for i := 0; i < 100; i = i + 10 {
// add your text to writer's buffer
fmt.Fprintf(writer, "Downloading (%d/100) bytes...\n", i)
// write to terminal
writer.Print()
time.Sleep(time.Millisecond * 200)// clear the text written by previous write, so that it can be re-written.
writer.Clear()
}// reset the writer
writer.Reset()
fmt.Println("Download finished!")
}
```
## Example![output](doc/download_progress.gif)
Another example which uses the [go-colortext](github.com/daviddengcn/go-colortext) library to re-write text along with using colors. Here is output of example:
![output](doc/color_terminal.gif)
Examples can be found [here](https://github.com/apoorvam/goterminal/tree/master/examples).
### More on usage
* Create a `Writer` instance.
* Add your text to writer's buffer and call `Print()` to print text on Terminal. This can be called any number of times.
* Call `Clear()` to move the cursor to position where first `Print()` started so that it can be over-written.
* `Reset()` writer, so it clears its state for next Write.