fractal

package module
v0.0.0-...-842edb8 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2019 License: MIT Imports: 7 Imported by: 0

README

Fractal

Fractal is a simple library for writing text-based user interfaces. It builds upon Termbox to provide a data model that is simple yet sufficiently expressive to implement classic UNIX TUI programs like less or vi.

Installation

Install and update this go package with go get -u github.com/ernestrc/fractal.

Examples

For examples of how to use some of the provided building blocks, see the ./examples folder. You can compile them by running make, which will compile each of the examples into a running executable in the ./bin folder.

Documentation

See https://godoc.org/github.com/ernestrc/fractal.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close()

Close should be called when this library is not required anynmore.

func Init

func Init() error

Init initializes this library. This function should be called before any other functions. 'Close' must be called at the end to ensure graceful shutdown.

func NewTileTree

func NewTileTree(content Component) (t *TileTree, n *TileNode)

NewTileTree allocates storage for a new TileTree and initializes it. It also returns the TileNode allocated to store the given content.

func Run

func Run(root Handler) (err error)

Run takes the given root handler, renders it full-screen, and starts feeding it with termbox Events. Error is non-nil if there were any errors.

func RunMode

func RunMode(root Handler, mode termbox.InputMode) (err error)

RunMode runs the given root handler with the given termbox InputMode. See Run for more information.

func SetAttr

func SetAttr(fg, bg, highlightfg, highlightbg termbox.Attribute)

SetAttr sets the global foreground and background attributes.

func Size

func Size() (width int, height int)

Size returns the total available width and height in the current terminal.

Types

type Buffer

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

A Buffer is a variable-sized matrix of cells. The zero value for Buffer is ready to use.

func (*Buffer) ConflateRow

func (b *Buffer) ConflateRow(i int) (ok bool)

ConflateRow will conflate row at index i with the next row

func (*Buffer) Init

func (b *Buffer) Init(tabspaces int)

Init initializes this Buffer with the given tabspaces config and resets its contents.

func (*Buffer) InsertAt

func (b *Buffer) InsertAt(pos Coordinates, r rune) Coordinates

InsertAt inserts a rune in the given position and shift the cells to the right

func (*Buffer) InsertRowAt

func (b *Buffer) InsertRowAt(i int)

InsertRowAt inserts a new row at given position. If pos is out of bounds, this method does not panic; instead, it will fill in the necessary rows such that the new row is the last row in the buffer.

func (*Buffer) RawCells

func (b *Buffer) RawCells() [][]termbox.Cell

RawCells gives clients access to the underlying cell matrix.

func (*Buffer) ReadFrom

func (b *Buffer) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads data from r until EOF and appends it to the buffer, growing the buffer as needed. The return value n is the number of bytes read. Any error except io.EOF encountered during the read is also returned.

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset resets the contents of this cellbuf.

func (*Buffer) ResetAttr

func (b *Buffer) ResetAttr()

ResetAttr resets all the attributes of the underlying cell matrix.

func (*Buffer) RowLastIdx

func (b *Buffer) RowLastIdx(y int) (x int, ok bool)

RowLastIdx returns the width of row i.

func (*Buffer) RowLen

func (b *Buffer) RowLen(i int) (j int, ok bool)

RowLen returns the number of cells of row at index i

func (*Buffer) Rows

func (b *Buffer) Rows() int

Rows returns the number of rows in the buffer

func (*Buffer) Select

func (b *Buffer) Select(from Coordinates, to Coordinates) (res [][]termbox.Cell)

Select returns the cells inside the given coordinates or nil if coordinates are out of bounds.

func (*Buffer) SelectBlock

func (b *Buffer) SelectBlock(from Coordinates, to Coordinates) (res [][]termbox.Cell)

SelectBlock returns the block of cells inside the given coordinates or nil if coordinates are out of bounds.

func (*Buffer) SelectLine

func (b *Buffer) SelectLine(from Coordinates, to Coordinates) (res [][]termbox.Cell)

SelectLine returns the lines inside the given coordinates or nil if coordinates are out of bounds.

