Documentation ¶
Overview ¶
Package tview implements rich widgets for terminal based user interfaces. The widgets provided with this package are useful for data exploration and data entry.
Widgets ¶
The package implements the following widgets:
- TextView: A scrollable window that display multi-colored text. Text may also be highlighted.
- Table: A scrollable display of tabular data. Table cells, rows, or columns may also be highlighted.
- TreeView: A scrollable display for hierarchical data. Tree nodes can be highlighted, collapsed, expanded, and more.
- List: A navigable text list with optional keyboard shortcuts.
- InputField: One-line input fields to enter text.
- DropDown: Drop-down selection fields.
- Checkbox: Selectable checkbox for boolean values.
- Button: Buttons which get activated when the user selects them.
- Form: Forms composed of input fields, drop down selections, checkboxes, and buttons.
- Modal: A centered window with a text message and one or more buttons.
- Flex: A Flexbox based layout manager.
- Pages: A page based layout manager.
The package also provides Application which is used to poll the event queue and draw widgets on screen.
Hello World ¶
The following is a very basic example showing a box with the title "Hello, world!":
package main import ( "github.com/rivo/tview" ) func main() { box := tview.NewBox().SetBorder(true).SetTitle("Hello, world!") if err := tview.NewApplication().SetRoot(box, true).Run(); err != nil { panic(err) } }
First, we create a box primitive with a border and a title. Then we create an application, set the box as its root primitive, and run the event loop. The application exits when the application's Stop() function is called or when Ctrl-C is pressed.
If we have a primitive which consumes key presses, we call the application's SetFocus() function to redirect all key presses to that primitive. Most primitives then offer ways to install handlers that allow you to react to any actions performed on them.
More Demos ¶
You will find more demos in the "demos" subdirectory. It also contains a presentation (written using tview) which gives an overview of the different widgets and how they can be used.
Colors ¶
Throughout this package, colors are specified using the tcell.Color type. Functions such as tcell.GetColor(), tcell.NewHexColor(), and tcell.NewRGBColor() can be used to create colors from W3C color names or RGB values.
Almost all strings which are displayed can contain color tags. Color tags are W3C color names or six hexadecimal digits following a hash tag, wrapped in square brackets. Examples:
This is a [red]warning[white]! The sky is [#8080ff]blue[#ffffff].
A color tag changes the color of the characters following that color tag. This applies to almost everything from box titles, list text, form item labels, to table cells. In a TextView, this functionality has to be switched on explicitly. See the TextView documentation for more information.
Color tags may contain not just the foreground (text) color but also the background color and additional flags. In fact, the full definition of a color tag is as follows:
[<foreground>:<background>:<flags>]
Each of the three fields can be left blank and trailing fields can be omitted. (Empty square brackets "[]", however, are not considered color tags.) Colors that are not specified will be left unchanged. A field with just a dash ("-") means "reset to default".
You can specify the following flags (some flags may not be supported by your terminal):
l: blink b: bold d: dim r: reverse (switch foreground and background color) u: underline
Examples:
[yellow]Yellow text [yellow:red]Yellow text on red background [:red]Red background, text color unchanged [yellow::u]Yellow text underlined [::bl]Bold, blinking text [::-]Colors unchanged, flags reset [-]Reset foreground color [-:-:-]Reset everything [:]No effect []Not a valid color tag, will print square brackets as they are
In the rare event that you want to display a string such as "[red]" or "[#00ff1a]" without applying its effect, you need to put an opening square bracket before the closing square bracket. Note that the text inside the brackets will be matched less strictly than region or colors tags. I.e. any character that may be used in color or region tags will be recognized. Examples:
[red[] will be output as [red] ["123"[] will be output as ["123"] [#6aff00[[] will be output as [#6aff00[] [a#"[[[] will be output as [a#"[[] [] will be output as [] (see color tags above) [[] will be output as [[] (not an escaped tag)
You can use the Escape() function to insert brackets automatically where needed.
Styles ¶
When primitives are instantiated, they are initialized with colors taken from the global Styles variable. You may change this variable to adapt the look and feel of the primitives to your preferred style.
Unicode Support ¶
This package supports unicode characters including wide characters.
Type Hierarchy ¶
All widgets listed above contain the Box type. All of Box's functions are therefore available for all widgets, too.
All widgets also implement the Primitive interface. There is also the Focusable interface which is used to override functions in subclassing types.
The tview package is based on https://github.com/gdamore/tcell. It uses types and constants from that package (e.g. colors and keyboard values).
This package does not process mouse input (yet).
Index ¶
- Constants
- Variables
- func ANSIIWriter(writer io.Writer) io.Writer
- func Escape(text string) string
- func Print(screen tcell.Screen, text string, x, y, maxWidth, align int, color tcell.Color) (int, int)
- func PrintJoinedSemigraphics(screen tcell.Screen, x, y int, ch rune, color tcell.Color)
- func PrintSimple(screen tcell.Screen, text string, x, y int)
- func StringWidth(text string) int
- func TranslateANSII(text string) string
- func WordWrap(text string, width int) (lines []string)
- type Application
- func (a *Application) Draw() *Application
- func (a *Application) GetAfterDrawFunc() func(screen tcell.Screen)
- func (a *Application) GetBeforeDrawFunc() func(screen tcell.Screen) bool
- func (a *Application) GetFocus() Primitive
- func (a *Application) GetInputCapture() func(event *tcell.EventKey) *tcell.EventKey
- func (a *Application) ResizeToFullScreen(p Primitive) *Application
- func (a *Application) Run() error
- func (a *Application) SetAfterDrawFunc(handler func(screen tcell.Screen)) *Application
- func (a *Application) SetBeforeDrawFunc(handler func(screen tcell.Screen) bool) *Application
- func (a *Application) SetFocus(p Primitive) *Application
- func (a *Application) SetInputCapture(capture func(event *tcell.EventKey) *tcell.EventKey) *Application
- func (a *Application) SetRoot(root Primitive, fullscreen bool) *Application
- func (a *Application) Stop()
- func (a *Application) Suspend(f func()) bool
- type Box
- func (b *Box) Blur()
- func (b *Box) Draw(screen tcell.Screen)
- func (b *Box) Focus(delegate func(p Primitive))
- func (b *Box) GetDrawFunc() func(screen tcell.Screen, x, y, width, height int) (int, int, int, int)
- func (b *Box) GetFocusable() Focusable
- func (b *Box) GetInnerRect() (int, int, int, int)
- func (b *Box) GetInputCapture() func(event *tcell.EventKey) *tcell.EventKey
- func (b *Box) GetRect() (int, int, int, int)
- func (b *Box) HasFocus() bool
- func (b *Box) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive))
- func (b *Box) SetBackgroundColor(color tcell.Color) *Box
- func (b *Box) SetBorder(show bool) *Box
- func (b *Box) SetBorderColor(color tcell.Color) *Box
- func (b *Box) SetBorderPadding(top, bottom, left, right int) *Box
- func (b *Box) SetDrawFunc(...) *Box
- func (b *Box) SetInputCapture(capture func(event *tcell.EventKey) *tcell.EventKey) *Box
- func (b *Box) SetRect(x, y, width, height int)
- func (b *Box) SetTitle(title string) *Box
- func (b *Box) SetTitleAlign(align int) *Box
- func (b *Box) SetTitleColor(color tcell.Color) *Box
- func (b *Box) WrapInputHandler(inputHandler func(*tcell.EventKey, func(p Primitive))) func(*tcell.EventKey, func(p Primitive))
- type Button
- func (b *Button) Draw(screen tcell.Screen)
- func (b *Button) GetLabel() string
- func (b *Button) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive))
- func (b *Button) SetBackgroundColorActivated(color tcell.Color) *Button
- func (b *Button) SetBlurFunc(handler func(key tcell.Key)) *Button
- func (b *Button) SetLabel(label string) *Button
- func (b *Button) SetLabelColor(color tcell.Color) *Button
- func (b *Button) SetLabelColorActivated(color tcell.Color) *Button
- func (b *Button) SetSelectedFunc(handler func()) *Button
- type Checkbox
- func (c *Checkbox) Draw(screen tcell.Screen)
- func (c *Checkbox) GetFieldWidth() int
- func (c *Checkbox) GetLabel() string
- func (c *Checkbox) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive))
- func (c *Checkbox) IsChecked() bool
- func (c *Checkbox) SetChangedFunc(handler func(checked bool)) *Checkbox
- func (c *Checkbox) SetChecked(checked bool) *Checkbox
- func (c *Checkbox) SetDoneFunc(handler func(key tcell.Key)) *Checkbox
- func (c *Checkbox) SetFieldBackgroundColor(color tcell.Color) *Checkbox
- func (c *Checkbox) SetFieldTextColor(color tcell.Color) *Checkbox
- func (c *Checkbox) SetFinishedFunc(handler func(key tcell.Key)) FormItem
- func (c *Checkbox) SetFormAttributes(labelWidth int, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem
- func (c *Checkbox) SetLabel(label string) *Checkbox
- func (c *Checkbox) SetLabelColor(color tcell.Color) *Checkbox
- func (c *Checkbox) SetLabelWidth(width int) *Checkbox
- type DropDown
- func (d *DropDown) AddOption(text string, selected func()) *DropDown
- func (d *DropDown) Draw(screen tcell.Screen)
- func (d *DropDown) Focus(delegate func(p Primitive))
- func (d *DropDown) GetCurrentOption() (int, string)
- func (d *DropDown) GetFieldWidth() int
- func (d *DropDown) GetLabel() string
- func (d *DropDown) HasFocus() bool
- func (d *DropDown) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive))
- func (d *DropDown) SetCurrentOption(index int) *DropDown
- func (d *DropDown) SetDoneFunc(handler func(key tcell.Key)) *DropDown
- func (d *DropDown) SetFieldBackgroundColor(color tcell.Color) *DropDown
- func (d *DropDown) SetFieldTextColor(color tcell.Color) *DropDown
- func (d *DropDown) SetFieldWidth(width int) *DropDown
- func (d *DropDown) SetFinishedFunc(handler func(key tcell.Key)) FormItem
- func (d *DropDown) SetFormAttributes(labelWidth int, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem
- func (d *DropDown) SetLabel(label string) *DropDown
- func (d *DropDown) SetLabelColor(color tcell.Color) *DropDown
- func (d *DropDown) SetLabelWidth(width int) *DropDown
- func (d *DropDown) SetOptions(texts []string, selected func(text string, index int)) *DropDown
- func (d *DropDown) SetPrefixTextColor(color tcell.Color) *DropDown
- type Flex
- func (f *Flex) AddItem(item Primitive, fixedSize, proportion int, focus bool) *Flex
- func (f *Flex) Draw(screen tcell.Screen)
- func (f *Flex) Focus(delegate func(p Primitive))
- func (f *Flex) HasFocus() bool
- func (f *Flex) RemoveItem(p Primitive) *Flex
- func (f *Flex) ResizeItem(p Primitive, fixedSize, proportion int) *Flex
- func (f *Flex) SetDirection(direction int) *Flex
- func (f *Flex) SetFullScreen(fullScreen bool) *Flex
- type Focusable
- type Form
- func (f *Form) AddButton(label string, selected func()) *Form
- func (f *Form) AddCheckbox(label string, checked bool, changed func(checked bool)) *Form
- func (f *Form) AddDropDown(label string, options []string, initialOption int, ...) *Form
- func (f *Form) AddFormItem(item FormItem) *Form
- func (f *Form) AddInputField(label, value string, fieldWidth int, ...) *Form
- func (f *Form) AddPasswordField(label, value string, fieldWidth int, mask rune, changed func(text string)) *Form
- func (f *Form) Clear(includeButtons bool) *Form
- func (f *Form) Draw(screen tcell.Screen)
- func (f *Form) Focus(delegate func(p Primitive))
- func (f *Form) GetFormItem(index int) FormItem
- func (f *Form) GetFormItemByLabel(label string) FormItem
- func (f *Form) HasFocus() bool
- func (f *Form) SetButtonBackgroundColor(color tcell.Color) *Form
- func (f *Form) SetButtonTextColor(color tcell.Color) *Form
- func (f *Form) SetButtonsAlign(align int) *Form
- func (f *Form) SetCancelFunc(callback func()) *Form
- func (f *Form) SetFieldBackgroundColor(color tcell.Color) *Form
- func (f *Form) SetFieldTextColor(color tcell.Color) *Form
- func (f *Form) SetHorizontal(horizontal bool) *Form
- func (f *Form) SetItemPadding(padding int) *Form
- func (f *Form) SetLabelColor(color tcell.Color) *Form
- type FormItem
- type Frame
- func (f *Frame) AddText(text string, header bool, align int, color tcell.Color) *Frame
- func (f *Frame) Clear() *Frame
- func (f *Frame) Draw(screen tcell.Screen)
- func (f *Frame) Focus(delegate func(p Primitive))
- func (f *Frame) HasFocus() bool
- func (f *Frame) SetBorders(top, bottom, header, footer, left, right int) *Frame
- type Grid
- func (g *Grid) AddItem(p Primitive, row, column, height, width, minGridHeight, minGridWidth int, ...) *Grid
- func (g *Grid) Blur()
- func (g *Grid) Clear() *Grid
- func (g *Grid) Draw(screen tcell.Screen)
- func (g *Grid) Focus(delegate func(p Primitive))
- func (g *Grid) GetOffset() (rows, columns int)
- func (g *Grid) HasFocus() bool
- func (g *Grid) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive))
- func (g *Grid) RemoveItem(p Primitive) *Grid
- func (g *Grid) SetBorders(borders bool) *Grid
- func (g *Grid) SetBordersColor(color tcell.Color) *Grid
- func (g *Grid) SetColumns(columns ...int) *Grid
- func (g *Grid) SetGap(row, column int) *Grid
- func (g *Grid) SetMinSize(row, column int) *Grid
- func (g *Grid) SetOffset(rows, columns int) *Grid
- func (g *Grid) SetRows(rows ...int) *Grid
- func (g *Grid) SetSize(numRows, numColumns, rowSize, columnSize int) *Grid
- type InputField
- func (i *InputField) Draw(screen tcell.Screen)
- func (i *InputField) GetFieldWidth() int
- func (i *InputField) GetLabel() string
- func (i *InputField) GetText() string
- func (i *InputField) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive))
- func (i *InputField) SetAcceptanceFunc(handler func(textToCheck string, lastChar rune) bool) *InputField
- func (i *InputField) SetChangedFunc(handler func(text string)) *InputField
- func (i *InputField) SetDoneFunc(handler func(key tcell.Key)) *InputField
- func (i *InputField) SetFieldBackgroundColor(color tcell.Color) *InputField
- func (i *InputField) SetFieldTextColor(color tcell.Color) *InputField
- func (i *InputField) SetFieldWidth(width int) *InputField
- func (i *InputField) SetFinishedFunc(handler func(key tcell.Key)) FormItem
- func (i *InputField) SetFormAttributes(labelWidth int, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem
- func (i *InputField) SetLabel(label string) *InputField
- func (i *InputField) SetLabelColor(color tcell.Color) *InputField
- func (i *InputField) SetLabelWidth(width int) *InputField
- func (i *InputField) SetMaskCharacter(mask rune) *InputField
- func (i *InputField) SetPlaceholder(text string) *InputField
- func (i *InputField) SetPlaceholderTextColor(color tcell.Color) *InputField
- func (i *InputField) SetText(text string) *InputField
- type List
- func (l *List) AddItem(mainText, secondaryText string, shortcut rune, selected func()) *List
- func (l *List) Clear() *List
- func (l *List) Draw(screen tcell.Screen)
- func (l *List) GetChosenItem() int
- func (l *List) GetCurrentItem() int
- func (l *List) GetItemCount() int
- func (l *List) GetItemText(index int) (main, secondary string)
- func (l *List) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive))
- func (l *List) SetChangedFunc(handler func(int, string, string, rune)) *List
- func (l *List) SetChosenBackgroundColor(color tcell.Color) *List
- func (l *List) SetChosenFunc(handler func(int, string, string, rune)) *List
- func (l *List) SetChosenItem(index int) *List
- func (l *List) SetChosenTextColor(color tcell.Color) *List
- func (l *List) SetCurrentItem(index int) *List
- func (l *List) SetDoneFunc(handler func()) *List
- func (l *List) SetItemText(index int, main, secondary string) *List
- func (l *List) SetMainTextColor(color tcell.Color) *List
- func (l *List) SetSecondaryTextColor(color tcell.Color) *List
- func (l *List) SetSelectable(b bool) *List
- func (l *List) SetSelectedBackgroundColor(color tcell.Color) *List
- func (l *List) SetSelectedFunc(handler func(int, string, string, rune)) *List
- func (l *List) SetSelectedTextColor(color tcell.Color) *List
- func (l *List) SetShortcutColor(color tcell.Color) *List
- func (l *List) ShowSecondaryText(show bool) *List
- type Modal
- func (m *Modal) AddButtons(labels []string) *Modal
- func (m *Modal) Draw(screen tcell.Screen)
- func (m *Modal) Focus(delegate func(p Primitive))
- func (m *Modal) HasFocus() bool
- func (m *Modal) SetDoneFunc(handler func(buttonIndex int, buttonLabel string)) *Modal
- func (m *Modal) SetText(text string) *Modal
- func (m *Modal) SetTextColor(color tcell.Color) *Modal
- type Pages
- func (p *Pages) AddAndSwitchToPage(name string, item Primitive, resize bool) *Pages
- func (p *Pages) AddPage(name string, item Primitive, resize, visible bool) *Pages
- func (p *Pages) Draw(screen tcell.Screen)
- func (p *Pages) Focus(delegate func(p Primitive))
- func (p *Pages) HasFocus() bool
- func (p *Pages) HasPage(name string) bool
- func (p *Pages) HidePage(name string) *Pages
- func (p *Pages) RemovePage(name string) *Pages
- func (p *Pages) SendToBack(name string) *Pages
- func (p *Pages) SendToFront(name string) *Pages
- func (p *Pages) SetChangedFunc(handler func()) *Pages
- func (p *Pages) ShowPage(name string) *Pages
- func (p *Pages) SwitchToPage(name string) *Pages
- type Primitive
- type Table
- func (t *Table) Clear() *Table
- func (t *Table) Draw(screen tcell.Screen)
- func (t *Table) GetCell(row, column int) *TableCell
- func (t *Table) GetColumnCount() int
- func (t *Table) GetOffset() (row, column int)
- func (t *Table) GetRowCount() int
- func (t *Table) GetSelectable() (rows, columns bool)
- func (t *Table) GetSelection() (row, column int)
- func (t *Table) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive))
- func (t *Table) ScrollToBeginning() *Table
- func (t *Table) ScrollToEnd() *Table
- func (t *Table) Select(row, column int) *Table
- func (t *Table) SetBorders(show bool) *Table
- func (t *Table) SetBordersColor(color tcell.Color) *Table
- func (t *Table) SetCell(row, column int, cell *TableCell) *Table
- func (t *Table) SetCellSimple(row, column int, text string) *Table
- func (t *Table) SetDoneFunc(handler func(key tcell.Key)) *Table
- func (t *Table) SetFixed(rows, columns int) *Table
- func (t *Table) SetOffset(row, column int) *Table
- func (t *Table) SetSelectable(rows, columns bool) *Table
- func (t *Table) SetSelectedFunc(handler func(row, column int)) *Table
- func (t *Table) SetSelectionChangedFunc(handler func(row, column int)) *Table
- func (t *Table) SetSeparator(separator rune) *Table
- type TableCell
- func (c *TableCell) GetLastPosition() (x, y, width int)
- func (c *TableCell) SetAlign(align int) *TableCell
- func (c *TableCell) SetAttributes(attr tcell.AttrMask) *TableCell
- func (c *TableCell) SetBackgroundColor(color tcell.Color) *TableCell
- func (c *TableCell) SetExpansion(expansion int) *TableCell
- func (c *TableCell) SetMaxWidth(maxWidth int) *TableCell
- func (c *TableCell) SetSelectable(selectable bool) *TableCell
- func (c *TableCell) SetStyle(style tcell.Style) *TableCell
- func (c *TableCell) SetText(text string) *TableCell
- func (c *TableCell) SetTextColor(color tcell.Color) *TableCell
- type TextView
- func (t *TextView) Clear() *TextView
- func (t *TextView) Draw(screen tcell.Screen)
- func (t *TextView) GetHighlights() (regionIDs []string)
- func (t *TextView) GetRegionText(regionID string) string
- func (t *TextView) Highlight(regionIDs ...string) *TextView
- func (t *TextView) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive))
- func (t *TextView) ScrollTo(row, column int) *TextView
- func (t *TextView) ScrollToBeginning() *TextView
- func (t *TextView) ScrollToEnd() *TextView
- func (t *TextView) ScrollToHighlight() *TextView
- func (t *TextView) SetChangedFunc(handler func()) *TextView
- func (t *TextView) SetDoneFunc(handler func(key tcell.Key)) *TextView
- func (t *TextView) SetDynamicColors(dynamic bool) *TextView
- func (t *TextView) SetRegions(regions bool) *TextView
- func (t *TextView) SetScrollable(scrollable bool) *TextView
- func (t *TextView) SetText(text string) *TextView
- func (t *TextView) SetTextAlign(align int) *TextView
- func (t *TextView) SetTextColor(color tcell.Color) *TextView
- func (t *TextView) SetWordWrap(wrapOnWords bool) *TextView
- func (t *TextView) SetWrap(wrap bool) *TextView
- func (t *TextView) Write(p []byte) (n int, err error)
- type TreeNode
- func (n *TreeNode) AddChild(node *TreeNode) *TreeNode
- func (n *TreeNode) ClearChildren() *TreeNode
- func (n *TreeNode) Collapse() *TreeNode
- func (n *TreeNode) CollapseAll() *TreeNode
- func (n *TreeNode) Expand() *TreeNode
- func (n *TreeNode) ExpandAll() *TreeNode
- func (n *TreeNode) GetChildren() []*TreeNode
- func (n *TreeNode) GetReference() interface{}
- func (n *TreeNode) IsExpanded() bool
- func (n *TreeNode) SetChildren(childNodes []*TreeNode) *TreeNode
- func (n *TreeNode) SetColor(color tcell.Color) *TreeNode
- func (n *TreeNode) SetExpanded(expanded bool) *TreeNode
- func (n *TreeNode) SetIndent(indent int) *TreeNode
- func (n *TreeNode) SetReference(reference interface{}) *TreeNode
- func (n *TreeNode) SetSelectable(selectable bool) *TreeNode
- func (n *TreeNode) SetSelectedFunc(handler func()) *TreeNode
- func (n *TreeNode) SetText(text string) *TreeNode
- func (n *TreeNode) Walk(callback func(node, parent *TreeNode) bool) *TreeNode
- type TreeView
- func (t *TreeView) Draw(screen tcell.Screen)
- func (t *TreeView) GetCurrentNode() *TreeNode
- func (t *TreeView) GetRoot() *TreeNode
- func (t *TreeView) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive))
- func (t *TreeView) SetAlign(align bool) *TreeView
- func (t *TreeView) SetChangedFunc(handler func(node *TreeNode)) *TreeView
- func (t *TreeView) SetCurrentNode(node *TreeNode) *TreeView
- func (t *TreeView) SetGraphics(showGraphics bool) *TreeView
- func (t *TreeView) SetGraphicsColor(color tcell.Color) *TreeView
- func (t *TreeView) SetPrefixes(prefixes []string) *TreeView
- func (t *TreeView) SetRoot(root *TreeNode) *TreeView
- func (t *TreeView) SetSelectedFunc(handler func(node *TreeNode)) *TreeView
- func (t *TreeView) SetTopLevel(topLevel int) *TreeView
Constants ¶
const ( FlexRow = iota FlexColumn )
Configuration values.
const ( // Block: General Punctation U+2000-U+206F (http://unicode.org/charts/PDF/U2000.pdf) SemigraphicsHorizontalEllipsis rune = '\u2026' // … // Block: Box Drawing U+2500-U+257F (http://unicode.org/charts/PDF/U2500.pdf) BoxDrawingsLightHorizontal rune = '\u2500' // ─ BoxDrawingsHeavyHorizontal rune = '\u2501' // ━ BoxDrawingsLightVertical rune = '\u2502' // │ BoxDrawingsHeavyVertical rune = '\u2503' // ┃ BoxDrawingsLightTripleDashHorizontal rune = '\u2504' // ┄ BoxDrawingsHeavyTripleDashHorizontal rune = '\u2505' // ┅ BoxDrawingsLightTripleDashVertical rune = '\u2506' // ┆ BoxDrawingsHeavyTripleDashVertical rune = '\u2507' // ┇ BoxDrawingsLightQuadrupleDashHorizontal rune = '\u2508' // ┈ BoxDrawingsHeavyQuadrupleDashHorizontal rune = '\u2509' // ┉ BoxDrawingsLightQuadrupleDashVertical rune = '\u250a' // ┊ BoxDrawingsHeavyQuadrupleDashVertical rune = '\u250b' // ┋ BoxDrawingsLightDownAndRight rune = '\u250c' // ┌ BoxDrawingsDownLighAndRightHeavy rune = '\u250d' // ┍ BoxDrawingsDownHeavyAndRightLight rune = '\u250e' // ┎ BoxDrawingsHeavyDownAndRight rune = '\u250f' // ┏ BoxDrawingsLightDownAndLeft rune = '\u2510' // ┐ BoxDrawingsDownLighAndLeftHeavy rune = '\u2511' // ┑ BoxDrawingsDownHeavyAndLeftLight rune = '\u2512' // ┒ BoxDrawingsHeavyDownAndLeft rune = '\u2513' // ┓ BoxDrawingsLightUpAndRight rune = '\u2514' // └ BoxDrawingsUpLightAndRightHeavy rune = '\u2515' // ┕ BoxDrawingsUpHeavyAndRightLight rune = '\u2516' // ┖ BoxDrawingsHeavyUpAndRight rune = '\u2517' // ┗ BoxDrawingsLightUpAndLeft rune = '\u2518' // ┘ BoxDrawingsUpLightAndLeftHeavy rune = '\u2519' // ┙ BoxDrawingsUpHeavyAndLeftLight rune = '\u251a' // ┚ BoxDrawingsHeavyUpAndLeft rune = '\u251b' // ┛ BoxDrawingsLightVerticalAndRight rune = '\u251c' // ├ BoxDrawingsVerticalLightAndRightHeavy rune = '\u251d' // ┝ BoxDrawingsUpHeavyAndRightDownLight rune = '\u251e' // ┞ BoxDrawingsDownHeacyAndRightUpLight rune = '\u251f' // ┟ BoxDrawingsVerticalHeavyAndRightLight rune = '\u2520' // ┠ BoxDrawingsDownLightAnbdRightUpHeavy rune = '\u2521' // ┡ BoxDrawingsUpLightAndRightDownHeavy rune = '\u2522' // ┢ BoxDrawingsHeavyVerticalAndRight rune = '\u2523' // ┣ BoxDrawingsLightVerticalAndLeft rune = '\u2524' // ┤ BoxDrawingsVerticalLightAndLeftHeavy rune = '\u2525' // ┥ BoxDrawingsUpHeavyAndLeftDownLight rune = '\u2526' // ┦ BoxDrawingsDownHeavyAndLeftUpLight rune = '\u2527' // ┧ BoxDrawingsVerticalheavyAndLeftLight rune = '\u2528' // ┨ BoxDrawingsDownLightAndLeftUpHeavy rune = '\u2529' // ┨ BoxDrawingsUpLightAndLeftDownHeavy rune = '\u252a' // ┪ BoxDrawingsHeavyVerticalAndLeft rune = '\u252b' // ┫ BoxDrawingsLightDownAndHorizontal rune = '\u252c' // ┬ BoxDrawingsLeftHeavyAndRightDownLight rune = '\u252d' // ┭ BoxDrawingsRightHeavyAndLeftDownLight rune = '\u252e' // ┮ BoxDrawingsDownLightAndHorizontalHeavy rune = '\u252f' // ┯ BoxDrawingsDownHeavyAndHorizontalLight rune = '\u2530' // ┰ BoxDrawingsRightLightAndLeftDownHeavy rune = '\u2531' // ┱ BoxDrawingsLeftLightAndRightDownHeavy rune = '\u2532' // ┲ BoxDrawingsHeavyDownAndHorizontal rune = '\u2533' // ┳ BoxDrawingsLightUpAndHorizontal rune = '\u2534' // ┴ BoxDrawingsLeftHeavyAndRightUpLight rune = '\u2535' // ┵ BoxDrawingsRightHeavyAndLeftUpLight rune = '\u2536' // ┶ BoxDrawingsUpLightAndHorizontalHeavy rune = '\u2537' // ┷ BoxDrawingsUpHeavyAndHorizontalLight rune = '\u2538' // ┸ BoxDrawingsRightLightAndLeftUpHeavy rune = '\u2539' // ┹ BoxDrawingsLeftLightAndRightUpHeavy rune = '\u253a' // ┺ BoxDrawingsHeavyUpAndHorizontal rune = '\u253b' // ┻ BoxDrawingsLightVerticalAndHorizontal rune = '\u253c' // ┼ BoxDrawingsLeftHeavyAndRightVerticalLight rune = '\u253d' // ┽ BoxDrawingsRightHeavyAndLeftVerticalLight rune = '\u253e' // ┾ BoxDrawingsVerticalLightAndHorizontalHeavy rune = '\u253f' // ┿ BoxDrawingsUpHeavyAndDownHorizontalLight rune = '\u2540' // ╀ BoxDrawingsDownHeavyAndUpHorizontalLight rune = '\u2541' // ╁ BoxDrawingsVerticalHeavyAndHorizontalLight rune = '\u2542' // ╂ BoxDrawingsLeftUpHeavyAndRightDownLight rune = '\u2543' // ╃ BoxDrawingsRightUpHeavyAndLeftDownLight rune = '\u2544' // ╄ BoxDrawingsLeftDownHeavyAndRightUpLight rune = '\u2545' // ╅ BoxDrawingsRightDownHeavyAndLeftUpLight rune = '\u2546' // ╆ BoxDrawingsDownLightAndUpHorizontalHeavy rune = '\u2547' // ╇ BoxDrawingsUpLightAndDownHorizontalHeavy rune = '\u2548' // ╈ BoxDrawingsRightLightAndLeftVerticalHeavy rune = '\u2549' // ╉ BoxDrawingsLeftLightAndRightVerticalHeavy rune = '\u254a' // ╊ BoxDrawingsHeavyVerticalAndHorizontal rune = '\u254b' // ╋ BoxDrawingsLightDoubleDashHorizontal rune = '\u254c' // ╌ BoxDrawingsHeavyDoubleDashHorizontal rune = '\u254d' // ╍ BoxDrawingsLightDoubleDashVertical rune = '\u254e' // ╎ BoxDrawingsHeavyDoubleDashVertical rune = '\u254f' // ╏ BoxDrawingsDoubleHorizontal rune = '\u2550' // ═ BoxDrawingsDoubleVertical rune = '\u2551' // ║ BoxDrawingsDownSingleAndRightDouble rune = '\u2552' // ╒ BoxDrawingsDownDoubleAndRightSingle rune = '\u2553' // ╓ BoxDrawingsDoubleDownAndRight rune = '\u2554' // ╔ BoxDrawingsDownSingleAndLeftDouble rune = '\u2555' // ╕ BoxDrawingsDownDoubleAndLeftSingle rune = '\u2556' // ╖ BoxDrawingsDoubleDownAndLeft rune = '\u2557' // ╗ BoxDrawingsUpSingleAndRightDouble rune = '\u2558' // ╘ BoxDrawingsUpDoubleAndRightSingle rune = '\u2559' // ╙ BoxDrawingsDoubleUpAndRight rune = '\u255a' // ╚ BoxDrawingsUpSingleAndLeftDouble rune = '\u255b' // ╛ BoxDrawingsUpDobuleAndLeftSingle rune = '\u255c' // ╜ BoxDrawingsDoubleUpAndLeft rune = '\u255d' // ╝ BoxDrawingsVerticalSingleAndRightDouble rune = '\u255e' // ╞ BoxDrawingsVerticalDoubleAndRightSingle rune = '\u255f' // ╟ BoxDrawingsDoubleVerticalAndRight rune = '\u2560' // ╠ BoxDrawingsVerticalSingleAndLeftDouble rune = '\u2561' // ╡ BoxDrawingsVerticalDoubleAndLeftSingle rune = '\u2562' // ╢ BoxDrawingsDoubleVerticalAndLeft rune = '\u2563' // ╣ BoxDrawingsDownSingleAndHorizontalDouble rune = '\u2564' // ╤ BoxDrawingsDownDoubleAndHorizontalSingle rune = '\u2565' // ╥ BoxDrawingsDoubleDownAndHorizontal rune = '\u2566' // ╦ BoxDrawingsUpSingleAndHorizontalDouble rune = '\u2567' // ╧ BoxDrawingsUpDoubleAndHorizontalSingle rune = '\u2568' // ╨ BoxDrawingsDoubleUpAndHorizontal rune = '\u2569' // ╩ BoxDrawingsVerticalSingleAndHorizontalDouble rune = '\u256a' // ╪ BoxDrawingsVerticalDoubleAndHorizontalSingle rune = '\u256b' // ╫ BoxDrawingsDoubleVerticalAndHorizontal rune = '\u256c' // ╬ BoxDrawingsLightArcDownAndRight rune = '\u256d' // ╭ BoxDrawingsLightArcDownAndLeft rune = '\u256e' // ╮ BoxDrawingsLightArcUpAndLeft rune = '\u256f' // ╯ BoxDrawingsLightArcUpAndRight rune = '\u2570' // ╰ BoxDrawingsLightDiagonalUpperRightToLowerLeft rune = '\u2571' // ╱ BoxDrawingsLightDiagonalUpperLeftToLowerRight rune = '\u2572' // ╲ BoxDrawingsLightDiagonalCross rune = '\u2573' // ╳ BoxDrawingsLightLeft rune = '\u2574' // ╴ BoxDrawingsLightUp rune = '\u2575' // ╵ BoxDrawingsLightRight rune = '\u2576' // ╶ BoxDrawingsLightDown rune = '\u2577' // ╷ BoxDrawingsHeavyLeft rune = '\u2578' // ╸ BoxDrawingsHeavyUp rune = '\u2579' // ╹ BoxDrawingsHeavyRight rune = '\u257a' // ╺ BoxDrawingsHeavyDown rune = '\u257b' // ╻ BoxDrawingsLightLeftAndHeavyRight rune = '\u257c' // ╼ BoxDrawingsLightUpAndHeavyDown rune = '\u257d' // ╽ BoxDrawingsHeavyLeftAndLightRight rune = '\u257e' // ╾ BoxDrawingsHeavyUpAndLightDown rune = '\u257f' // ╿ )
Semigraphics provides an easy way to access unicode characters for drawing.
Named like the unicode characters, 'Semigraphics'-prefix used if unicode block isn't prefixed itself.
const ( AlignLeft = iota AlignCenter AlignRight )
Text alignment within a box.
Variables ¶
var ( // InputFieldInteger accepts integers. InputFieldInteger func(text string, ch rune) bool // InputFieldFloat accepts floating-point numbers. InputFieldFloat func(text string, ch rune) bool // InputFieldMaxLength returns an input field accept handler which accepts // input strings up to a given length. Use it like this: // // inputField.SetAcceptanceFunc(InputFieldMaxLength(10)) // Accept up to 10 characters. InputFieldMaxLength func(maxLength int) func(text string, ch rune) bool )
Predefined InputField acceptance functions.
var Borders = struct { Horizontal rune Vertical rune TopLeft rune TopRight rune BottomLeft rune BottomRight rune LeftT rune RightT rune TopT rune BottomT rune Cross rune HorizontalFocus rune VerticalFocus rune TopLeftFocus rune TopRightFocus rune BottomLeftFocus rune BottomRightFocus rune }{ Horizontal: BoxDrawingsLightHorizontal, Vertical: BoxDrawingsLightVertical, TopLeft: BoxDrawingsLightDownAndRight, TopRight: BoxDrawingsLightDownAndLeft, BottomLeft: BoxDrawingsLightUpAndRight, BottomRight: BoxDrawingsLightUpAndLeft, LeftT: BoxDrawingsLightVerticalAndRight, RightT: BoxDrawingsLightVerticalAndLeft, TopT: BoxDrawingsLightDownAndHorizontal, BottomT: BoxDrawingsLightUpAndHorizontal, Cross: BoxDrawingsLightVerticalAndHorizontal, HorizontalFocus: BoxDrawingsDoubleHorizontal, VerticalFocus: BoxDrawingsDoubleVertical, TopLeftFocus: BoxDrawingsDoubleDownAndRight, TopRightFocus: BoxDrawingsDoubleDownAndLeft, BottomLeftFocus: BoxDrawingsDoubleUpAndRight, BottomRightFocus: BoxDrawingsDoubleUpAndLeft, }
Borders defines various borders used when primitives are drawn. These may be changed to accommodate a different look and feel.
var DefaultFormFieldWidth = 10
DefaultFormFieldWidth is the default field screen width of form elements whose field width is flexible (0). This is used in the Form class for horizontal layouts.
var SemigraphicJoints = map[string]rune{ string([]rune{BoxDrawingsLightHorizontal, BoxDrawingsLightVertical}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightHorizontal, BoxDrawingsLightDownAndRight}): BoxDrawingsLightDownAndHorizontal, string([]rune{BoxDrawingsLightHorizontal, BoxDrawingsLightDownAndLeft}): BoxDrawingsLightDownAndHorizontal, string([]rune{BoxDrawingsLightHorizontal, BoxDrawingsLightUpAndRight}): BoxDrawingsLightUpAndHorizontal, string([]rune{BoxDrawingsLightHorizontal, BoxDrawingsLightUpAndLeft}): BoxDrawingsLightUpAndHorizontal, string([]rune{BoxDrawingsLightHorizontal, BoxDrawingsLightVerticalAndRight}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightHorizontal, BoxDrawingsLightVerticalAndLeft}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightHorizontal, BoxDrawingsLightDownAndHorizontal}): BoxDrawingsLightDownAndHorizontal, string([]rune{BoxDrawingsLightHorizontal, BoxDrawingsLightUpAndHorizontal}): BoxDrawingsLightUpAndHorizontal, string([]rune{BoxDrawingsLightHorizontal, BoxDrawingsLightVerticalAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightVertical, BoxDrawingsLightDownAndRight}): BoxDrawingsLightVerticalAndRight, string([]rune{BoxDrawingsLightVertical, BoxDrawingsLightDownAndLeft}): BoxDrawingsLightVerticalAndLeft, string([]rune{BoxDrawingsLightVertical, BoxDrawingsLightUpAndRight}): BoxDrawingsLightVerticalAndRight, string([]rune{BoxDrawingsLightVertical, BoxDrawingsLightUpAndLeft}): BoxDrawingsLightVerticalAndLeft, string([]rune{BoxDrawingsLightVertical, BoxDrawingsLightVerticalAndRight}): BoxDrawingsLightVerticalAndRight, string([]rune{BoxDrawingsLightVertical, BoxDrawingsLightVerticalAndLeft}): BoxDrawingsLightVerticalAndLeft, string([]rune{BoxDrawingsLightVertical, BoxDrawingsLightDownAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightVertical, BoxDrawingsLightUpAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightVertical, BoxDrawingsLightVerticalAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightDownAndRight, BoxDrawingsLightDownAndLeft}): BoxDrawingsLightDownAndHorizontal, string([]rune{BoxDrawingsLightDownAndRight, BoxDrawingsLightUpAndRight}): BoxDrawingsLightVerticalAndRight, string([]rune{BoxDrawingsLightDownAndRight, BoxDrawingsLightUpAndLeft}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightDownAndRight, BoxDrawingsLightVerticalAndRight}): BoxDrawingsLightVerticalAndRight, string([]rune{BoxDrawingsLightDownAndRight, BoxDrawingsLightVerticalAndLeft}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightDownAndRight, BoxDrawingsLightDownAndHorizontal}): BoxDrawingsLightDownAndHorizontal, string([]rune{BoxDrawingsLightDownAndRight, BoxDrawingsLightUpAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightDownAndRight, BoxDrawingsLightVerticalAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightDownAndLeft, BoxDrawingsLightUpAndRight}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightDownAndLeft, BoxDrawingsLightUpAndLeft}): BoxDrawingsLightVerticalAndLeft, string([]rune{BoxDrawingsLightDownAndLeft, BoxDrawingsLightVerticalAndRight}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightDownAndLeft, BoxDrawingsLightVerticalAndLeft}): BoxDrawingsLightVerticalAndLeft, string([]rune{BoxDrawingsLightDownAndLeft, BoxDrawingsLightDownAndHorizontal}): BoxDrawingsLightDownAndHorizontal, string([]rune{BoxDrawingsLightDownAndLeft, BoxDrawingsLightUpAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightDownAndLeft, BoxDrawingsLightVerticalAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightUpAndRight, BoxDrawingsLightUpAndLeft}): BoxDrawingsLightUpAndHorizontal, string([]rune{BoxDrawingsLightUpAndRight, BoxDrawingsLightVerticalAndRight}): BoxDrawingsLightVerticalAndRight, string([]rune{BoxDrawingsLightUpAndRight, BoxDrawingsLightVerticalAndLeft}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightUpAndRight, BoxDrawingsLightDownAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightUpAndRight, BoxDrawingsLightUpAndHorizontal}): BoxDrawingsLightUpAndHorizontal, string([]rune{BoxDrawingsLightUpAndRight, BoxDrawingsLightVerticalAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightUpAndLeft, BoxDrawingsLightVerticalAndRight}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightUpAndLeft, BoxDrawingsLightVerticalAndLeft}): BoxDrawingsLightVerticalAndLeft, string([]rune{BoxDrawingsLightUpAndLeft, BoxDrawingsLightDownAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightUpAndLeft, BoxDrawingsLightUpAndHorizontal}): BoxDrawingsLightUpAndHorizontal, string([]rune{BoxDrawingsLightUpAndLeft, BoxDrawingsLightVerticalAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightVerticalAndRight, BoxDrawingsLightVerticalAndLeft}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightVerticalAndRight, BoxDrawingsLightDownAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightVerticalAndRight, BoxDrawingsLightUpAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightVerticalAndRight, BoxDrawingsLightVerticalAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightVerticalAndLeft, BoxDrawingsLightDownAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightVerticalAndLeft, BoxDrawingsLightUpAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightVerticalAndLeft, BoxDrawingsLightVerticalAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightDownAndHorizontal, BoxDrawingsLightUpAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightDownAndHorizontal, BoxDrawingsLightVerticalAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, string([]rune{BoxDrawingsLightUpAndHorizontal, BoxDrawingsLightVerticalAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, }
SemigraphicJoints is a map for joining semigraphic (or otherwise) runes. So far only light lines are supported but if you want to change the border styling you need to provide the joints, too. The matching will be sorted ascending by rune value, so you don't need to provide all rune combinations, e.g. (─) + (│) = (┼) will also match (│) + (─) = (┼)
var Styles = struct { PrimitiveBackgroundColor tcell.Color // Main background color for primitives. ContrastBackgroundColor tcell.Color // Background color for contrasting elements. MoreContrastBackgroundColor tcell.Color // Background color for even more contrasting elements. BorderColor tcell.Color // Box borders. TitleColor tcell.Color // Box titles. GraphicsColor tcell.Color // Graphics. PrimaryTextColor tcell.Color // Primary text. SecondaryTextColor tcell.Color // Secondary text (e.g. labels). TertiaryTextColor tcell.Color // Tertiary text (e.g. subtitles, notes). InverseTextColor tcell.Color // Text on primary-colored backgrounds. ContrastSecondaryTextColor tcell.Color // Secondary text on ContrastBackgroundColor-colored backgrounds. }{ PrimitiveBackgroundColor: tcell.ColorBlack, ContrastBackgroundColor: tcell.ColorBlue, MoreContrastBackgroundColor: tcell.ColorGreen, BorderColor: tcell.ColorWhite, TitleColor: tcell.ColorWhite, GraphicsColor: tcell.ColorWhite, PrimaryTextColor: tcell.ColorWhite, SecondaryTextColor: tcell.ColorYellow, TertiaryTextColor: tcell.ColorGreen, InverseTextColor: tcell.ColorBlue, ContrastSecondaryTextColor: tcell.ColorDarkCyan, }
Styles defines various colors used when primitives are initialized. These may be changed to accommodate a different look and feel.
The default is for applications with a black background and basic colors: black, white, yellow, green, and blue.
var TabSize = 4
TabSize is the number of spaces with which a tab character will be replaced.
Functions ¶
func ANSIIWriter ¶
ANSIIWriter returns an io.Writer which translates any ANSII escape codes written to it into tview color tags. Other escape codes don't have an effect and are simply removed. The translated text is written to the provided writer.
func Escape ¶
Escape escapes the given text such that color and/or region tags are not recognized and substituted by the print functions of this package. For example, to include a tag-like string in a box title or in a TextView:
box.SetTitle(tview.Escape("[squarebrackets]")) fmt.Fprint(textView, tview.Escape(`["quoted"]`))
func Print ¶
func Print(screen tcell.Screen, text string, x, y, maxWidth, align int, color tcell.Color) (int, int)
Print prints text onto the screen into the given box at (x,y,maxWidth,1), not exceeding that box. "align" is one of AlignLeft, AlignCenter, or AlignRight. The screen's background color will not be changed.
You can change the colors and text styles mid-text by inserting a color tag. See the package description for details.
Returns the number of actual runes printed (not including color tags) and the actual width used for the printed runes.
func PrintJoinedSemigraphics ¶
PrintJoinedSemigraphics prints a semigraphics rune into the screen at the given position with the given color, joining it with any existing semigraphics rune. Background colors are preserved. At this point, only regular single line borders are supported.
func PrintSimple ¶
PrintSimple prints white text to the screen at the given position.
func StringWidth ¶
StringWidth returns the width of the given string needed to print it on screen. The text may contain color tags which are not counted.
func TranslateANSII ¶
TranslateANSII replaces ANSII escape sequences found in the provided string with tview's color tags and returns the resulting string.
func WordWrap ¶
WordWrap splits a text such that each resulting line does not exceed the given screen width. Possible split points are after any punctuation or whitespace. Whitespace after split points will be dropped.
This function considers color tags to have no width.
Text is always split at newline characters ('\n').
Types ¶
type Application ¶
Application represents the top node of an application.
It is not strictly required to use this class as none of the other classes depend on it. However, it provides useful tools to set up an application and plays nicely with all widgets.
func NewApplication ¶
func NewApplication() *Application
NewApplication creates and returns a new application.
func (*Application) Draw ¶
func (a *Application) Draw() *Application
Draw refreshes the screen. It calls the Draw() function of the application's root primitive and then syncs the screen buffer.
func (*Application) GetAfterDrawFunc ¶
func (a *Application) GetAfterDrawFunc() func(screen tcell.Screen)
GetAfterDrawFunc returns the callback function installed with SetAfterDrawFunc() or nil if none has been installed.
func (*Application) GetBeforeDrawFunc ¶
func (a *Application) GetBeforeDrawFunc() func(screen tcell.Screen) bool
GetBeforeDrawFunc returns the callback function installed with SetBeforeDrawFunc() or nil if none has been installed.
func (*Application) GetFocus ¶
func (a *Application) GetFocus() Primitive
GetFocus returns the primitive which has the current focus. If none has it, nil is returned.
func (*Application) GetInputCapture ¶
func (a *Application) GetInputCapture() func(event *tcell.EventKey) *tcell.EventKey
GetInputCapture returns the function installed with SetInputCapture() or nil if no such function has been installed.
func (*Application) ResizeToFullScreen ¶
func (a *Application) ResizeToFullScreen(p Primitive) *Application
ResizeToFullScreen resizes the given primitive such that it fills the entire screen.
func (*Application) Run ¶
func (a *Application) Run() error
Run starts the application and thus the event loop. This function returns when Stop() was called.
func (*Application) SetAfterDrawFunc ¶
func (a *Application) SetAfterDrawFunc(handler func(screen tcell.Screen)) *Application
SetAfterDrawFunc installs a callback function which is invoked after the root primitive was drawn during screen updates.
Provide nil to uninstall the callback function.
func (*Application) SetBeforeDrawFunc ¶
func (a *Application) SetBeforeDrawFunc(handler func(screen tcell.Screen) bool) *Application
SetBeforeDrawFunc installs a callback function which is invoked just before the root primitive is drawn during screen updates. If the function returns true, drawing will not continue, i.e. the root primitive will not be drawn (and an after-draw-handler will not be called).
Note that the screen is not cleared by the application. To clear the screen, you may call screen.Clear().
Provide nil to uninstall the callback function.
func (*Application) SetFocus ¶
func (a *Application) SetFocus(p Primitive) *Application
SetFocus sets the focus on a new primitive. All key events will be redirected to that primitive. Callers must ensure that the primitive will handle key events.
Blur() will be called on the previously focused primitive. Focus() will be called on the new primitive.
func (*Application) SetInputCapture ¶
func (a *Application) SetInputCapture(capture func(event *tcell.EventKey) *tcell.EventKey) *Application
SetInputCapture sets a function which captures all key events before they are forwarded to the key event handler of the primitive which currently has focus. This function can then choose to forward that key event (or a different one) by returning it or stop the key event processing by returning nil.
Note that this also affects the default event handling of the application itself: Such a handler can intercept the Ctrl-C event which closes the applicatoon.
func (*Application) SetRoot ¶
func (a *Application) SetRoot(root Primitive, fullscreen bool) *Application
SetRoot sets the root primitive for this application. If "fullscreen" is set to true, the root primitive's position will be changed to fill the screen.
This function must be called at least once or nothing will be displayed when the application starts.
It also calls SetFocus() on the primitive.
func (*Application) Stop ¶
func (a *Application) Stop()
Stop stops the application, causing Run() to return.
func (*Application) Suspend ¶
func (a *Application) Suspend(f func()) bool
Suspend temporarily suspends the application by exiting terminal UI mode and invoking the provided function "f". When "f" returns, terminal UI mode is entered again and the application resumes.
A return value of true indicates that the application was suspended and "f" was called. If false is returned, the application was already suspended, terminal UI mode was not exited, and "f" was not called.
type Box ¶
type Box struct {
// contains filtered or unexported fields
}
Box implements Primitive with a background and optional elements such as a border and a title. Most subclasses keep their content contained in the box but don't necessarily have to.
Note that all classes which subclass from Box will also have access to its functions.
See https://github.com/rivo/tview/wiki/Box for an example.
func (*Box) GetDrawFunc ¶
GetDrawFunc returns the callback function which was installed with SetDrawFunc() or nil if no such function has been installed.
func (*Box) GetFocusable ¶
GetFocusable returns the item's Focusable.
func (*Box) GetInnerRect ¶
GetInnerRect returns the position of the inner rectangle (x, y, width, height), without the border and without any padding.
func (*Box) GetInputCapture ¶
GetInputCapture returns the function installed with SetInputCapture() or nil if no such function has been installed.
func (*Box) GetRect ¶
GetRect returns the current position of the rectangle, x, y, width, and height.
func (*Box) InputHandler ¶
InputHandler returns nil.
func (*Box) SetBackgroundColor ¶
SetBackgroundColor sets the box's background color.
func (*Box) SetBorder ¶
SetBorder sets the flag indicating whether or not the box should have a border.
func (*Box) SetBorderColor ¶
SetBorderColor sets the box's border color.
func (*Box) SetBorderPadding ¶
SetBorderPadding sets the size of the borders around the box content.
func (*Box) SetDrawFunc ¶
func (b *Box) SetDrawFunc(handler func(screen tcell.Screen, x, y, width, height int) (int, int, int, int)) *Box
SetDrawFunc sets a callback function which is invoked after the box primitive has been drawn. This allows you to add a more individual style to the box (and all primitives which extend it).
The function is provided with the box's dimensions (set via SetRect()). It must return the box's inner dimensions (x, y, width, height) which will be returned by GetInnerRect(), used by descendent primitives to draw their own content.
func (*Box) SetInputCapture ¶
SetInputCapture installs a function which captures key events before they are forwarded to the primitive's default key event handler. This function can then choose to forward that key event (or a different one) to the default handler by returning it. If nil is returned, the default handler will not be called.
Providing a nil handler will remove a previously existing handler.
func (*Box) SetTitleAlign ¶
SetTitleAlign sets the alignment of the title, one of AlignLeft, AlignCenter, or AlignRight.
func (*Box) SetTitleColor ¶
SetTitleColor sets the box's title color.
func (*Box) WrapInputHandler ¶
func (b *Box) WrapInputHandler(inputHandler func(*tcell.EventKey, func(p Primitive))) func(*tcell.EventKey, func(p Primitive))
WrapInputHandler wraps an input handler (see InputHandler()) with the functionality to capture input (see SetInputCapture()) before passing it on to the provided (default) input handler.
This is only meant to be used by subclassing primitives.
type Button ¶
type Button struct { *Box // contains filtered or unexported fields }
Button is labeled box that triggers an action when selected.
See https://github.com/rivo/tview/wiki/Button for an example.
func (*Button) InputHandler ¶
InputHandler returns the handler for this primitive.
func (*Button) SetBackgroundColorActivated ¶
SetBackgroundColorActivated sets the background color of the button text when the button is in focus.
func (*Button) SetBlurFunc ¶
SetBlurFunc sets a handler which is called when the user leaves the button. The callback function is provided with the key that was pressed, which is one of the following:
- KeyEscape: Leaving the button with no specific direction.
- KeyTab: Move to the next field.
- KeyBacktab: Move to the previous field.
func (*Button) SetLabelColor ¶
SetLabelColor sets the color of the button text.
func (*Button) SetLabelColorActivated ¶
SetLabelColorActivated sets the color of the button text when the button is in focus.
func (*Button) SetSelectedFunc ¶
SetSelectedFunc sets a handler which is called when the button was selected.
type Checkbox ¶
type Checkbox struct { *Box // contains filtered or unexported fields }
Checkbox implements a simple box for boolean values which can be checked and unchecked.
See https://github.com/rivo/tview/wiki/Checkbox for an example.
func (*Checkbox) GetFieldWidth ¶
GetFieldWidth returns this primitive's field width.
func (*Checkbox) InputHandler ¶
InputHandler returns the handler for this primitive.
func (*Checkbox) SetChangedFunc ¶
SetChangedFunc sets a handler which is called when the checked state of this checkbox was changed by the user. The handler function receives the new state.
func (*Checkbox) SetChecked ¶
SetChecked sets the state of the checkbox.
func (*Checkbox) SetDoneFunc ¶
SetDoneFunc sets a handler which is called when the user is done entering text. The callback function is provided with the key that was pressed, which is one of the following:
- KeyEscape: Abort text input.
- KeyTab: Move to the next field.
- KeyBacktab: Move to the previous field.
func (*Checkbox) SetFieldBackgroundColor ¶
SetFieldBackgroundColor sets the background color of the input area.
func (*Checkbox) SetFieldTextColor ¶
SetFieldTextColor sets the text color of the input area.
func (*Checkbox) SetFinishedFunc ¶
SetFinishedFunc sets a callback invoked when the user leaves this form item.
func (*Checkbox) SetFormAttributes ¶
func (c *Checkbox) SetFormAttributes(labelWidth int, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem
SetFormAttributes sets attributes shared by all form items.
func (*Checkbox) SetLabelColor ¶
SetLabelColor sets the color of the label.
func (*Checkbox) SetLabelWidth ¶
SetLabelWidth sets the screen width of the label. A value of 0 will cause the primitive to use the width of the label string.
type DropDown ¶
type DropDown struct { *Box // contains filtered or unexported fields }
DropDown implements a selection widget whose options become visible in a drop-down list when activated.
See https://github.com/rivo/tview/wiki/DropDown for an example.
func (*DropDown) AddOption ¶
AddOption adds a new selectable option to this drop-down. The "selected" callback is called when this option was selected. It may be nil.
func (*DropDown) GetCurrentOption ¶
GetCurrentOption returns the index of the currently selected option as well as its text. If no option was selected, -1 and an empty string is returned.
func (*DropDown) GetFieldWidth ¶
GetFieldWidth returns this primitive's field screen width.
func (*DropDown) InputHandler ¶
InputHandler returns the handler for this primitive.
func (*DropDown) SetCurrentOption ¶
SetCurrentOption sets the index of the currently selected option. This may be a negative value to indicate that no option is currently selected.
func (*DropDown) SetDoneFunc ¶
SetDoneFunc sets a handler which is called when the user is done selecting options. The callback function is provided with the key that was pressed, which is one of the following:
- KeyEscape: Abort selection.
- KeyTab: Move to the next field.
- KeyBacktab: Move to the previous field.
func (*DropDown) SetFieldBackgroundColor ¶
SetFieldBackgroundColor sets the background color of the options area.
func (*DropDown) SetFieldTextColor ¶
SetFieldTextColor sets the text color of the options area.
func (*DropDown) SetFieldWidth ¶
SetFieldWidth sets the screen width of the options area. A value of 0 means extend to as long as the longest option text.
func (*DropDown) SetFinishedFunc ¶
SetFinishedFunc sets a callback invoked when the user leaves this form item.
func (*DropDown) SetFormAttributes ¶
func (d *DropDown) SetFormAttributes(labelWidth int, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem
SetFormAttributes sets attributes shared by all form items.
func (*DropDown) SetLabelColor ¶
SetLabelColor sets the color of the label.
func (*DropDown) SetLabelWidth ¶
SetLabelWidth sets the screen width of the label. A value of 0 will cause the primitive to use the width of the label string.
func (*DropDown) SetOptions ¶
SetOptions replaces all current options with the ones provided and installs one callback function which is called when one of the options is selected. It will be called with the option's text and its index into the options slice. The "selected" parameter may be nil.
type Flex ¶
type Flex struct { *Box // contains filtered or unexported fields }
Flex is a basic implementation of the Flexbox layout. The contained primitives are arranged horizontally or vertically. The way they are distributed along that dimension depends on their layout settings, which is either a fixed length or a proportional length. See AddItem() for details.
See https://github.com/rivo/tview/wiki/Flex for an example.
func NewFlex ¶
func NewFlex() *Flex
NewFlex returns a new flexbox layout container with no primitives and its direction set to FlexColumn. To add primitives to this layout, see AddItem(). To change the direction, see SetDirection().
Note that Box, the superclass of Flex, will have its background color set to transparent so that any nil flex items will leave their background unchanged. To clear a Flex's background before any items are drawn, set it to the desired color:
flex.SetBackgroundColor(tview.Styles.PrimitiveBackgroundColor)
func (*Flex) AddItem ¶
AddItem adds a new item to the container. The "fixedSize" argument is a width or height that may not be changed by the layout algorithm. A value of 0 means that its size is flexible and may be changed. The "proportion" argument defines the relative size of the item compared to other flexible-size items. For example, items with a proportion of 2 will be twice as large as items with a proportion of 1. The proportion must be at least 1 if fixedSize == 0 (ignored otherwise).
If "focus" is set to true, the item will receive focus when the Flex primitive receives focus. If multiple items have the "focus" flag set to true, the first one will receive focus.
You can provide a nil value for the primitive. This will still consume screen space but nothing will be drawn.
func (*Flex) RemoveItem ¶
RemoveItem removes all items for the given primitive from the container, keeping the order of the remaining items intact.
func (*Flex) ResizeItem ¶
ResizeItem sets a new size for the item(s) with the given primitive. If there are multiple Flex items with the same primitive, they will all receive the same size. For details regarding the size parameters, see AddItem().
func (*Flex) SetDirection ¶
SetDirection sets the direction in which the contained primitives are distributed. This can be either FlexColumn (default) or FlexRow.
func (*Flex) SetFullScreen ¶
SetFullScreen sets the flag which, when true, causes the flex layout to use the entire screen space instead of whatever size it is currently assigned to.
type Focusable ¶
type Focusable interface {
HasFocus() bool
}
Focusable provides a method which determines if a primitive has focus. Composed primitives may be focused based on the focused state of their contained primitives.
type Form ¶
type Form struct { *Box // contains filtered or unexported fields }
Form allows you to combine multiple one-line form elements into a vertical or horizontal layout. Form elements include types such as InputField or Checkbox. These elements can be optionally followed by one or more buttons for which you can define form-wide actions (e.g. Save, Clear, Cancel).
See https://github.com/rivo/tview/wiki/Form for an example.
func (*Form) AddButton ¶
AddButton adds a new button to the form. The "selected" function is called when the user selects this button. It may be nil.
func (*Form) AddCheckbox ¶
AddCheckbox adds a checkbox to the form. It has a label, an initial state, and an (optional) callback function which is invoked when the state of the checkbox was changed by the user.
func (*Form) AddDropDown ¶
func (f *Form) AddDropDown(label string, options []string, initialOption int, selected func(option string, optionIndex int)) *Form
AddDropDown adds a drop-down element to the form. It has a label, options, and an (optional) callback function which is invoked when an option was selected. The initial option may be a negative value to indicate that no option is currently selected.
func (*Form) AddFormItem ¶
AddFormItem adds a new item to the form. This can be used to add your own objects to the form. Note, however, that the Form class will override some of its attributes to make it work in the form context. Specifically, these are:
- The label width
- The label color
- The background color
- The field text color
- The field background color
func (*Form) AddInputField ¶
func (f *Form) AddInputField(label, value string, fieldWidth int, accept func(textToCheck string, lastChar rune) bool, changed func(text string)) *Form
AddInputField adds an input field to the form. It has a label, an optional initial value, a field width (a value of 0 extends it as far as possible), an optional accept function to validate the item's value (set to nil to accept any text), and an (optional) callback function which is invoked when the input field's text has changed.
func (*Form) AddPasswordField ¶
func (f *Form) AddPasswordField(label, value string, fieldWidth int, mask rune, changed func(text string)) *Form
AddPasswordField adds a password field to the form. This is similar to an input field except that the user's input not shown. Instead, a "mask" character is displayed. The password field has a label, an optional initial value, a field width (a value of 0 extends it as far as possible), and an (optional) callback function which is invoked when the input field's text has changed.
func (*Form) Clear ¶
Clear removes all input elements from the form, including the buttons if specified.
func (*Form) GetFormItem ¶
GetFormItem returns the form element at the given position, starting with index 0. Elements are referenced in the order they were added. Buttons are not included.
func (*Form) GetFormItemByLabel ¶
GetFormItemByLabel returns the first form element with the given label. If no such element is found, nil is returned. Buttons are not searched and will therefore not be returned.
func (*Form) SetButtonBackgroundColor ¶
SetButtonBackgroundColor sets the background color of the buttons.
func (*Form) SetButtonTextColor ¶
SetButtonTextColor sets the color of the button texts.
func (*Form) SetButtonsAlign ¶
SetButtonsAlign sets how the buttons align horizontally, one of AlignLeft (the default), AlignCenter, and AlignRight. This is only
func (*Form) SetCancelFunc ¶
SetCancelFunc sets a handler which is called when the user hits the Escape key.
func (*Form) SetFieldBackgroundColor ¶
SetFieldBackgroundColor sets the background color of the input areas.
func (*Form) SetFieldTextColor ¶
SetFieldTextColor sets the text color of the input areas.
func (*Form) SetHorizontal ¶
SetHorizontal sets the direction the form elements are laid out. If set to true, instead of positioning them from top to bottom (the default), they are positioned from left to right, moving into the next row if there is not enough space.
func (*Form) SetItemPadding ¶
SetItemPadding sets the number of empty rows between form items for vertical layouts and the number of empty cells between form items for horizontal layouts.
type FormItem ¶
type FormItem interface { Primitive // GetLabel returns the item's label text. GetLabel() string // SetFormAttributes sets a number of item attributes at once. SetFormAttributes(labelWidth int, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem // GetFieldWidth returns the width of the form item's field (the area which // is manipulated by the user) in number of screen cells. A value of 0 // indicates the the field width is flexible and may use as much space as // required. GetFieldWidth() int // SetEnteredFunc sets the handler function for when the user finished // entering data into the item. The handler may receive events for the // Enter key (we're done), the Escape key (cancel input), the Tab key (move to // next field), and the Backtab key (move to previous field). SetFinishedFunc(handler func(key tcell.Key)) FormItem }
FormItem is the interface all form items must implement to be able to be included in a form.
type Frame ¶
type Frame struct { *Box // contains filtered or unexported fields }
Frame is a wrapper which adds a border around another primitive. The top area (header) and the bottom area (footer) may also contain text.
See https://github.com/rivo/tview/wiki/Frame for an example.
func NewFrame ¶
NewFrame returns a new frame around the given primitive. The primitive's size will be changed to fit within this frame.
func (*Frame) AddText ¶
AddText adds text to the frame. Set "header" to true if the text is to appear in the header, above the contained primitive. Set it to false for it to appear in the footer, below the contained primitive. "align" must be one of the Align constants. Rows in the header are printed top to bottom, rows in the footer are printed bottom to top. Note that long text can overlap as different alignments will be placed on the same row.
func (*Frame) SetBorders ¶
SetBorders sets the width of the frame borders as well as "header" and "footer", the vertical space between the header and footer text and the contained primitive (does not apply if there is no text).
type Grid ¶
type Grid struct { *Box // contains filtered or unexported fields }
Grid is an implementation of a grid-based layout. It works by defining the size of the rows and columns, then placing primitives into the grid.
Some settings can lead to the grid exceeding its available space. SetOffset() can then be used to scroll in steps of rows and columns. These offset values can also be controlled with the arrow keys (or the "g","G", "j", "k", "h", and "l" keys) while the grid has focus and none of its contained primitives do.
See https://github.com/rivo/tview/wiki/Grid for an example.
func NewGrid ¶
func NewGrid() *Grid
NewGrid returns a new grid-based layout container with no initial primitives.
Note that Box, the superclass of Grid, will have its background color set to transparent so that any grid areas not covered by any primitives will leave their background unchanged. To clear a Grid's background before any items are drawn, set it to the desired color:
grid.SetBackgroundColor(tview.Styles.PrimitiveBackgroundColor)
func (*Grid) AddItem ¶
func (g *Grid) AddItem(p Primitive, row, column, height, width, minGridHeight, minGridWidth int, focus bool) *Grid
AddItem adds a primitive and its position to the grid. The top-left corner of the primitive will be located in the top-left corner of the grid cell at the given row and column and will span "width" rows and "height" columns. For example, for a primitive to occupy rows 2, 3, and 4 and columns 5 and 6:
grid.AddItem(p, 2, 4, 3, 2, true)
If width or height is 0, the primitive will not be drawn.
You can add the same primitive multiple times with different grid positions. The minGridWidth and minGridHeight values will then determine which of those positions will be used. This is similar to CSS media queries. These minimum values refer to the overall size of the grid. If multiple items for the same primitive apply, the one that has at least one highest minimum value will be used, or the primitive added last if those values are the same. Example:
grid.AddItem(p, 0, 0, 0, 0, 0, 0, true). // Hide in small grids. AddItem(p, 0, 0, 1, 2, 100, 0, true). // One-column layout for medium grids. AddItem(p, 1, 1, 3, 2, 300, 0, true) // Multi-column layout for large grids.
To use the same grid layout for all sizes, simply set minGridWidth and minGridHeight to 0.
If the item's focus is set to true, it will receive focus when the grid receives focus. If there are multiple items with a true focus flag, the last visible one that was added will receive focus.
func (*Grid) GetOffset ¶
GetOffset returns the current row and column offset (see SetOffset() for details).
func (*Grid) InputHandler ¶
InputHandler returns the handler for this primitive.
func (*Grid) RemoveItem ¶
RemoveItem removes all items for the given primitive from the grid, keeping the order of the remaining items intact.
func (*Grid) SetBorders ¶
SetBorders sets whether or not borders are drawn around grid items. Setting this value to true will cause the gap values (see SetGap()) to be ignored and automatically assumed to be 1 where the border graphics are drawn.
func (*Grid) SetBordersColor ¶
SetBordersColor sets the color of the item borders.
func (*Grid) SetColumns ¶
SetColumns defines how the columns of the grid are distributed. These values behave the same as the row values provided with SetRows(), see there for a definition and examples.
The provided values correspond to column heights, the first value defining the height of the topmost column.
func (*Grid) SetGap ¶
SetGap sets the size of the gaps between neighboring primitives on the grid. If borders are drawn (see SetBorders()), these values are ignored and a gap of 1 is assumed. Panics if negative values are provided.
func (*Grid) SetMinSize ¶
SetMinSize sets an absolute minimum width for rows and an absolute minimum height for columns. Panics if negative values are provided.
func (*Grid) SetOffset ¶
SetOffset sets the number of rows and columns which are skipped before drawing the first grid cell in the top-left corner. As the grid will never completely move off the screen, these values may be adjusted the next time the grid is drawn. The actual position of the grid may also be adjusted such that contained primitives that have focus are visible.
func (*Grid) SetRows ¶
SetRows defines how the rows of the grid are distributed. Each value defines the size of one row, starting with the leftmost row. Values greater 0 represent absolute row widths (gaps not included). Values less or equal 0 represent proportional row widths or fractions of the remaining free space, where 0 is treated the same as -1. That is, a row with a value of -3 will have three times the width of a row with a value of -1 (or 0). The minimum width set with SetMinSize() is always observed.
Primitives may extend beyond the rows defined explicitly with this function. A value of 0 is assumed for any undefined row. In fact, if you never call this function, all rows occupied by primitives will have the same width. On the other hand, unoccupied rows defined with this function will always take their place.
Assuming a total width of the grid of 100 cells and a minimum width of 0, the following call will result in rows with widths of 30, 10, 15, 15, and 30 cells:
grid.SetRows(30, 10, -1, -1, -2)
If a primitive were then placed in the 6th and 7th row, the resulting widths would be: 30, 10, 10, 10, 20, 10, and 10 cells.
If you then called SetMinSize() as follows:
grid.SetMinSize(15, 20)
The resulting widths would be: 30, 15, 15, 15, 20, 15, and 15 cells, a total of 125 cells, 25 cells wider than the available grid width.
type InputField ¶
type InputField struct { *Box // contains filtered or unexported fields }
InputField is a one-line box (three lines if there is a title) where the user can enter text.
Use SetMaskCharacter() to hide input from onlookers (e.g. for password input).
See https://github.com/rivo/tview/wiki/InputField for an example.
func (*InputField) Draw ¶
func (i *InputField) Draw(screen tcell.Screen)
Draw draws this primitive onto the screen.
func (*InputField) GetFieldWidth ¶
func (i *InputField) GetFieldWidth() int
GetFieldWidth returns this primitive's field width.
func (*InputField) GetLabel ¶
func (i *InputField) GetLabel() string
GetLabel returns the text to be displayed before the input area.
func (*InputField) GetText ¶
func (i *InputField) GetText() string
GetText returns the current text of the input field.
func (*InputField) InputHandler ¶
func (i *InputField) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive))
InputHandler returns the handler for this primitive.
func (*InputField) SetAcceptanceFunc ¶
func (i *InputField) SetAcceptanceFunc(handler func(textToCheck string, lastChar rune) bool) *InputField
SetAcceptanceFunc sets a handler which may reject the last character that was entered (by returning false).
This package defines a number of variables Prefixed with InputField which may be used for common input (e.g. numbers, maximum text length).
func (*InputField) SetChangedFunc ¶
func (i *InputField) SetChangedFunc(handler func(text string)) *InputField
SetChangedFunc sets a handler which is called whenever the text of the input field has changed. It receives the current text (after the change).
func (*InputField) SetDoneFunc ¶
func (i *InputField) SetDoneFunc(handler func(key tcell.Key)) *InputField
SetDoneFunc sets a handler which is called when the user is done entering text. The callback function is provided with the key that was pressed, which is one of the following:
- KeyEnter: Done entering text.
- KeyEscape: Abort text input.
- KeyTab: Move to the next field.
- KeyBacktab: Move to the previous field.
func (*InputField) SetFieldBackgroundColor ¶
func (i *InputField) SetFieldBackgroundColor(color tcell.Color) *InputField
SetFieldBackgroundColor sets the background color of the input area.
func (*InputField) SetFieldTextColor ¶
func (i *InputField) SetFieldTextColor(color tcell.Color) *InputField
SetFieldTextColor sets the text color of the input area.
func (*InputField) SetFieldWidth ¶
func (i *InputField) SetFieldWidth(width int) *InputField
SetFieldWidth sets the screen width of the input area. A value of 0 means extend as much as possible.
func (*InputField) SetFinishedFunc ¶
func (i *InputField) SetFinishedFunc(handler func(key tcell.Key)) FormItem
SetFinishedFunc sets a callback invoked when the user leaves this form item.
func (*InputField) SetFormAttributes ¶
func (i *InputField) SetFormAttributes(labelWidth int, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem
SetFormAttributes sets attributes shared by all form items.
func (*InputField) SetLabel ¶
func (i *InputField) SetLabel(label string) *InputField
SetLabel sets the text to be displayed before the input area.
func (*InputField) SetLabelColor ¶
func (i *InputField) SetLabelColor(color tcell.Color) *InputField
SetLabelColor sets the color of the label.
func (*InputField) SetLabelWidth ¶
func (i *InputField) SetLabelWidth(width int) *InputField
SetLabelWidth sets the screen width of the label. A value of 0 will cause the primitive to use the width of the label string.
func (*InputField) SetMaskCharacter ¶
func (i *InputField) SetMaskCharacter(mask rune) *InputField
SetMaskCharacter sets a character that masks user input on a screen. A value of 0 disables masking.
func (*InputField) SetPlaceholder ¶
func (i *InputField) SetPlaceholder(text string) *InputField
SetPlaceholder sets the text to be displayed when the input text is empty.
func (*InputField) SetPlaceholderTextColor ¶
func (i *InputField) SetPlaceholderTextColor(color tcell.Color) *InputField
SetPlaceholderTextColor sets the text color of placeholder text.
func (*InputField) SetText ¶
func (i *InputField) SetText(text string) *InputField
SetText sets the current text of the input field.
type List ¶
type List struct { *Box // contains filtered or unexported fields }
List displays rows of items, each of which can be selected.
See https://github.com/rivo/tview/wiki/List for an example.
func (*List) AddItem ¶
AddItem adds a new item to the list. An item has a main text which will be highlighted when selected. It also has a secondary text which is shown underneath the main text (if it is set to visible) but which may remain empty.
The shortcut is a key binding. If the specified rune is entered, the item is selected immediately. Set to 0 for no binding.
The "selected" callback will be invoked when the user selects the item. You may provide nil if no such item is needed or if all events are handled through the selected callback set with SetSelectedFunc().
func (*List) GetChosenItem ¶
func (*List) GetCurrentItem ¶
GetCurrentItem returns the index of the currently selected list item.
func (*List) GetItemCount ¶
GetItemCount returns the number of items in the list.
func (*List) GetItemText ¶
GetItemText returns an item's texts (main and secondary). Panics if the index is out of range.
func (*List) InputHandler ¶
InputHandler returns the handler for this primitive.
func (*List) SetChangedFunc ¶
SetChangedFunc sets the function which is called when the user navigates to a list item. The function receives the item's index in the list of items (starting with 0), its main text, secondary text, and its shortcut rune.
This function is also called when the first item is added or when SetCurrentItem() is called.
func (*List) SetChosenBackgroundColor ¶
func (*List) SetChosenFunc ¶
func (*List) SetChosenItem ¶
func (*List) SetCurrentItem ¶
SetCurrentItem sets the currently selected item by its index. This triggers a "changed" event.
func (*List) SetDoneFunc ¶
SetDoneFunc sets a function which is called when the user presses the Escape key.
func (*List) SetItemText ¶
SetItemText sets an item's main and secondary text. Panics if the index is out of range.
func (*List) SetMainTextColor ¶
SetMainTextColor sets the color of the items' main text.
func (*List) SetSecondaryTextColor ¶
SetSecondaryTextColor sets the color of the items' secondary text.
func (*List) SetSelectable ¶
func (*List) SetSelectedBackgroundColor ¶
SetSelectedBackgroundColor sets the background color of selected items.
func (*List) SetSelectedFunc ¶
SetSelectedFunc sets the function which is called when the user selects a list item by pressing Enter on the current selection. The function receives the item's index in the list of items (starting with 0), its main text, secondary text, and its shortcut rune.
func (*List) SetSelectedTextColor ¶
SetSelectedTextColor sets the text color of selected items.
func (*List) SetShortcutColor ¶
SetShortcutColor sets the color of the items' shortcut.
func (*List) ShowSecondaryText ¶
ShowSecondaryText determines whether or not to show secondary item texts.
type Modal ¶
type Modal struct { *Box // contains filtered or unexported fields }
Modal is a centered message window used to inform the user or prompt them for an immediate decision. It needs to have at least one button (added via AddButtons()) or it will never disappear.
See https://github.com/rivo/tview/wiki/Modal for an example.
func (*Modal) AddButtons ¶
AddButtons adds buttons to the window. There must be at least one button and a "done" handler so the window can be closed again.
func (*Modal) SetDoneFunc ¶
SetDoneFunc sets a handler which is called when one of the buttons was pressed. It receives the index of the button as well as its label text. The handler is also called when the user presses the Escape key. The index will then be negative and the label text an emptry string.
type Pages ¶
type Pages struct { *Box // contains filtered or unexported fields }
Pages is a container for other primitives often used as the application's root primitive. It allows to easily switch the visibility of the contained primitives.
See https://github.com/rivo/tview/wiki/Pages for an example.
func (*Pages) AddAndSwitchToPage ¶
AddAndSwitchToPage calls AddPage(), then SwitchToPage() on that newly added page.
func (*Pages) AddPage ¶
AddPage adds a new page with the given name and primitive. If there was previously a page with the same name, it is overwritten. Leaving the name empty may cause conflicts in other functions.
Visible pages will be drawn in the order they were added (unless that order was changed in one of the other functions). If "resize" is set to true, the primitive will be set to the size available to the Pages primitive whenever the pages are drawn.
func (*Pages) RemovePage ¶
RemovePage removes the page with the given name.
func (*Pages) SendToBack ¶
SendToBack changes the order of the pages such that the page with the given name comes first, causing it to be drawn first with the next update (if visible).
func (*Pages) SendToFront ¶
SendToFront changes the order of the pages such that the page with the given name comes last, causing it to be drawn last with the next update (if visible).
func (*Pages) SetChangedFunc ¶
SetChangedFunc sets a handler which is called whenever the visibility or the order of any visible pages changes. This can be used to redraw the pages.
func (*Pages) ShowPage ¶
ShowPage sets a page's visibility to "true" (in addition to any other pages which are already visible).
func (*Pages) SwitchToPage ¶
SwitchToPage sets a page's visibility to "true" and all other pages' visibility to "false".
type Primitive ¶
type Primitive interface { // Draw draws this primitive onto the screen. Implementers can call the // screen's ShowCursor() function but should only do so when they have focus. // (They will need to keep track of this themselves.) Draw(screen tcell.Screen) // GetRect returns the current position of the primitive, x, y, width, and // height. GetRect() (int, int, int, int) // SetRect sets a new position of the primitive. SetRect(x, y, width, height int) // InputHandler returns a handler which receives key events when it has focus. // It is called by the Application class. // // A value of nil may also be returned, in which case this primitive cannot // receive focus and will not process any key events. // // The handler will receive the key event and a function that allows it to // set the focus to a different primitive, so that future key events are sent // to that primitive. // // The Application's Draw() function will be called automatically after the // handler returns. // // The Box class provides functionality to intercept keyboard input. If you // subclass from Box, it is recommended that you wrap your handler using // Box.WrapInputHandler() so you inherit that functionality. InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) // Focus is called by the application when the primitive receives focus. // Implementers may call delegate() to pass the focus on to another primitive. Focus(delegate func(p Primitive)) // Blur is called by the application when the primitive loses focus. Blur() // GetFocusable returns the item's Focusable. GetFocusable() Focusable }
Primitive is the top-most interface for all graphical primitives.
type Table ¶
type Table struct { *Box // contains filtered or unexported fields }
Table visualizes two-dimensional data consisting of rows and columns. Each Table cell is defined via SetCell() by the TableCell type. They can be added dynamically to the table and changed any time.
The most compact display of a table is without borders. Each row will then occupy one row on screen and columns are separated by the rune defined via SetSeparator() (a space character by default).
When borders are turned on (via SetBorders()), each table cell is surrounded by lines. Therefore one table row will require two rows on screen.
Columns will use as much horizontal space as they need. You can constrain their size with the MaxWidth parameter of the TableCell type.
Fixed Columns ¶
You can define fixed rows and rolumns via SetFixed(). They will always stay in their place, even when the table is scrolled. Fixed rows are always the top rows. Fixed columns are always the leftmost columns.
Selections ¶
You can call SetSelectable() to set columns and/or rows to "selectable". If the flag is set only for columns, entire columns can be selected by the user. If it is set only for rows, entire rows can be selected. If both flags are set, individual cells can be selected. The "selected" handler set via SetSelectedFunc() is invoked when the user presses Enter on a selection.
Navigation ¶
If the table extends beyond the available space, it can be navigated with key bindings similar to Vim:
- h, left arrow: Move left by one column.
- l, right arrow: Move right by one column.
- j, down arrow: Move down by one row.
- k, up arrow: Move up by one row.
- g, home: Move to the top.
- G, end: Move to the bottom.
- Ctrl-F, page down: Move down by one page.
- Ctrl-B, page up: Move up by one page.
When there is no selection, this affects the entire table (except for fixed rows and columns). When there is a selection, the user moves the selection. The class will attempt to keep the selection from moving out of the screen.
Use SetInputCapture() to override or modify keyboard input.
See https://github.com/rivo/tview/wiki/Table for an example.
func (*Table) GetCell ¶
GetCell returns the contents of the cell at the specified position. A valid TableCell object is always returns but it will be uninitialized if the cell was not previously set.
func (*Table) GetColumnCount ¶
GetColumnCount returns the (maximum) number of columns in the table.
func (*Table) GetOffset ¶
GetOffset returns the current row and column offset. This indicates how many rows and columns the table is scrolled down and to the right.
func (*Table) GetRowCount ¶
GetRowCount returns the number of rows in the table.
func (*Table) GetSelectable ¶
GetSelectable returns what can be selected in a table. Refer to SetSelectable() for details.
func (*Table) GetSelection ¶
GetSelection returns the position of the current selection. If entire rows are selected, the column index is undefined. Likewise for entire columns.
func (*Table) InputHandler ¶
InputHandler returns the handler for this primitive.
func (*Table) ScrollToBeginning ¶
ScrollToBeginning scrolls the table to the beginning to that the top left corner of the table is shown. Note that this position may be corrected if there is a selection.
func (*Table) ScrollToEnd ¶
ScrollToEnd scrolls the table to the beginning to that the bottom left corner of the table is shown. Adding more rows to the table will cause it to automatically scroll with the new data. Note that this position may be corrected if there is a selection.
func (*Table) Select ¶
Select sets the selected cell. Depending on the selection settings specified via SetSelectable(), this may be an entire row or column, or even ignored completely.
func (*Table) SetBorders ¶
SetBorders sets whether or not each cell in the table is surrounded by a border.
func (*Table) SetBordersColor ¶
SetBordersColor sets the color of the cell borders.
func (*Table) SetCell ¶
SetCell sets the content of a cell the specified position. It is ok to directly instantiate a TableCell object. If the cell has contain, at least the Text and Color fields should be set.
Note that setting cells in previously unknown rows and columns will automatically extend the internal table representation, e.g. starting with a row of 100,000 will immediately create 100,000 empty rows.
To avoid unnecessary garbage collection, fill columns from left to right.
func (*Table) SetCellSimple ¶
SetCellSimple calls SetCell() with the given text, left-aligned, in white.
func (*Table) SetDoneFunc ¶
SetDoneFunc sets a handler which is called whenever the user presses the Escape, Tab, or Backtab key. If nothing is selected, it is also called when user presses the Enter key (because pressing Enter on a selection triggers the "selected" handler set via SetSelectedFunc()).
func (*Table) SetFixed ¶
SetFixed sets the number of fixed rows and columns which are always visible even when the rest of the cells are scrolled out of view. Rows are always the top-most ones. Columns are always the left-most ones.
func (*Table) SetOffset ¶
SetOffset sets how many rows and columns should be skipped when drawing the table. This is useful for large tables that do not fit on the screen. Navigating a selection can change these values.
Fixed rows and columns are never skipped.
func (*Table) SetSelectable ¶
SetSelectable sets the flags which determine what can be selected in a table. There are three selection modi:
- rows = false, columns = false: Nothing can be selected.
- rows = true, columns = false: Rows can be selected.
- rows = false, columns = true: Columns can be selected.
- rows = true, columns = true: Individual cells can be selected.
func (*Table) SetSelectedFunc ¶
SetSelectedFunc sets a handler which is called whenever the user presses the Enter key on a selected cell/row/column. The handler receives the position of the selection and its cell contents. If entire rows are selected, the column index is undefined. Likewise for entire columns.
func (*Table) SetSelectionChangedFunc ¶
SetSelectionChangedFunc sets a handler which is called whenever the user navigates to a new selection. The handler receives the position of the new selection. If entire rows are selected, the column index is undefined. Likewise for entire columns.
func (*Table) SetSeparator ¶
SetSeparator sets the character used to fill the space between two neighboring cells. This is a space character ' ' per default but you may want to set it to Borders.Vertical (or any other rune) if the column separation should be more visible. If cell borders are activated, this is ignored.
Separators have the same color as borders.
type TableCell ¶
type TableCell struct { // The text to be displayed in the table cell. Text string // The alignment of the cell text. One of AlignLeft (default), AlignCenter, // or AlignRight. Align int // The maximum width of the cell in screen space. This is used to give a // column a maximum width. Any cell text whose screen width exceeds this width // is cut off. Set to 0 if there is no maximum width. MaxWidth int // If the total table width is less than the available width, this value is // used to add extra width to a column. See SetExpansion() for details. Expansion int // The color of the cell text. Color tcell.Color // The background color of the cell. BackgroundColor tcell.Color // The style attributes of the cell. Attributes tcell.AttrMask // If set to true, this cell cannot be selected. NotSelectable bool // contains filtered or unexported fields }
TableCell represents one cell inside a Table. You can instantiate this type directly but all colors (background and text) will be set to their default which is black.
func NewTableCell ¶
NewTableCell returns a new table cell with sensible defaults. That is, left aligned text with the primary text color (see Styles) and a transparent background (using the background of the Table).
func (*TableCell) GetLastPosition ¶
GetLastPosition returns the position of the table cell the last time it was drawn on screen. If the cell is not on screen, the return values are undefined.
Because the Table class will attempt to keep selected cells on screen, this function is most useful in response to a "selected" event (see SetSelectedFunc()) or a "selectionChanged" event (see SetSelectionChangedFunc()).
func (*TableCell) SetAlign ¶
SetAlign sets the cell's text alignment, one of AlignLeft, AlignCenter, or AlignRight.
func (*TableCell) SetAttributes ¶
SetAttributes sets the cell's text attributes. You can combine different attributes using bitmask operations:
cell.SetAttributes(tcell.AttrUnderline | tcell.AttrBold)
func (*TableCell) SetBackgroundColor ¶
SetBackgroundColor sets the cell's background color. Set to tcell.ColorDefault to use the table's background color.
func (*TableCell) SetExpansion ¶
SetExpansion sets the value by which the column of this cell expands if the available width for the table is more than the table width (prior to applying this expansion value). This is a proportional value. The amount of unused horizontal space is divided into widths to be added to each column. How much extra width a column receives depends on the expansion value: A value of 0 (the default) will not cause the column to increase in width. Other values are proportional, e.g. a value of 2 will cause a column to grow by twice the amount of a column with a value of 1.
Since this value affects an entire column, the maximum over all visible cells in that column is used.
This function panics if a negative value is provided.
func (*TableCell) SetMaxWidth ¶
SetMaxWidth sets maximum width of the cell in screen space. This is used to give a column a maximum width. Any cell text whose screen width exceeds this width is cut off. Set to 0 if there is no maximum width.
func (*TableCell) SetSelectable ¶
SetSelectable sets whether or not this cell can be selected by the user.
func (*TableCell) SetStyle ¶
SetStyle sets the cell's style (foreground color, background color, and attributes) all at once.
type TextView ¶
TextView is a box which displays text. It implements the io.Writer interface so you can stream text to it. This does not trigger a redraw automatically but if a handler is installed via SetChangedFunc(), you can cause it to be redrawn.
Navigation ¶
If the text view is scrollable (the default), text is kept in a buffer which may be larger than the screen and can be navigated similarly to Vim:
- h, left arrow: Move left.
- l, right arrow: Move right.
- j, down arrow: Move down.
- k, up arrow: Move up.
- g, home: Move to the top.
- G, end: Move to the bottom.
- Ctrl-F, page down: Move down by one page.
- Ctrl-B, page up: Move up by one page.
If the text is not scrollable, any text above the top visible line is discarded.
Use SetInputCapture() to override or modify keyboard input.
Colors ¶
If dynamic colors are enabled via SetDynamicColors(), text color can be changed dynamically by embedding color strings in square brackets. This works the same way as anywhere else. Please see the package documentation for more information.
Regions and Highlights ¶
If regions are enabled via SetRegions(), you can define text regions within the text and assign region IDs to them. Text regions start with region tags. Region tags are square brackets that contain a region ID in double quotes, for example:
We define a ["rg"]region[""] here.
A text region ends with the next region tag. Tags with no region ID ([""]) don't start new regions. They can therefore be used to mark the end of a region. Region IDs must satisfy the following regular expression:
[a-zA-Z0-9_,;: \-\.]+
Regions can be highlighted by calling the Highlight() function with one or more region IDs. This can be used to display search results, for example.
The ScrollToHighlight() function can be used to jump to the currently highlighted region once when the text view is drawn the next time.
See https://github.com/rivo/tview/wiki/TextView for an example.
func (*TextView) GetHighlights ¶
GetHighlights returns the IDs of all currently highlighted regions.
func (*TextView) GetRegionText ¶
GetRegionText returns the text of the region with the given ID. If dynamic colors are enabled, color tags are stripped from the text. Newlines are always returned as '\n' runes.
If the region does not exist or if regions are turned off, an empty string is returned.
func (*TextView) Highlight ¶
Highlight specifies which regions should be highlighted. See class description for details on regions. Empty region strings are ignored.
Text in highlighted regions will be drawn inverted, i.e. with their background and foreground colors swapped.
Calling this function will remove any previous highlights. To remove all highlights, call this function without any arguments.
func (*TextView) InputHandler ¶
InputHandler returns the handler for this primitive.
func (*TextView) ScrollTo ¶
ScrollTo scrolls to the specified row and column (both starting with 0).
func (*TextView) ScrollToBeginning ¶
ScrollToBeginning scrolls to the top left corner of the text if the text view is scrollable.
func (*TextView) ScrollToEnd ¶
ScrollToEnd scrolls to the bottom left corner of the text if the text view is scrollable. Adding new rows to the end of the text view will cause it to scroll with the new data.
func (*TextView) ScrollToHighlight ¶
ScrollToHighlight will cause the visible area to be scrolled so that the highlighted regions appear in the visible area of the text view. This repositioning happens the next time the text view is drawn. It happens only once so you will need to call this function repeatedly to always keep highlighted regions in view.
Nothing happens if there are no highlighted regions or if the text view is not scrollable.
func (*TextView) SetChangedFunc ¶
SetChangedFunc sets a handler function which is called when the text of the text view has changed. This is typically used to cause the application to redraw the screen.
func (*TextView) SetDoneFunc ¶
SetDoneFunc sets a handler which is called when the user presses on the following keys: Escape, Enter, Tab, Backtab. The key is passed to the handler.
func (*TextView) SetDynamicColors ¶
SetDynamicColors sets the flag that allows the text color to be changed dynamically. See class description for details.
func (*TextView) SetRegions ¶
SetRegions sets the flag that allows to define regions in the text. See class description for details.
func (*TextView) SetScrollable ¶
SetScrollable sets the flag that decides whether or not the text view is scrollable. If true, text is kept in a buffer and can be navigated.
func (*TextView) SetText ¶
SetText sets the text of this text view to the provided string. Previously contained text will be removed.
func (*TextView) SetTextAlign ¶
SetTextAlign sets the text alignment within the text view. This must be either AlignLeft, AlignCenter, or AlignRight.
func (*TextView) SetTextColor ¶
SetTextColor sets the initial color of the text (which can be changed dynamically by sending color strings in square brackets to the text view if dynamic colors are enabled).
func (*TextView) SetWordWrap ¶
SetWordWrap sets the flag that, if true and if the "wrap" flag is also true (see SetWrap()), wraps the line at spaces or after punctuation marks. Note that trailing spaces will not be printed.
This flag is ignored if the "wrap" flag is false.
type TreeNode ¶
type TreeNode struct {
// contains filtered or unexported fields
}
TreeNode represents one node in a tree view.
func (*TreeNode) ClearChildren ¶
ClearChildren removes all child nodes from this node.
func (*TreeNode) CollapseAll ¶
CollapseAll collapses this node and all descendent nodes.
func (*TreeNode) GetChildren ¶
GetChildren returns this node's children.
func (*TreeNode) GetReference ¶
func (n *TreeNode) GetReference() interface{}
GetReference returns this node's reference object.
func (*TreeNode) IsExpanded ¶
IsExpanded returns whether the child nodes of this node are visible.
func (*TreeNode) SetChildren ¶
SetChildren sets this node's child nodes.
func (*TreeNode) SetExpanded ¶
SetExpanded sets whether or not this node's child nodes should be displayed.
func (*TreeNode) SetIndent ¶
SetIndent sets an additional indentation for this node's text. A value of 0 keeps the text as far left as possible with a minimum of line graphics. Any value greater than that moves the text to the right.
func (*TreeNode) SetReference ¶
SetReference allows you to store a reference of any type in this node. This will allow you to establish a mapping between the TreeView hierarchy and your internal tree structure.
func (*TreeNode) SetSelectable ¶
SetSelectable sets a flag indicating whether this node can be selected by the user.
func (*TreeNode) SetSelectedFunc ¶
SetSelectedFunc sets a function which is called when the user selects this node by hitting Enter when it is selected.
func (*TreeNode) Walk ¶
Walk traverses this node's subtree in depth-first, pre-order (NLR) order and calls the provided callback function on each traversed node (which includes this node) with the traversed node and its parent node (nil for this node). The callback returns whether traversal should continue with the traversed node's child nodes (true) or not recurse any deeper (false).
type TreeView ¶
type TreeView struct { *Box // contains filtered or unexported fields }
TreeView displays tree structures. A tree consists of nodes (TreeNode objects) where each node has zero or more child nodes and exactly one parent node (except for the root node which has no parent node).
The SetRoot() function is used to specify the root of the tree. Other nodes are added locally to the root node or any of its descendents. See the TreeNode documentation for details on node attributes. (You can use SetReference() to store a reference to nodes of your own tree structure.)
Nodes can be selected by calling SetCurrentNode(). The user can navigate the selection or the tree by using the following keys:
- j, down arrow, right arrow: Move (the selection) down by one node.
- k, up arrow, left arrow: Move (the selection) up by one node.
- g, home: Move (the selection) to the top.
- G, end: Move (the selection) to the bottom.
- Ctrl-F, page down: Move (the selection) down by one page.
- Ctrl-B, page up: Move (the selection) up by one page.
Selected nodes can trigger the "selected" callback when the user hits Enter.
The root node corresponds to level 0, its children correspond to level 1, their children to level 2, and so on. Per default, the first level that is displayed is 0, i.e. the root node. You can call SetTopLevel() to hide levels.
If graphics are turned on (see SetGraphics()), lines indicate the tree's hierarchy. Alternative (or additionally), you can set different prefixes using SetPrefixes() for different levels, for example to display hierarchical bullet point lists.
See https://github.com/rivo/tview/wiki/TreeView for an example.
func (*TreeView) GetCurrentNode ¶
GetCurrentNode returns the currently selected node or nil of no node is currently selected.
func (*TreeView) GetRoot ¶
GetRoot returns the root node of the tree. If no such node was previously set, nil is returned.
func (*TreeView) InputHandler ¶
InputHandler returns the handler for this primitive.
func (*TreeView) SetAlign ¶
SetAlign controls the horizontal alignment of the node texts. If set to true, all texts except that of top-level nodes will be placed in the same column. If set to false, they will indent with the hierarchy.
func (*TreeView) SetChangedFunc ¶
SetChangedFunc sets the function which is called when the user navigates to a new tree node.
func (*TreeView) SetCurrentNode ¶
SetCurrentNode sets the currently selected node. Provide nil to clear all selections. Selected nodes must be visible and selectable, or else the selection will be changed to the top-most selectable and visible node.
This function does NOT trigger the "changed" callback.
func (*TreeView) SetGraphics ¶
SetGraphics sets a flag which determines whether or not line graphics are drawn to illustrate the tree's hierarchy.
func (*TreeView) SetGraphicsColor ¶
SetGraphicsColor sets the colors of the lines used to draw the tree structure.
func (*TreeView) SetPrefixes ¶
SetPrefixes defines the strings drawn before the nodes' texts. This is a slice of strings where each element corresponds to a node's hierarchy level, i.e. 0 for the root, 1 for the root's children, and so on (levels will cycle).
For example, to display a hierarchical list with bullet points:
treeView.SetGraphics(false). SetPrefixes([]string{"* ", "- ", "x "})
func (*TreeView) SetSelectedFunc ¶
SetSelectedFunc sets the function which is called when the user selects a node by pressing Enter on the current selection.
func (*TreeView) SetTopLevel ¶
SetTopLevel sets the first tree level that is visible with 0 referring to the root, 1 to the root's child nodes, and so on. Nodes above the top level are not displayed.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
demos
|
|
box
Demo code for the Box primitive.
|
Demo code for the Box primitive. |
button
Demo code for the Button primitive.
|
Demo code for the Button primitive. |
checkbox
Demo code for the Checkbox primitive.
|
Demo code for the Checkbox primitive. |
dropdown
Demo code for the DropDown primitive.
|
Demo code for the DropDown primitive. |
flex
Demo code for the Flex primitive.
|
Demo code for the Flex primitive. |
form
Demo code for the Form primitive.
|
Demo code for the Form primitive. |
frame
Demo code for the Frame primitive.
|
Demo code for the Frame primitive. |
inputfield
Demo code for the InputField primitive.
|
Demo code for the InputField primitive. |
list
Demo code for the List primitive.
|
Demo code for the List primitive. |
modal
Demo code for the Modal primitive.
|
Demo code for the Modal primitive. |
pages
Demo code for the Pages primitive.
|
Demo code for the Pages primitive. |
presentation
A presentation of the tview package, implemented with tview.
|
A presentation of the tview package, implemented with tview. |
primitive
Demo code which illustrates how to implement your own primitive.
|
Demo code which illustrates how to implement your own primitive. |
table
Demo code for the Table primitive.
|
Demo code for the Table primitive. |
textview
Demo code for the TextView primitive.
|
Demo code for the TextView primitive. |
unicode
Demo code for unicode support (demonstrates wide Chinese characters).
|
Demo code for unicode support (demonstrates wide Chinese characters). |