]> Cypherpunks.ru repositories - nncp.git/blob - src/uilive/README.md
Operations progress
[nncp.git] / src / uilive / README.md
1 # uilive [![GoDoc](https://godoc.org/github.com/gosuri/uilive?status.svg)](https://godoc.org/github.com/gosuri/uilive) [![Build Status](https://travis-ci.org/gosuri/uilive.svg?branch=master)](https://travis-ci.org/gosuri/uilive)
2
3 uilive is a go library for updating terminal output in realtime. It provides a buffered [io.Writer](https://golang.org/pkg/io/#Writer) that is flushed at a timed interval. uilive powers [uiprogress](https://github.com/gosuri/uiprogress).
4
5 ## Usage Example
6
7 Calling `uilive.New()` will create a new writer. To start rendering, simply call `writer.Start()` and update the ui by writing to the `writer`. Full source for the below example is in [example/main.go](example/main.go).
8
9 ```go
10 writer := uilive.New()
11 // start listening for updates and render
12 writer.Start()
13
14 for i := 0; i <= 100; i++ {
15   fmt.Fprintf(writer, "Downloading.. (%d/%d) GB\n", i, 100)
16   time.Sleep(time.Millisecond * 5)
17 }
18
19 fmt.Fprintln(writer, "Finished: Downloaded 100GB")
20 writer.Stop() // flush and stop rendering
21 ```
22
23 The above will render
24
25 ![example](doc/example.gif)
26
27 ## Installation
28
29 ```sh
30 $ go get -v github.com/gosuri/uilive
31 ```