func (*Buffer) SetAttr

func (b *Buffer) SetAttr(pos Coordinates, fg, bg termbox.Attribute)

SetAttr overwrites the background and foreground attributes of cell at position.

func (*Buffer) String

func (b *Buffer) String() string

func (*Buffer) TruncateCellAt

func (b *Buffer) TruncateCellAt(pos Coordinates) (orig termbox.Cell, n int)

TruncateCellAt truncates the cell at the given position. It returns the cell truncated along with the number of cells truncated because if a tab cell was truncated the tab padding is truncated along with it.

func (*Buffer) TruncateFrom

func (b *Buffer) TruncateFrom(pos Coordinates) (ok bool)

TruncateFrom truncates from the given position to the end of the buffer.

func (*Buffer) TruncateLastRow

func (b *Buffer) TruncateLastRow()

TruncateLastRow truncates the last row in the buffer

func (*Buffer) TruncateRowAt

func (b *Buffer) TruncateRowAt(i int) (ok bool)

TruncateRowAt truncates the row at Coordinates.Y

func (*Buffer) TruncateRowFrom

func (b *Buffer) TruncateRowFrom(pos Coordinates) (ok bool)

TruncateRowFrom truncates the row at Coordinates.Y starting from Coordinates.X

func (*Buffer) WriteAt

func (b *Buffer) WriteAt(pos Coordinates, r rune)

WriteAt overwrites the cell at the given position with rune

func (*Buffer) WriteRune

func (b *Buffer) WriteRune(r rune) Coordinates

WriteRune writes the given rune at the end of the buffer

func (*Buffer) WriteString

func (b *Buffer) WriteString(p string) Coordinates

WriteString writes the given string at the end of the buffer

type Component

type Component interface {
	Resize(width, height int)
	Draw(Writer) error
}

Component represents an element that can be drawn in a text-based user interface. It wraps the basic Draw and Resize methods.

Draw draws this component to the underlying Writer. It returns non-nil error if something went wrong in the process of writing or the writer returned an error.

Resize is used by clients to indicate what's the virtual space available for this component to be drawn in subsequent calls to Draw. When a component is initialized, its width and height is 0 until Resize is called to set the appropiate dimensions.

type Coordinates

type Coordinates struct {
	X, Y int
}

Coordinates represent a point in a 2-D space.

type Frame

type Frame struct {
	Fg, Bg termbox.Attribute
	// contains filtered or unexported fields
}

Frame is a Component that simply draws a border around a nested component.

func NewFrame

func NewFrame(content Component, fg, bg termbox.Attribute) (f *Frame)

NewFrame allocates storage and initializes a new frame with the given border attributes and underlying component.

func (*Frame) Content

func (f *Frame) Content() Component

Content returns the underlying Component.

func (*Frame) ContentPosition

func (f *Frame) ContentPosition() Coordinates

ContentPosition returns the position of the content inside this frame.

func (*Frame) Draw

func (f *Frame) Draw(w Writer) (err error)

Draw draws this frame's border and contents to the given Writer.

func (*Frame) Init

func (f *Frame) Init(content Component, fg, bg termbox.Attribute)

Init initializes this frame with the given Component and border attributes.

func (*Frame) Resize

func (f *Frame) Resize(width, height int)

Resize updates this frame with a new width and height. If width or height is smaller than 3 cells, the border will not be drawn.

func (*Frame) SetAttr

func (f *Frame) SetAttr(fg, bg termbox.Attribute)

SetAttr updates the border attributes of this Frame.

func (*Frame) SetContent

func (f *Frame) SetContent(content Component) (err error)

SetContent updates the underlying component and resizes it to conform to this frame's width and height.

type FrameProxy

type FrameProxy struct {
	Frame
	// contains filtered or unexported fields
}

FrameProxy is a proxy handler that simply draws a frame around the underlying handler.

func NewFrameProxy

func NewFrameProxy(handler Handler, fg, bg termbox.Attribute) (f *FrameProxy)

NewFrameProxy allocates storage for a new FrameProxy and initializes it.

func (*FrameProxy) GetCursor

func (f *FrameProxy) GetCursor() (pos Coordinates)

GetCursor returns the underlying handler's cursor position with the frame offset.

func (*FrameProxy) Handle

func (f *FrameProxy) Handle(ev termbox.Event) bool

Handle delegates the event to the underlying handler.

func (*FrameProxy) Init

func (f *FrameProxy) Init(handler Handler, fg, bg termbox.Attribute)

Init initializes this FrameProxy with the given underlying handler and frame attributes.

func (*FrameProxy) Man

func (f *FrameProxy) Man() Manual

Man just delegates Man call to underlying handler.

type Handler

type Handler interface {
	Component
	Handle(termbox.Event) bool
	GetCursor() Coordinates
	Man() Manual
}

Handler builds upon Component to add event-handling behavior. It wraps the basic Handle, GetCursor and Man methods.

Handle represents the ability to handle termbox events. These events could be key presses or other types of events. See termbox' documentation for more information. Handle returns true if a handler is done processing events.

GetCursor returns a handler's cursor coordinates. Clients can have multiple handlers in the same interface so this method will be called only when handler is in focus.

Man returns a Handler's usage manual. See Manual for more information.

func WithMapping

func WithMapping(inner Handler, mappings map[termbox.Event]termbox.Event) Handler

WithMapping takes a handler and a set of event mappings to provide key and event mapping to override default handler event handler.

type KeyMap

type KeyMap map[termbox.Event]struct {
	ID          string
	Description string
}

KeyMap represents a Handler's key mapping information in the Manual.

type Less

type Less struct {
	*Scroll
	// contains filtered or unexported fields
}

Less is a clone of Unix' less program.

func NewLess

func NewLess() *Less

NewLess allocates storage and returns a new instance of Less.

func (*Less) Draw

func (l *Less) Draw(w Writer) (err error)

Draw : Component

func (*Less) GetCursor

func (l *Less) GetCursor() Coordinates

GetCursor : Handler

func (*Less) Handle

func (l *Less) Handle(ev termbox.Event) (exit bool)

Handle : Handler

func (*Less) Init

func (l *Less) Init()

Init initializes this instance or resets it if already initialized.

func (*Less) InitWithConfig

func (l *Less) InitWithConfig(cfg *LessConfig)

InitWithConfig will initialize a less handler. If config is nil this method will panic.

func (*Less) Man

func (l *Less) Man() Manual

Man : Handler

func (*Less) Mode

func (l *Less) Mode() LessMode

Mode returns the current LessMode.

func (*Less) Reset

func (l *Less) Reset()

Reset resets the contents and state of this instance.

func (*Less) Resize

func (l *Less) Resize(width, height int)

Resize : Component

func (*Less) SetContent

func (l *Less) SetContent(text string, args ...interface{})

SetContent replaces the content of the underlying scroll with 'text'.

func (*Less) SetMessage

func (l *Less) SetMessage(text string, args ...interface{})

SetMessage sets a message to be displayed on the bottom right corner.

func (*Less) SetScroll

func (l *Less) SetScroll(s *Scroll) (orig *Scroll)

SetScroll swaps the main scroll for s and returns the original scroll.

type LessConfig

type LessConfig struct {
	Tabspaces int
	Wrap      bool
	ResFG     termbox.Attribute
	ResBG     termbox.Attribute
	Handler   func(LessEvent)
}

LessConfig holds configuration values for a Less instance.

func DefaultLessConfig

func DefaultLessConfig() *LessConfig

DefaultLessConfig returns sane configuration defaults for a less instance.

type LessEvent

type LessEvent struct {
	Type LessEventType
	Data []byte
	Err  error
}

LessEvent type represents a less event.

type LessEventType

type LessEventType uint8

LessEventType represents a less event

const (
	// EOF is dispatched when user has reached end of buffer
	EOF LessEventType = iota
	// Search is dispatched when user has performed a text search
	// `Data` field in `Event` struct will be set to the search text
	Search
)

type LessMode

type LessMode uint8

LessMode represents one of the two modes of a less Handler. See Manual for more information on how to switch between modes.

const (
	LessNormalMode LessMode = iota
	LessSearchMode
)

type List

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

List represents a list of VirtualComponent which are drawn each one in series as a separate row.

func NewList

func NewList(elementHeight int) (l *List)

NewList allocates storage for a new List and initializes it.

func (*List) Back

func (l *List) Back() *list.Element

Back returns the last element of list l or nil if the list is empty.

func (*List) CanSeekDown

func (l *List) CanSeekDown() bool

CanSeekDown returns whether SeekUp would seek one row down.

func (*List) CanSeekUp

func (l *List) CanSeekUp() bool

CanSeekUp returns whether SeekUp would seek one row up.

func (*List) Draw

func (l *List) Draw(w Writer) (err error)

Draw draws this list's elements with the current seek offset.

func (*List) ElementHeight

func (l *List) ElementHeight() int

ElementHeight returns the height for each element of this list.

func (*List) Front

func (l *List) Front() *list.Element

Front returns the first element of list l or nil if the list is empty.

func (*List) Init

func (l *List) Init(elementHeight int)

Init initializes this List.

func (*List) InsertAfter

func (l *List) InsertAfter(v *VirtualComponent, mark *list.Element) *list.Element

InsertAfter inserts a new element e with value v immediately after mark and returns e. If mark is not an element of l, the list is not modified. The mark must not be nil.

func (*List) InsertBefore

func (l *List) InsertBefore(v *VirtualComponent, mark *list.Element) *list.Element

InsertBefore inserts a new element e with value v immediately before mark and returns e. If mark is not an element of l, the list is not modified. The mark must not be nil.

func (*List) Len

func (l *List) Len() int

Len returns the number of elements of list l. The complexity is O(1).

func (*List) MoveAfter

func (l *List) MoveAfter(e, mark *list.Element)

MoveAfter moves element e to its new position after mark. If e or mark is not an element of l, or e == mark, the list is not modified. The element and mark must not be nil.

func (*List) MoveBefore

func (l *List) MoveBefore(e, mark *list.Element)

MoveBefore moves element e to its new position before mark. If e or mark is not an element of l, or e == mark, the list is not modified. The element and mark must not be nil.

func (*List) MoveToBack

func (l *List) MoveToBack(e *list.Element)

MoveToBack moves element e to the back of list l. If e is not an element of l, the list is not modified. The element must not be nil.

func (*List) MoveToFront

func (l *List) MoveToFront(e *list.Element)

MoveToFront moves element e to the front of list l. If e is not an element of l, the list is not modified. The element must not be nil.

func (*List) PushBack

func (l *List) PushBack(v *VirtualComponent) *list.Element

PushBack inserts a new element e with value v at the back of list l and returns e.

func (*List) PushBackList

func (l *List) PushBackList(other *List)

PushBackList inserts a copy of an other list at the back of list l. The lists l and other must NOT be the same or nil.

func (*List) PushFront

func (l *List) PushFront(v *VirtualComponent) *list.Element

PushFront inserts a new element e with value v at the front of list l and returns e.

func (*List) PushFrontList

func (l *List) PushFrontList(other *List)

PushFrontList inserts a copy of an other list at the front of list l. The lists l and other must NOT be the same or nil.

func (*List) Remove

func (l *List) Remove(e *list.Element) *VirtualComponent

Remove removes e from l if e is an element of list l. It returns the element value e.Value. The element must not be nil.

func (*List) Reset

func (l *List) Reset()

Reset resets the contents of this List.

func (*List) Resize

func (l *List) Resize(width, height int)

Resize resizes this list to fit within width and height.

func (*List) SeekDown

func (l *List) SeekDown()

SeekDown shifts the contents of this list one row down.

func (*List) SeekEnd

func (l *List) SeekEnd()

SeekEnd shifts the contents of this list such that the last element is drawn at the top of the list.

func (*List) SeekStart

func (l *List) SeekStart()

SeekStart shifts the contents of this list such that the first element is drawn at the top f the list.

func (*List) SeekUp

func (l *List) SeekUp()

