termdash: github.com/mum4k/termdash Index | Examples | Files | Directories

package termdash

import "github.com/mum4k/termdash"

Package termdash implements a terminal based dashboard.

While running, the terminal dashboard performs the following:

- Periodic redrawing of the canvas and all the widgets.
- Event based redrawing of the widgets (i.e. on Keyboard or Mouse events).
- Forwards input events to widgets and optional subscribers.
- Handles terminal resize events.

Example shows how to setup and run termdash with periodic redraw.

Code:

// Create the terminal.
t, err := termbox.New()
if err != nil {
    panic(err)
}
defer t.Close()

// Create some widgets.
bc, err := barchart.New()
if err != nil {
    panic(err)
}
g, err := gauge.New()
if err != nil {
    panic(err)
}

// Create the container with two widgets.
c, err := container.New(
    t,
    container.SplitVertical(
        container.Left(
            container.PlaceWidget(bc),
        ),
        container.Right(
            container.PlaceWidget(g),
        ),
        container.SplitPercent(30),
    ),
)
if err != nil {
    panic(err)
}

// Termdash runs until the context expires.
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := Run(ctx, t, c); err != nil {
    panic(err)
}

Example shows how to setup and run termdash with manually triggered redraw.

Code:

// Create the terminal.
t, err := termbox.New()
if err != nil {
    panic(err)
}
defer t.Close()

// Create a widget.
bc, err := barchart.New()
if err != nil {
    panic(err)
}

// Create the container with a widget.
c, err := container.New(
    t,
    container.PlaceWidget(bc),
)
if err != nil {
    panic(err)
}

// Create the controller and disable periodic redraw.
ctrl, err := NewController(t, c)
if err != nil {
    panic(err)
}
// Close the controller and termdash once it isn't required anymore.
defer ctrl.Close()

// Redraw the terminal manually.
if err := ctrl.Redraw(); err != nil {
    panic(err)
}

Index

Examples

Package Files

termdash.go

Constants

const DefaultRedrawInterval = 250 * time.Millisecond

DefaultRedrawInterval is the default for the RedrawInterval option.

func Run Uses

func Run(ctx context.Context, t terminalapi.Terminal, c *container.Container, opts ...Option) error

Run runs the terminal dashboard with the provided container on the terminal. Redraws the terminal periodically. If you prefer a manual redraw, use the Controller instead. Blocks until the context expires.

type Controller Uses

type Controller struct {
    // contains filtered or unexported fields
}

Controller controls a termdash instance. The controller instance is only valid until Close() is called. The controller is not thread-safe.

func NewController Uses

func NewController(t terminalapi.Terminal, c *container.Container, opts ...Option) (*Controller, error)

NewController initializes termdash and returns an instance of the controller. Periodic redrawing is disabled when using the controller, the RedrawInterval option is ignored. Close the controller when it isn't needed anymore.

func (*Controller) Close Uses

func (c *Controller) Close()

Close closes the Controller and its termdash instance.

func (*Controller) Redraw Uses

func (c *Controller) Redraw() error

Redraw triggers redraw of the terminal.

type Option Uses

type Option interface {
    // contains filtered or unexported methods
}

Option is used to provide options.

func ErrorHandler Uses

func ErrorHandler(f func(error)) Option

ErrorHandler is used to provide a function that will be called with all errors that occur while the dashboard is running. If not provided, any errors panic the application. The provided function must be thread-safe.

func KeyboardSubscriber Uses

func KeyboardSubscriber(f func(*terminalapi.Keyboard)) Option

KeyboardSubscriber registers a subscriber for Keyboard events. Each keyboard event is forwarded to the container and the registered subscriber. The provided function must be thread-safe.

func MouseSubscriber Uses

func MouseSubscriber(f func(*terminalapi.Mouse)) Option

MouseSubscriber registers a subscriber for Mouse events. Each mouse event is forwarded to the container and the registered subscriber. The provided function must be thread-safe.

func RedrawInterval Uses

func RedrawInterval(t time.Duration) Option

RedrawInterval sets how often termdash redraws the container and all the widgets. Defaults to DefaultRedrawInterval. Use the controller to disable the periodic redraw.

Directories

