Documentation ¶
Index ¶
- Variables
- func Clamp(value, min, max int) int
- func ConfineString(s string, rect Rect, separator string) (lines []string, width, height int)
- func DefaultEventLoop(app *App, s tcell.Screen)
- func DrawBox(rect Rect, decoration *BoxDecoration, s tcell.Screen)
- func DrawRect(rect Rect, r rune, style tcell.Style, screen tcell.Screen)
- func DrawString(x, y int, s string, style tcell.Style, screen tcell.Screen)
- func Max(a, b int) int
- func Min(a, b int) int
- func TestRectHasPoint(t *testing.T)
- type Align
- func (a *Align) DisplaySize(boundsW, boundsH int) (w, h int)
- func (a *Align) Draw(rect Rect, s tcell.Screen)
- func (a *Align) GetChildRect(currentRect Rect) Rect
- func (a *Align) HandleKey(ev *tcell.EventKey) bool
- func (a *Align) HandleMouse(currentRect Rect, ev *tcell.EventMouse) bool
- func (a *Align) SetFocused(b bool)
- type Alignment
- type App
- type Box
- type BoxDecoration
- type Button
- type Center
- func (c *Center) DisplaySize(boundsW, boundsH int) (w, h int)
- func (c *Center) Draw(rect Rect, s tcell.Screen)
- func (c *Center) GetChildRect(currentRect Rect) Rect
- func (c *Center) HandleKey(ev *tcell.EventKey) bool
- func (c *Center) HandleMouse(currentRect Rect, ev *tcell.EventMouse) bool
- func (c *Center) SetFocused(b bool)
- type Column
- func (c *Column) DisplaySize(boundsW, boundsH int) (w, h int)
- func (c *Column) Draw(rect Rect, s tcell.Screen)
- func (c *Column) FocusNext()
- func (c *Column) FocusPrevious()
- func (c *Column) GetChildRects(rect Rect) []Rect
- func (c *Column) HandleKey(ev *tcell.EventKey) bool
- func (c *Column) HandleMouse(currentRect Rect, ev *tcell.EventMouse) bool
- func (c *Column) SetFocused(b bool)
- type Context
- type Label
- type Menu
- type MenuBar
- func (m *MenuBar) DisplaySize(boundsW, _ int) (w, h int)
- func (m *MenuBar) Draw(rect Rect, s tcell.Screen)
- func (m *MenuBar) HandleKey(ev *tcell.EventKey) bool
- func (m *MenuBar) HandleMouse(currentRect Rect, ev *tcell.EventMouse) bool
- func (m *MenuBar) ItemRects(rect Rect) []Rect
- func (m *MenuBar) SetFocused(b bool)
- type MenuBarItem
- type MenuItem
- type MenuItemType
- type Padding
- func (p *Padding) DisplaySize(boundsW, boundsH int) (w, h int)
- func (p *Padding) Draw(rect Rect, s tcell.Screen)
- func (p *Padding) GetChildRect(currentRect Rect) Rect
- func (p *Padding) HandleKey(ev *tcell.EventKey) bool
- func (p *Padding) HandleMouse(currentRect Rect, ev *tcell.EventMouse) bool
- func (p *Padding) SetFocused(b bool)
- type Positioning
- type Rect
- type Row
- func (r *Row) DisplaySize(boundsW, boundsH int) (w, h int)
- func (r *Row) Draw(rect Rect, s tcell.Screen)
- func (r *Row) FocusNext()
- func (r *Row) FocusPrevious()
- func (r *Row) GetChildRects(rect Rect) []Rect
- func (r *Row) HandleKey(ev *tcell.EventKey) bool
- func (r *Row) HandleMouse(currentRect Rect, ev *tcell.EventMouse) bool
- func (r *Row) SetFocused(b bool)
- type Scaffold
- func (s *Scaffold) DisplaySize(boundsW, boundsH int) (w, h int)
- func (s *Scaffold) Draw(rect Rect, screen tcell.Screen)
- func (s *Scaffold) FocusFloating()
- func (s *Scaffold) FocusMainWidget()
- func (s *Scaffold) FocusMenuBar()
- func (s *Scaffold) HandleKey(ev *tcell.EventKey) bool
- func (s *Scaffold) HandleMouse(currentRect Rect, ev *tcell.EventMouse) bool
- func (s *Scaffold) IsFloatingFocused() bool
- func (s *Scaffold) IsMainWidgetFocused() bool
- func (s *Scaffold) IsMenuBarFocused() bool
- func (s *Scaffold) SetFocused(b bool)
- type Shadow
- type TextInput
- type Widget
- type Window
- func (w *Window) Close()
- func (w *Window) DisplaySize(boundsW, boundsH int) (int, int)
- func (w *Window) Draw(rect Rect, s tcell.Screen)
- func (w *Window) GetChildRect(rect Rect) *Rect
- func (w *Window) HandleKey(ev *tcell.EventKey) bool
- func (w *Window) HandleMouse(rect Rect, ev *tcell.EventMouse) bool
- func (w *Window) SetFocused(b bool)
Constants ¶
This section is empty.
Variables ¶
var DefaultBoxDecoration = BoxDecoration{
Hor: '─',
Vert: '│',
TL: '┌',
TR: '┐',
BR: '┘',
BL: '└',
JointT: '┬',
JointR: '┤',
JointB: '┴',
JointL: '├',
Style: tcell.StyleDefault,
}
Functions ¶
func ConfineString ¶
ConfineString inserts newlines where a line would run out of the rect, and trims the string to have no more lines than rows in the rect. Returns the formatted lines, the minimum columns to draw it, and the number of lines produced.
func DefaultEventLoop ¶
func DefaultEventLoop(app *App, s tcell.Screen)
func DrawBox ¶
func DrawBox(rect Rect, decoration *BoxDecoration, s tcell.Screen)
func DrawString ¶
DrawString prints the string s at column x and row y with the provided style. Use mattn/go-runewidth to determine how many terminal cells your string will consume.
func TestRectHasPoint ¶
Types ¶
type Align ¶
type Align struct { Child Widget Positioning Positioning Rect Rect // Rect of Child if Positioning is Absolute or Relative. }
func (*Align) DisplaySize ¶
func (*Align) GetChildRect ¶
func (*Align) HandleMouse ¶
func (*Align) SetFocused ¶
type Alignment ¶
type Alignment uint8
const ( AlignLeft Alignment = iota AlignRight AlignCenter AlignStart = AlignLeft AlignEnd = AlignRight )
type App ¶
type App struct { ClearRune rune ClearStyle tcell.Style // Style used when clearing the screen MainWidget Widget CustomEventLoop func(app *App, s tcell.Screen) Running bool OnResize func(width, height int) // OnKeyEvent is called before the MainWidget's handler, and if this function // returns true, then the event is never passed onto the main widget. OnKeyEvent func(ev *tcell.EventKey) bool // OnMouseEvent is called before the MainWidget's handler, and if this function // returns true, then the event is never passed onto the main widget. OnMouseEvent func(ev *tcell.EventMouse) bool }
type Box ¶
type Box struct { Child Widget Decoration *BoxDecoration }
A Box draws an enclosed rectangle around its Child. A Box assumes each rune has a width of one terminal cell so double-wide characters will not be drawn correctly using a Box and BoxDecoration combination.
func (*Box) DisplaySize ¶
func (*Box) HandleMouse ¶
func (*Box) SetFocused ¶
type BoxDecoration ¶
type BoxDecoration struct {
Hor, Vert rune // Horizontal and vertical sides
TL, TR, BR, BL rune // Clockwise corners
JointT, JointR rune // Joints (for menus and other divided boxes)
JointB, JointL rune
Style tcell.Style
}
The BoxDecoration allows for an individual rune per side and corner of the box being drawn. See https://en.wikipedia.org/wiki/Box-drawing_character
func (BoxDecoration) WithStyle ¶
func (b BoxDecoration) WithStyle(style tcell.Style) BoxDecoration
WithStyle is a helper function to make a copy of the BoxDecoration with a different style.
type Button ¶
type Button struct { Text string NormalStyle tcell.Style FocusedStyle tcell.Style OnPressed func() // contains filtered or unexported fields }
func (*Button) DisplaySize ¶
func (*Button) HandleMouse ¶
func (*Button) SetFocused ¶
type Center ¶
type Center struct {
Child Widget
}
func (*Center) DisplaySize ¶
func (*Center) GetChildRect ¶
func (*Center) HandleMouse ¶
func (*Center) SetFocused ¶
type Column ¶
type Column struct { Children []Widget HorizontalAlign Alignment FocusedIndex int // Index of child that receives focus OnKeyEvent func(column *Column, ev *tcell.EventKey) bool // contains filtered or unexported fields }
A Column orders its children vertically.
func (*Column) DisplaySize ¶
func (*Column) FocusPrevious ¶
func (c *Column) FocusPrevious()
func (*Column) GetChildRects ¶
func (*Column) HandleMouse ¶
func (*Column) SetFocused ¶
type Label ¶
type Label struct { Text string Align Alignment WrapLen int // Force the text to wrap after a specified number of terminal cells. Separator string // Empty string defaults to Unix linefeed "\n". Style tcell.Style }
func (*Label) DisplaySize ¶
func (*Label) GetSeparator ¶
func (*Label) HandleMouse ¶
func (*Label) SetFocused ¶
type Menu ¶
type Menu struct { Items []MenuItem Decorated bool // Whether to draw a styled box around the Menu Decoration *BoxDecoration // Used only if Decorated is true NormalStyle tcell.Style SelectionStyle tcell.Style Selected int // contains filtered or unexported fields }
A Menu contains a list of selectable items the user may either click or scroll through using the arrow keys. The items of a Menu are the type MenuItem, which can be an action or expand into another menu, known as a submenu. This widget will handle any events it receives, so do not pass an event to the Menu if it is not focused or otherwise visible.
func (*Menu) ActivateItem ¶
func (*Menu) DisplaySize ¶
DisplaySize for Menu returns the minimum size to show the Menu normally, so it ignores the input boundary values.
func (*Menu) HandleMouse ¶
func (*Menu) SetFocused ¶
type MenuBar ¶
type MenuBar struct { Menus []MenuBarItem NormalStyle tcell.Style SelectionStyle tcell.Style Selected int // contains filtered or unexported fields }
func (*MenuBar) DisplaySize ¶
func (*MenuBar) HandleMouse ¶
func (*MenuBar) ItemRects ¶
ItemRects returns a slice of Rects for each Menu's title that the user selects before expanding the actual Menu. The returned slice length will be equal to the length of Menus.
func (*MenuBar) SetFocused ¶
type MenuBarItem ¶
A MenuBarItem is a Menu with an added Title field.
type MenuItem ¶
type MenuItem struct { Title string Type MenuItemType Action func() }
A MenuItem is a selectable option inside a Menu. If the Type is MenuItemAction, then only the Action field should be accessed. Likewise, if the Type is MenuItemSubmenu, then only the Submenu field should be accessed.
type MenuItemType ¶
type MenuItemType uint8
const ( MenuItemAction MenuItemType = iota MenuItemSeparator )
type Padding ¶
func (*Padding) DisplaySize ¶
func (*Padding) GetChildRect ¶
func (*Padding) HandleMouse ¶
func (*Padding) SetFocused ¶
type Positioning ¶
type Positioning uint8
const ( // Inherit is the default layout for all Widgets. The Rect property will be // ignored. Calling Align's DisplaySize will return DisplaySize on the // Child. Inherit Positioning = iota // Absolute positioning causes a Widget to be placed at any X, Y coordinate // with any arbitrary width and height as specified. This is useful for // drop-down menus or other floating widgets. Calling Align's DisplaySize // will return zero. Absolute // Relative positioning is similar to Absolute, but causes a Widget to // inherit its parent's position. Calling Align's DisplaySize will return // zero. Relative )
type Row ¶
type Row struct { Children []Widget VerticalAlign Alignment FocusedIndex int // Index of child that receives focus OnKeyEvent func(row *Row, ev *tcell.EventKey) bool // contains filtered or unexported fields }
A Row orders its children horizontally.
func (*Row) DisplaySize ¶
func (*Row) FocusPrevious ¶
func (r *Row) FocusPrevious()
func (*Row) GetChildRects ¶
func (*Row) HandleMouse ¶
func (*Row) SetFocused ¶
type Scaffold ¶
type Scaffold struct { MenuBar *MenuBar MainWidget Widget Floating []Widget // contains filtered or unexported fields }
func (*Scaffold) DisplaySize ¶
func (*Scaffold) FocusFloating ¶
func (s *Scaffold) FocusFloating()
func (*Scaffold) FocusMainWidget ¶
func (s *Scaffold) FocusMainWidget()
func (*Scaffold) FocusMenuBar ¶
func (s *Scaffold) FocusMenuBar()
func (*Scaffold) HandleMouse ¶
func (*Scaffold) IsFloatingFocused ¶
func (*Scaffold) IsMainWidgetFocused ¶
func (*Scaffold) IsMenuBarFocused ¶
func (*Scaffold) SetFocused ¶
type Shadow ¶
A Shadow draws a shadow covering one cell below, and two cells right of its bounding box. This is useful for dialog windows or buttons that need depth.
func (*Shadow) DisplaySize ¶
func (*Shadow) Draw ¶
Draw causes the Shadow to intentionally set cells outside its provided rect. The provided rect is passed directly to the child.
func (*Shadow) HandleMouse ¶
func (*Shadow) SetFocused ¶
type TextInput ¶
type TextInput struct { Text string // User-entered content. Placeholder string // Placeholder is visible when Text is empty. IsHidden bool HiddenChar rune Scroll int // Number of runes skipped when viewing. Width int // If Width is zero, then it is will be as wide as possible. NormalStyle tcell.Style FocusedStyle tcell.Style PlaceholderStyle tcell.Style // If PlaceholderStyle is zero (or default style), then it inherits Normal/FocusedStyle. OnTextEdited func(text string) // contains filtered or unexported fields }
func (*TextInput) DisplaySize ¶
func (*TextInput) HandleMouse ¶
func (*TextInput) SetFocused ¶
type Widget ¶
type Widget interface { // HandleMouse is called by a parent of the Widget when they receive the // event. A parent passes the event down to their child after attempting // to handle it, passing their child's accurate currentRect, which is // determined differently for every Widget, but is based upon the result of // the child's DisplaySize function. HandleMouse will return `true` if the // event is handled. Otherwise, `false`, so the event continues to be // propagated. If this Widget or any of its child Widgets handle this event // successfully (by returning true), then SetFocused(true) should be called. // // The currentRect is used by the Widget to determine its current position // and size on the terminal. The rect is determined by the Widget's parent. HandleMouse(currentRect Rect, ev *tcell.EventMouse) bool // HandleKey is called by a parent of the Widget when they receive the // event. The Widget will only try to handle the event if it is focused. // HandleKey will return `true` if the event is handled. Otherwise, `false`, // so the event can continue to be propagated. If this Widget or any of its // child Widgets handle this event successfully (by returning true), then // SetFocused(true) should be called. HandleKey(ev *tcell.EventKey) bool // SetFocused alerts the Widget that it has received input focus from the // user. The value can be kept in the Widget to differ its appearance during // Draw. The Widget will call SetFocused(b) on all of its children, also. SetFocused(b bool) // DisplaySize returns the exact size of the Widget when it will be drawn. // This is used for containers like Center, and especially for the // HandleMouse function to work properly, as a Widget's position and size // will be determined by the result of calling its DisplaySize function. DisplaySize(boundsW, boundsH int) (w, h int) // Draw renders the Widget onto the terminal screen, bounded by the provided // Rect. It is a bug if the Widget draws any part of itself outside the rect // provided. Draw should not call Sync() on the tcell.Screen or other // synchronizing functions, as all synchronization will be done by the event // loop. Draw(rect Rect, s tcell.Screen) }
type Window ¶
type Window struct { Title string Child Widget HideClose bool OnClosed func() DisableMoving bool OnMove func(newX, newY int) CloseButtonStyle tcell.Style TitleBarStyle tcell.Style WindowStyle tcell.Style // contains filtered or unexported fields }
A Window displays a flexible dialog. The dialog can be moved by the user, but events must be handled with the OnMove and OnClosed callbacks. By standard, the Window assumes the position and size of whatever Rect is provided to Draw and DisplaySize, but you could use an Align to provide the Window an arbitrary position and size on the terminal.