SeekUp shifts the contents of this list one row up.

func (*List) SetElementHeight

func (l *List) SetElementHeight(height int)

SetElementHeight sets the height for each element of this list.

type Manual

type Manual struct {
	Summary string
	Keys    KeyMap
}

Manual represents a handler's instruction manual and other useful information to be displayed in a text-based user interface.

type Scroll

type Scroll struct {
	Buffer

	ResultsFG termbox.Attribute // foreground attribute for search results
	ResultsBG termbox.Attribute // background attribute for search results
	Wrap      bool              // lines longer than the width of the window will wrap and displaying continues on the next line. wrap text
	// contains filtered or unexported fields
}

Scroll adds Draw to a Buffer along with scrolling, searching and wrap-around capabilities.

func NewScroll

func NewScroll() (s *Scroll)

NewScroll allocates storage for a Scroll and initializes it.

func (*Scroll) CanSeekDown

func (s *Scroll) CanSeekDown() bool

CanSeekDown returns true if SeekDown would seek one row down.

func (*Scroll) CanSeekLeft

func (s *Scroll) CanSeekLeft() bool

CanSeekLeft returns true if SeekLeft would seek one column left.

func (*Scroll) CanSeekRight

func (s *Scroll) CanSeekRight() bool

CanSeekRight returns true if SeekRight would seek one column right.

func (*Scroll) CanSeekUp

func (s *Scroll) CanSeekUp() bool

CanSeekUp returns true if SeekUp would seek one row up.

func (*Scroll) Draw

func (s *Scroll) Draw(writer Writer) (err error)

Draw draws the contents of this scroll to the given writer. If Wrap is set, lines that are too long to be rendered will wrap around and thus be rendered in the next line.

func (*Scroll) Init

func (s *Scroll) Init(tabspaces int)

Init initializes this scroll's internal cell buffer.

func (*Scroll) NextResult

func (s *Scroll) NextResult() (pos Coordinates, ok bool)

NextResult returns the coordinates of the next result in the Search list.

func (*Scroll) Offset

func (s *Scroll) Offset() Coordinates

Offset returns the scroll offset from the start of the content.

func (*Scroll) PrevResult

func (s *Scroll) PrevResult() (pos Coordinates, ok bool)

PrevResult returns the coordinates of the previous result in the Search list.

func (*Scroll) Reset

func (s *Scroll) Reset()

Reset resets this scroll's state and its contents.

func (*Scroll) Resize

func (s *Scroll) Resize(width, height int)

Resize resizes this scroll to fit inside given width and height.

func (*Scroll) Result

func (s *Scroll) Result() (pos Coordinates, ok bool)

Result returns the current search result's coordinates.

func (*Scroll) Search

func (s *Scroll) Search(text string) int

Search performs a text search of text in the internal cell buffer. It populates a search list so SeekNextResult and SeekPreviousResult can be used to visualize results. It returns the number of matches found.

func (*Scroll) SeekDown

func (s *Scroll) SeekDown() (ok bool)

SeekDown shifts the contents of this scroll one row down.

func (*Scroll) SeekEndFile

func (s *Scroll) SeekEndFile() bool

SeekEndFile shifts the contents of this scroll to the maximum y offset.

func (*Scroll) SeekEndLine

func (s *Scroll) SeekEndLine() bool

SeekEndLine shifts the contents of this scroll to the maximum x offset.

func (*Scroll) SeekHorizontal

func (s *Scroll) SeekHorizontal(x int) (ok bool)

SeekHorizontal shifts the contents of this scroll such that the horizontal offset is x. If x is out of bounds the contents will be shifted to the maximum possible x offset.

func (*Scroll) SeekLeft

func (s *Scroll) SeekLeft() (ok bool)

SeekLeft shifts the contents of this scroll one column left.

func (*Scroll) SeekNextResult

func (s *Scroll) SeekNextResult() bool

SeekNextResult shifts the contents of this scroll to visualize the next result in the result list.

func (*Scroll) SeekPrevResult

func (s *Scroll) SeekPrevResult() bool