PathSynopsis
alignPackage align defines constants representing types of alignment.
cellPackage cell implements cell options and attributes.
containerPackage container defines a type that wraps other containers or widgets.
container/gridPackage grid helps to build grid layouts.
internal/areaPackage area provides functions working with image areas.
internal/canvas/braille/testbraillePackage testbraille provides helpers for tests that use the braille package.
internal/canvas/bufferPackage buffer implements a 2-D buffer of cells.
internal/canvas/testcanvasPackage testcanvas provides helpers for tests that use the canvas package.
internal/eventPackage event provides a non-blocking event distribution and subscription system.
internal/event/testeventPackage testevent provides utilities for tests that deal with concurrent events.
internal/fakewidgetPackage fakewidget implements a fake widget that is useful for testing the termdash infrastructure.
internal/numbersPackage numbers implements various numerical functions.
internal/segdispPackage segdisp provides utilities used by all segment display types.
internal/segdisp/sixteen/testsixteenPackage testsixteen provides helpers for tests that use the sixteen package.
internal/wrapPackage wrap implements line wrapping at character or word boundaries.
keyboardPackage keyboard defines well known keyboard keys and shortcuts.
linestylePackage linestyle defines various line styles.
mousePackage mouse defines known mouse buttons.
private/alignforPackage alignfor provides functions that align elements.
private/areaPackage area provides functions working with image areas.
private/attrrangePackage attrrange simplifies tracking of attributes that apply to a range of items.
private/buttonPackage button implements a state machine that tracks mouse button clicks.
private/canvasPackage canvas defines the canvas that the widgets draw on.
private/canvas/braillePackage braille provides a canvas that uses braille characters.
private/canvas/braille/testbraillePackage testbraille provides helpers for tests that use the braille package.
private/canvas/bufferPackage buffer implements a 2-D buffer of cells.
private/canvas/testcanvasPackage testcanvas provides helpers for tests that use the canvas package.
private/drawPackage draw provides functions that draw lines, shapes, etc on 2-D terminal like canvases.
private/draw/testdrawPackage testdraw provides helpers for tests that use the draw package.
private/eventPackage event provides a non-blocking event distribution and subscription system.
private/event/eventqueuePackage eventqueue provides an unboud FIFO queue of events.
private/event/testeventPackage testevent provides utilities for tests that deal with concurrent events.
private/faketermPackage faketerm is a fake implementation of the terminal for the use in tests.
private/fakewidgetPackage fakewidget implements a fake widget that is useful for testing the termdash infrastructure.
private/numbersPackage numbers implements various numerical functions.
private/numbers/trigPackage trig implements various trigonometrical calculations.
private/runewidthPackage runewidth is a wrapper over github.com/mattn/go-runewidth which gives different treatment to certain runes with ambiguous width.
private/segdispPackage segdisp provides utilities used by all segment display types.
private/segdisp/dotsegPackage dotseg simulates a segment display that can draw dots.
private/segdisp/segmentPackage segment provides functions that draw a single segment.
private/segdisp/segment/testsegmentPackage testsegment provides helpers for tests that use the segment package.
private/segdisp/sixteenPackage sixteen simulates a 16-segment display drawn on a canvas.
private/segdisp/sixteen/testsixteenPackage testsixteen provides helpers for tests that use the sixteen package.
private/wrapPackage wrap implements line wrapping at character or word boundaries.
termdashdemoBinary termdashdemo demonstrates the functionality of termdash and its various widgets.
terminal/tcell
terminal/termboxPackage termbox implements terminal using the nsf/termbox-go library.
terminal/terminalapiPackage terminalapi defines the API of all terminal implementations.
widgetapiPackage widgetapi defines the API of a widget on the dashboard.
widgets/barchartPackage barchart implements a widget that draws multiple bars displaying values and their relative ratios.
widgets/barchart/barchartdemoBinary barchartdemo displays a couple of BarChart widgets.
widgets/buttonPackage button implements an interactive widget that can be pressed to activate.
widgets/button/buttondemoBinary buttondemo shows the functionality of a button widget.
widgets/donutPackage donut is a widget that displays the progress of an operation as a partial or full circle.
widgets/donut/donutdemoBinary donutdemo displays a couple of Donut widgets.
widgets/gaugePackage gauge implements a widget that displays the progress of an operation.
widgets/gauge/gaugedemoBinary gaugedemo displays a couple of Gauge widgets.
widgets/linechartPackage linechart contains a widget that displays line charts.
widgets/linechart/internal/axesPackage axes calculates the required layout and draws the X and Y axes of a line chart.
widgets/linechart/internal/zoomPackage zoom contains code that tracks the current zoom level.
widgets/linechart/linechartdemoBinary linechartdemo displays a linechart widget.
widgets/segmentdisplayPackage segmentdisplay is a widget that displays text by simulating a segment display.
widgets/segmentdisplay/segmentdisplaydemoBinary segmentdisplaydemo shows the functionality of a segment display.
widgets/sparklinePackage sparkline is a widget that draws a graph showing a series of values as vertical bars.
widgets/sparkline/sparklinedemoBinary sparklinedemo displays a couple of SparkLine widgets.
widgets/textPackage text contains a widget that displays textual data.
widgets/textinputPackage textinput implements a widget that accepts text input.
widgets/textinput/textinputdemoBinary textinputdemo shows the functionality of a text input field.
widgets/text/textdemoBinary textdemo displays a couple of Text widgets.

Package termdash imports 8 packages (graph) and is imported by 14 packages. Updated 2020-04-11. Refresh now. Tools for package owners.