uilive

package module
v0.0.0-...-29d637c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2015 License: MIT Imports: 8 Imported by: 0

README

uilive GoDoc

uilive is a go library for updating terminal output in realtime. It provides a buffered io.Writer that is flushed at a timed interval. uilive powers uiprogress. It works for posix and Windows too!

Usage Example

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.

writer := uilive.New()
// start listening for updates and render
writer.Start()

for i := 0; i <= 100; i++ {
  fmt.Fprintf(writer, "Downloading.. (%d/%d) GB\n", i, 100)
  time.Sleep(time.Millisecond * 5)
}

fmt.Fprintln(writer, "Finished: Downloaded 100GB")
writer.Stop() // flush and stop rendering

The above will render

example

Installation

$ go get -v github.com/gosuri/uilive

Documentation

Overview

Package uilive provides a writer that live updates the terminal. It provides a buffered io.Writer that is flushed at a timed interval.

Package uilive provides a writer that updates the UI

Example
package main

import (
	"fmt"
	"time"

	"github.com/gosuri/uilive"
)

func main() {
	writer := uilive.New()

	// start listening to updates and render
	writer.Start()

	for i := 0; i <= 100; i++ {
		fmt.Fprintf(writer, "Downloading.. (%d/%d) GB\n", i, 100)
		time.Sleep(time.Millisecond * 5)
	}

	fmt.Fprintln(writer, "Finished: Downloaded 100GB")
	writer.Stop() // flush and stop rendering
}
Output:

Index

Examples

Constants

View Source
const ESC = 27

ESC is the ASCII code for escape character

Variables

View Source
var ErrClosedPipe = errors.New("uilive: read/write on closed pipe")

ErrClosedPipe is the error returned when trying to writer is not listening

View Source
var Out = os.Stdout

Out is the default out for the writer

View Source
var RefreshInterval = time.Millisecond

RefreshInterval is the default refresh interval to update the ui

Functions

This section is empty.

Types

type Writer

type Writer struct {
	// Out is the writer to write to
	Out io.Writer

	// RefreshInterval is the time the UI sould refresh
	RefreshInterval time.Duration
	// contains filtered or unexported fields
}

Writer represent the writer that updates the UI

func New

func New() *Writer

New returns a new writer with defaults

func (*Writer) Flush

func (w *Writer) Flush() error

Flush writes to the out and resets the buffer. It should be called after the last call to Write to ensure that any data buffered in the Writer is written to output. Any incomplete escape sequence at the end is considered complete for formatting purposes.

func (*Writer) Listen

func (w *Writer) Listen()

Listen listens for updates to the writers buffer and flushes to the out. It blocks the runtime.

func (*Writer) Start

func (w *Writer) Start()

Start starts the listener in a non blocking manner

func (*Writer) Stop

func (w *Writer) Stop()

Stop stops the listener that updates the UI

func (*Writer) Wait

func (w *Writer) Wait()

Wait waits for the writer to finish writing

func (*Writer) Write

func (w *Writer) Write(buf []byte) (n int, err error)

Write writes buf to the writer b. The only errors returned are ones encountered while writing to the underlying output stream.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL