gogrid

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2017 License: MIT Imports: 4 Imported by: 1

README

gogrid

Interactive grid in the terminal

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTerminalTooSmall = errors.New("terminal too small")
	ErrKeyInUse         = errors.New("key already registered")
)

Common errors.

Functions

This section is empty.

Types

type Grid

type Grid struct {
	// Dimensions.
	Height int
	Width  int

	// Offset at the top of the screen.
	HeaderHeight int
	HeaderFct    func(*Grid)

	// Internal controls.
	StopChan <-chan struct{}
	// contains filtered or unexported fields
}

Grid holds the data for the terminal grid.

Sample output for a 2 rows 3 columns grid:

┌─┬─┬─┐
│ │ │ │
├─┼─┼─┤
│ │ │ │
└─┴─┴─┘

func NewGrid

func NewGrid(h, w int) (*Grid, error)

NewGrid initialize the terminal and the grid. Should be closed by the caller.

func (*Grid) ClearHeader

func (g *Grid) ClearHeader()

ClearHeader zero out the header and reset the cursor to 0,0.

func (*Grid) Close

func (g *Grid) Close() error

Close terminates the runtime loop.

func (*Grid) HandleKeyboard

func (g *Grid) HandleKeyboard() error

HandleKeyboard is the runtime loop monitoring keyboard activity.

func (*Grid) RedrawAll

func (g *Grid) RedrawAll() error

RedrawAll redraws the whole grid.

func (*Grid) RegisterKeyHandler

func (g *Grid) RegisterKeyHandler(key termbox.Key, fct func(*Grid)) *KeyHandler

RegisterKeyHandler adds a handler for the given key. Returns a pointer to the handler, needed to unregister.

func (*Grid) SetCursor

func (g *Grid) SetCursor(x, y int)

SetCursor sets the cursor at the proper place and flushes the terminal. x and y are Cells, not absolute.

func (*Grid) SetCursorOrigin

func (g *Grid) SetCursorOrigin()

SetCursorOrigin sets the cursor back to 0,0 to display the header.

func (*Grid) UnregisterKeyHandler

func (g *Grid) UnregisterKeyHandler(hdlr *KeyHandler)

UnregisterKeyHandler removes the given handler from the list. hdlr is returned by (*gogrid.Grid).RegisterKeyHandler.

type KeyHandler

type KeyHandler struct {
	Key termbox.Key
	Fct func(*Grid)
}

KeyHandler associates a key with a callback.

Jump to

Keyboard shortcuts

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