uilive: github.com/gosuri/uilive Index | Examples | Files | Directories

package uilive

import "github.com/gosuri/uilive"

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

Code:

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

Index

Examples

Package Files

doc.go writer.go writer_posix.go

Constants

const ESC = 27

ESC is the ASCII code for escape character

Variables

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

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

var Out = os.Stdout

Out is the default output writer for the Writer

var RefreshInterval = time.Millisecond

RefreshInterval is the default refresh interval to update the ui

type FdWriter Uses

type FdWriter interface {
    io.Writer
    Fd() uintptr
}

FdWriter is a writer with a file descriptor.

type Writer Uses

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 is a buffered the writer that updates the terminal. The contents of writer will be flushed on a timed interval or when Flush is called.

func New Uses

func New() *Writer

New returns a new Writer with defaults

func (*Writer) Bypass Uses

func (w *Writer) Bypass() io.Writer

Bypass creates an io.Writer which allows non-buffered output to be written to the underlying output

func (*Writer) Flush Uses

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. An error is returned if the contents of the buffer cannot be written to the underlying output stream

func (*Writer) Listen Uses

func (w *Writer) Listen()

Listen listens for updates to the writer's buffer and flushes to the out provided. It blocks the runtime.

func (*Writer) Start Uses

func (w *Writer) Start()

Start starts the listener in a non-blocking manner

func (*Writer) Stop Uses

func (w *Writer) Stop()

Stop stops the listener that updates the terminal

func (*Writer) Write Uses

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

Write save the contents of b to its buffers. The only errors returned are ones encountered while writing to the underlying buffer.

Directories

PathSynopsis
example

Package uilive imports 7 packages (graph) and is imported by 29 packages. Updated 2017-03-24. Refresh now. Tools for package owners.