SeekPrevResult shifts the contents of this scroll to visualize the previous result in the result list.

func (*Scroll) SeekRight

func (s *Scroll) SeekRight() (ok bool)

SeekRight shifts the contents of this scroll one column right.

func (*Scroll) SeekStartFile

func (s *Scroll) SeekStartFile() bool

SeekStartFile shifts the contents of this scroll to the minimum y offset.

func (*Scroll) SeekStartLine

func (s *Scroll) SeekStartLine() bool

SeekStartLine shifts the contents of this scroll to the minimum x offset.

func (*Scroll) SeekTo

func (s *Scroll) SeekTo(pos Coordinates) bool

SeekTo shifts the contents of this scroll such that the offset is exactly at given coordinates.

func (*Scroll) SeekUp

func (s *Scroll) SeekUp() (ok bool)

SeekUp shifts the contents of this scroll one row up.

func (*Scroll) SeekVertical

func (s *Scroll) SeekVertical(y int) (ok bool)

SeekVertical shifts the contents of this scroll such that the vertical offset is y. If y is out of bounds the contents will be shifted to the maximum possible y offset.

type TileNode

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

TileNode represents a node in a tree of tiled components.

func (*TileNode) Close

func (t *TileNode) Close()

Close removes this node from the tree. It panics if node is last node on the tree.

func (*TileNode) Content

func (t *TileNode) Content() Component

Content returns the Component held by this TileNode in the TileTree.

func (*TileNode) Draw

func (t *TileNode) Draw(w Writer) (err error)

Draw : Component

func (*TileNode) Resize

func (t *TileNode) Resize(width, height int)

Resize : Component

func (*TileNode) Size

func (t *TileNode) Size() (size int)

Size returns the total number of nodes under this TileNode.

func (*TileNode) TileDown

func (t *TileNode) TileDown() *TileNode

TileDown returns the tile in the bottom of t or nil if t is the bottom-most tile in the tree.

func (*TileNode) TileLeft

func (t *TileNode) TileLeft() *TileNode

TileLeft returns the tile left-adjacent to t or nil if t is the left-most tile in the tree.

func (*TileNode) TileRight

func (t *TileNode) TileRight() *TileNode

TileRight returns the tile right-adjacent to t or nil if t is the right-most tile in the tree.

func (*TileNode) TileUp

func (t *TileNode) TileUp() *TileNode

TileUp returns the tile on top of t or nil if t is the top-most tile in the tree.

type TileTree

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

TileTree represents the root node of a tree of TileNodes.

func (*TileTree) Draw

func (t *TileTree) Draw(w Writer) error

Draw draws the contents of this TileTree.

func (*TileTree) Init

func (t *TileTree) Init(content Component) (n *TileNode)

Init initializes a TileTree or resets it if already initialied.

func (*TileTree) Resize

func (t *TileTree) Resize(width, height int)

Resize resizes the contents of this TileTree.

func (*TileTree) Size

func (t *TileTree) Size() (size int)

Size returns the total number of nodes in this tree.

func (*TileTree) SplitHorizontal

func (t *TileTree) SplitHorizontal(node *TileNode, content Component) *TileNode

SplitHorizontal splits the given node to incorporate new content. If direction of the given node's split is horizontal, a new node with content will be added as a sibling of node. Otherwise, a new node will become a child of the given node so height will be divided in half so new node can be drawn next to it. It panics if node is a child of this TileTree.

func (*TileTree) SplitVertical

func (t *TileTree) SplitVertical(node *TileNode, content Component) *TileNode

SplitVertical splits the given node to incorporate new content. If direction of the given node's split is vertical, a new node with content will be added as a sibling of node. Otherwise, a new node with content will become a child of the given node so width will be divided in half so new node can be drawn next to it. It panics if node is a child of this TileTree.

func (*TileTree) TilePosition

func (t *TileTree) TilePosition(tile *TileNode) Coordinates

TilePosition returns the given tile's position offset inside this TileTree. It panics if tile is not a member of this tree.

type VirtualComponent

