uilive

package module
v0.0.0-...-dc7a6ce Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2017 License: MIT Imports: 7 Imported by: 1

README

uilive GoDoc Build Status

uilive is a go library for updating terminal output in realtime. It provides a buffered io.Writer that you can flush when it is time.

This is an API-incompatible modified fork (original) that removes the timed interval ticker, so that you have full control of flushing lines to terminal.

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()

for _, f := range []string{"Foo.zip", "Bar.iso"} {
    for i := 0; i <= 50; i++ {
        fmt.Fprintf(writer, "Downloading %s.. (%d/%d) GB\n", f, i, 50)
        writer.Flush()
        time.Sleep(time.Millisecond * 70)
    }

    fmt.Fprintf(writer.Bypass(), "Downloaded %s\n", f)
}

fmt.Fprintln(writer, "Finished: Downloaded 100GB")

asciicast

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.

Example
package main

import (
	"fmt"
	"time"

	"github.com/henvic/uilive"
)

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

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

	fmt.Fprintln(writer.Bypass(), "Finished: Downloaded 100GB")
}

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 output writer for the Writer

Functions

This section is empty.

Types

type FdWriter

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

FdWriter is a writer with a file descriptor.

type Writer

type Writer struct {
	// Out is the writer to write to
	Out io.Writer
	// 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

func New() *Writer

New returns a new Writer with defaults

func (*Writer) Bypass

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

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) Write

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

Path Synopsis

Jump to

Keyboard shortcuts

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