view

package
v0.0.0-...-e2c65c2 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrStop = errors.New("client stop")

ErrStop may be returned by a client method to mean "we're done, break run loop".

Functions

func JustKeepRunning

func JustKeepRunning(factory func(v *View) (Client, error)) error

JustKeepRunning starts a view, and then running newly minted Runables provided by the given factory until an error occurs, or the user quits. Useful for implementing main.main.

Types

type Align

type Align uint8

Align specifies alignment to Layout placements.

const (
	// AlignLeft causes left horizontal alignment in a Layout.
	AlignLeft Align = 1 << iota
	// AlignRight causes right horizontal alignment in a Layout.
	AlignRight

	// AlignTop causes top vertical alignment in a Layout.
	AlignTop
	// AlignBottom causes bottom vertical alignment in a Layout.
	AlignBottom

	// AlignHFlush causes horizontal alignment to accept no offset; so it will
	// always get the "next empty row" in the relevant vertical direction.
	AlignHFlush

	// AlignCenter causes center horizontal alignment in a layout.
	AlignCenter = AlignLeft | AlignRight

	// AlignMiddle causes middle vertical alignment in a layout.
	AlignMiddle = AlignTop | AlignBottom
)

func (Align) String

func (a Align) String() string

type Client

type Client interface {
	Render(Grid) error
	HandleKey(KeyEvent) error
	Close() error
}

Client is the interface exposed to the user of View; its various methods are called in a loop that provides terminal orchestration.

type Grid

type Grid struct {
	Size point.Point
	Data []termbox.Cell
}

Grid represents a sized buffer of terminal cells.

func MakeGrid

func MakeGrid(sz point.Point) Grid

MakeGrid makes a new Grid with the given size.

func (Grid) Copy

func (g Grid) Copy(og Grid)

Copy copies another grid into this one, centered and clipped as necessary.

func (Grid) Get

func (g Grid) Get(x, y int) termbox.Cell

Get sets a cell in the grid.

func (Grid) Lines

func (g Grid) Lines(fillZero rune) []string

Lines returns a slice of row strings from the grid, filling in any zero runes with the given one.

func (Grid) Merge

func (g Grid) Merge(x, y int, ch rune, fg, bg termbox.Attribute)

Merge merges data into a cell in the grid.

func (*Grid) Resize

func (g *Grid) Resize(sz point.Point)

Resize update the grid size, growing Data capacity or truncating its length as needed.

func (Grid) Set

func (g Grid) Set(x, y int, ch rune, fg, bg termbox.Attribute)

Set sets a cell in the grid.

func (Grid) WriteString

func (g Grid) WriteString(x, y int, mess string, args ...interface{}) int

WriteString writes a string into the grid at the given position, returning how many cells were affected.

func (Grid) WriteStringRTL

func (g Grid) WriteStringRTL(x, y int, mess string, args ...interface{}) int

WriteStringRTL is like WriteString except it gose Right-To-Left (in both the string and the grid).

type KeyEvent

type KeyEvent struct {
	Mod termbox.Modifier
	Key termbox.Key
	Ch  rune
}

KeyEvent represents a terminal key event.

type Layout

type Layout struct {
	Grid
	// contains filtered or unexported fields
}

Layout places Renderables in a Grid, keeping track of used left/right/center space to inform future placements.

func (*Layout) Place

func (lay *Layout) Place(ren Renderable, align Align) LayoutPlacement

Place a Renderable into layout, returning false if the placement can't be done.

func (*Layout) Render

func (lay *Layout) Render(ren Renderable, align Align) LayoutPlacement

Render places and renders a Renderable if the placement succeeded.

type LayoutPlacement

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

LayoutPlacement represents a placement made by a Layout for a Renderable.

func MakeLayoutPlacement

func MakeLayoutPlacement(lay *Layout, ren Renderable) LayoutPlacement

MakeLayoutPlacement makes a new placement for the given layout and renderable; it records the wanted/needed render sizes, ready to attempt placement.

func (*LayoutPlacement) Render

func (plc *LayoutPlacement) Render()

Render renders the placement, if it has been resolved successfully.

func (*LayoutPlacement) Try

func (plc *LayoutPlacement) Try(align Align) bool

Try attempts to (re)resolve the placement with an other alignment.

type Renderable

type Renderable interface {
	RenderSize() (wanted, needed point.Point)
	Render(Grid)
}

Renderable is an element for Layout to place and maybe render; if its Render method is called, it will get a grid of at least the needed RenderSize.

func RenderString

func RenderString(mess string, args ...interface{}) Renderable

RenderString constructs a static string Renderable; either the entire string is rendered, or not; no truncation is supported.

type View

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

View implements a terminal user interaction, based around a grid, header, and footer. Additionally a log is provided, whose tail is displayed beneath the header.

func (*View) Run

func (v *View) Run(client Client) error

Run a Client under this view, returning any error from the run (may be caused by the client, or view).

Directories

Path Synopsis
hud

Jump to

Keyboard shortcuts

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