type VirtualComponent struct {
	C Component
	// contains filtered or unexported fields
}

VirtualComponent wraps a component to provide virtual coordinates and write bound checking. It exposes Move which can be used to move the inner component in the virtual coordinate space.

func (*VirtualComponent) Draw

func (c *VirtualComponent) Draw(writer Writer) error

Draw uses a virtual writer to perform bound checking and if successful draw the inner component in the virtual coordinate space.

func (*VirtualComponent) Height

func (c *VirtualComponent) Height() int

Height returns the height set in last Resize.

func (*VirtualComponent) Move

func (c *VirtualComponent) Move(pos Coordinates)

Move changes the position of this virtual component in the virtual coordinate space.

func (*VirtualComponent) Position

func (c *VirtualComponent) Position() Coordinates

Position returns this virtual component's position in the virtual coordinate space.

func (*VirtualComponent) Resize

func (c *VirtualComponent) Resize(width, height int)

Resize resizes the underlying component and stores size to perform bound checking on Draw.

func (*VirtualComponent) Width

func (c *VirtualComponent) Width() int

Width returns the width set in last Resize.

type WindowManager

type WindowManager struct {
	TileTree
	// contains filtered or unexported fields
}

WindowManager implements Handler as a tiled window manager.

func NewWindowManager

func NewWindowManager(handler Handler, border bool) (wm *WindowManager)

NewWindowManager allocates storage for a new WindowManager and initializes it with the given handler. If border is true, it will draw a border around every tile.

func (*WindowManager) Focus

func (wm *WindowManager) Focus() *TileNode

Focus returns the tile currently in focus.

func (*WindowManager) FocusDown

func (wm *WindowManager) FocusDown() bool

FocusDown switches the focus to the tile beneath the tile in focus If the tile in focus is the down-most tile in this window manager, then this method does nothing.

func (*WindowManager) FocusLeft

func (wm *WindowManager) FocusLeft() bool

FocusLeft switches the focus to the tile on the left side of the tile in focus If the tile in focus is the left-most tile in this window manager, then this method does nothing.

func (*WindowManager) FocusRight

func (wm *WindowManager) FocusRight() bool

FocusRight switches the focus to the tile on the right side of the tile in focus If the tile in focus is the right-most tile in this window manager, then this method does nothing.

func (*WindowManager) FocusUp

func (wm *WindowManager) FocusUp() bool

FocusUp switches the focus to the tile above the tile in focus If the tile in focus is the up-most tile in this window manager, then this method does nothing.

func (*WindowManager) GetCursor

func (wm *WindowManager) GetCursor() Coordinates

GetCursor returns the cursor coordinates of the tile in focus.

func (*WindowManager) Handle

func (wm *WindowManager) Handle(ev termbox.Event) (exit bool)

Handle : Handler

func (*WindowManager) Init

func (wm *WindowManager) Init(handler Handler, border bool)

Init initializes this WindowManager with the given handler. If border is true, it will draw a border around every tile.

func (*WindowManager) Man

func (wm *WindowManager) Man() Manual

Man : Handler

func (*WindowManager) SetFocus

func (wm *WindowManager) SetFocus(tile *TileNode) (prev *TileNode)

SetFocus sets the passed tile in focus. It returns the previous tile in focus. The behaviour is undefined if the given tile is not part of this WindowManager.

func (*WindowManager) SplitHorizontal

func (wm *WindowManager) SplitHorizontal(h Handler) *TileNode

SplitHorizontal creates a new horizontal split over the tile currently in focus.

func (*WindowManager) SplitVertical

func (wm *WindowManager) SplitVertical(h Handler) *TileNode

SplitVertical creates a new vertical split over the tile currently in focus.

type Writer

type Writer interface {
	Write(x, y int, r rune, fg termbox.Attribute, bg termbox.Attribute) error
	Flush() error
	Clear(fg, bg termbox.Attribute) error
	SetCursor(Coordinates)
}

Writer abstracts termbox write functionality to decouple components from termbox, so they're easier to test.

Directories

Path Synopsis
examples
wm

Jump to

Keyboard shortcuts

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