### Basic tview Hello World Example Source: https://pkg.go.dev/github.com/rivo/tview This example demonstrates how to create a simple bordered box with a title and display it in the terminal using the tview application. ```go 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) } } ``` -------------------------------- ### Install tview Source: https://pkg.go.dev/github.com/rivo/tview Use this command to add the tview package to your Go project. ```bash go get github.com/rivo/tview@master ``` -------------------------------- ### Create a New TextView Source: https://pkg.go.dev/github.com/rivo/tview Instantiates a new TextView primitive. No setup is required before using it. ```go func NewTextView() *TextView ``` -------------------------------- ### Run a tview application Source: https://pkg.go.dev/github.com/rivo/tview This example demonstrates how to set the root primitive of a new tview application and run it until interrupted (e.g., Ctrl-C). ```go if err := tview.NewApplication().SetRoot(p, true).Run(); err != nil { panic(err) } ``` -------------------------------- ### Run Source: https://pkg.go.dev/github.com/rivo/tview Starts the Tview application and its event loop. This function blocks until Application.Stop() is called. Note that this function claims stdin, stdout, and stderr. ```APIDOC ## Run ### Description Starts the application and thus the event loop. This function returns when Application.Stop was called. Note that while an application is running, it fully claims stdin, stdout, and stderr. If you use these standard streams, they may not work as expected. Consider stopping the application first or suspending it (using Application.Suspend) if you have to interact with the standard streams, for example when needing to print a call stack during a panic. ### Signature ```go func (a *Application) Run() error ``` ``` -------------------------------- ### Application.SetRoot Source: https://pkg.go.dev/github.com/rivo/tview Sets the root primitive for the application. If fullscreen is true, the root primitive will fill the screen. This must be called before starting the application. ```APIDOC ## Application.SetRoot ### Description 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. ### Method func (a *Application) SetRoot(root Primitive, fullscreen bool) *Application ### Parameters - **root** (Primitive) - Required - The root primitive to set. - **fullscreen** (bool) - Required - Whether the root primitive should fill the screen. ### Returns - *Application - The Application instance for chaining. ``` -------------------------------- ### Set Application Root Primitive with Application.SetRoot Source: https://pkg.go.dev/github.com/rivo/tview SetRoot establishes the main primitive for the application. Setting fullscreen to true will make the root primitive occupy the entire screen. This must be called before starting the application. ```go func (a *Application) SetRoot(root Primitive, fullscreen bool) *Application ``` -------------------------------- ### Get InputField Label Source: https://pkg.go.dev/github.com/rivo/tview Retrieves the text displayed before the input area. ```go func (i *InputField) GetLabel() string ``` -------------------------------- ### Set DropDown Options and Callback Source: https://pkg.go.dev/github.com/rivo/tview Replaces current options with new ones and installs a callback function executed when an option is selected. The callback receives the option's text and index. It can be nil. ```go func (d *DropDown) SetOptions(texts []string, selected func(text string, index int)) *DropDown ``` -------------------------------- ### SetInputCapture Source: https://pkg.go.dev/github.com/rivo/tview Installs a function to capture key events before they are processed by the primitive's default handler. The capture function can choose to forward the event, modify it, or prevent it from being handled. ```APIDOC ## SetInputCapture ### Description 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. Pasted key events are not forwarded if pasting is enabled. ### Method Signature ```go func (b *Box) SetInputCapture(capture func(event *tcell.EventKey) *tcell.EventKey) *Box ``` ``` -------------------------------- ### Get TextView Label Source: https://pkg.go.dev/github.com/rivo/tview Retrieves the label text displayed before the TextView. This is typically used for identification or context. ```go func (t *TextView) GetLabel() string ``` -------------------------------- ### TextView Region Definition Example Source: https://pkg.go.dev/github.com/rivo/tview Illustrates how to define text regions within a TextView using square bracket tags with optional region IDs. ```text We define a ["rg"]region[""] here. ``` -------------------------------- ### SetBeforeDrawFunc Source: https://pkg.go.dev/github.com/rivo/tview Installs a callback function to be executed before the root primitive is drawn. If the function returns true, drawing is aborted. Provide nil to uninstall. ```APIDOC ## SetBeforeDrawFunc ### Description 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. ### Signature ```go func (a *Application) SetBeforeDrawFunc(handler func(screen tcell.Screen) bool) *Application ``` ``` -------------------------------- ### Get the input handler for the tview Grid Source: https://pkg.go.dev/github.com/rivo/tview Returns the function responsible for handling keyboard input events for the grid. ```go func (g *Grid) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) ``` -------------------------------- ### SetInputCapture for Key Event Interception Source: https://pkg.go.dev/github.com/rivo/tview Installs a function to capture key events before they are processed by the primitive's default handler. The capture function can choose to forward the event, modify it, or consume it by returning nil. ```go func (b *Box) SetInputCapture(capture func(event *tcell.EventKey) *tcell.EventKey) *Box ``` -------------------------------- ### Pages Get Front Page - tview Source: https://pkg.go.dev/github.com/rivo/tview Retrieves the name and primitive of the front-most visible page. Returns an empty string and nil if no pages are visible. ```go func (p *Pages) GetFrontPage() (name string, item Primitive) ``` -------------------------------- ### Pages Get Page - tview Source: https://pkg.go.dev/github.com/rivo/tview Returns the primitive associated with the given page name. Returns nil if no page with that name exists. ```go func (p *Pages) GetPage(name string) Primitive ``` -------------------------------- ### Pages Get Page Names - tview Source: https://pkg.go.dev/github.com/rivo/tview Returns a slice of all page names, ordered from front to back. Optionally, it can return only the names of visible pages. ```go func (p *Pages) GetPageNames(visibleOnly bool) []string ``` -------------------------------- ### GetSelection Source: https://pkg.go.dev/github.com/rivo/tview GetSelection returns the currently selected text and its start and end positions within the entire text as a half-open interval. If the returned text is an empty string, the start and end positions are the same and can be interpreted as the cursor position. This function can be expensive due to string allocations and text position searches. ```APIDOC ## GetSelection ### Description GetSelection returns the currently selected text and its start and end positions within the entire text as a half-open interval. If the returned text is an empty string, the start and end positions are the same and can be interpreted as the cursor position. Calling this function will result in string allocations as well as a search for text positions. This is expensive if the text has been edited extensively already. Use TextArea.HasSelection first if you are only interested in selected text. ### Signature ```go func (t *TextArea) GetSelection() (text string, start int, end int) ``` ``` -------------------------------- ### Create a new tview application Source: https://pkg.go.dev/github.com/rivo/tview NewApplication creates and returns a new tview Application instance. ```go func NewApplication() *Application ``` -------------------------------- ### Get InputField Text Source: https://pkg.go.dev/github.com/rivo/tview Retrieves the current text content of the input field. ```go func (i *InputField) GetText() string ``` -------------------------------- ### Get InputField Label Style Source: https://pkg.go.dev/github.com/rivo/tview Returns the tcell.Style applied to the label text. ```go func (i *InputField) GetLabelStyle() tcell.Style ``` -------------------------------- ### Create a new tview Grid Source: https://pkg.go.dev/github.com/rivo/tview Initializes a new Grid layout container. The superclass Box is transparent by default. To set a background color, reset the Box. ```go func NewGrid() *Grid ``` ```go grid.Box = NewBox() ``` -------------------------------- ### Get TextView Field Width Source: https://pkg.go.dev/github.com/rivo/tview Retrieves the current field width of the TextView primitive. ```go func (t *TextView) GetFieldWidth() int ``` -------------------------------- ### Get TextView Field Height Source: https://pkg.go.dev/github.com/rivo/tview Retrieves the current field height of the TextView primitive. ```go func (t *TextView) GetFieldHeight() int ``` -------------------------------- ### New Pages Constructor - tview Source: https://pkg.go.dev/github.com/rivo/tview Creates and returns a new instance of the Pages primitive. ```go func NewPages() *Pages ``` -------------------------------- ### NewApplication Source: https://pkg.go.dev/github.com/rivo/tview NewApplication creates and returns a new application. ```APIDOC ## func NewApplication ### Signature ```go func NewApplication() *Application ``` ### Description Creates and returns a new tview application instance. ``` -------------------------------- ### Get Cell Reference Source: https://pkg.go.dev/github.com/rivo/tview Retrieves the reference object previously stored within the TableCell. ```go func (c *TableCell) GetReference() interface{} ``` -------------------------------- ### Get InputField Style Source: https://pkg.go.dev/github.com/rivo/tview Returns the tcell.Style applied to the input area when no placeholder is visible. ```go func (i *InputField) GetFieldStyle() tcell.Style ``` -------------------------------- ### Get the offset of the tview Grid Source: https://pkg.go.dev/github.com/rivo/tview Retrieves the current row and column offset of the grid. ```go func (g *Grid) GetOffset() (rows, columns int) ``` -------------------------------- ### Set Grid Size Shortcut Source: https://pkg.go.dev/github.com/rivo/tview A shortcut for setting all row and column sizes simultaneously. See Grid.SetColumns for details on size values. ```go func (g *Grid) SetSize(numRows, numColumns, rowSize, columnSize int) *Grid ``` -------------------------------- ### Pages Add and Switch - tview Source: https://pkg.go.dev/github.com/rivo/tview Adds a new page to the Pages container and immediately switches to it. The 'resize' parameter determines if the page should be resized to fit the available space. ```go func (p *Pages) AddAndSwitchToPage(name string, item Primitive, resize bool) *Pages ``` -------------------------------- ### Get TreeView Selected Function Source: https://pkg.go.dev/github.com/rivo/tview Retrieves the function set by TreeView.SetSelectedFunc, or nil if none has been set. ```go func (t *TreeView) GetSelectedFunc() func(node *TreeNode) ``` -------------------------------- ### Get InputField Placeholder Style Source: https://pkg.go.dev/github.com/rivo/tview Returns the tcell.Style applied to the input area when a placeholder is visible. ```go func (i *InputField) GetPlaceholderStyle() tcell.Style ``` -------------------------------- ### Get InputField Width Source: https://pkg.go.dev/github.com/rivo/tview Retrieves the current width of the input field's content area. ```go func (i *InputField) GetFieldWidth() int ``` -------------------------------- ### Create New InputField Source: https://pkg.go.dev/github.com/rivo/tview Initializes and returns a new instance of the InputField primitive. ```go func NewInputField() *InputField ``` -------------------------------- ### Default Theme Configuration Source: https://pkg.go.dev/github.com/rivo/tview Sets the default theme for tview applications, including the primitive background color. ```go var Styles = Theme{ PrimitiveBackgroundColor: tcell.ColorBlack, } ``` -------------------------------- ### Get InputField Height Source: https://pkg.go.dev/github.com/rivo/tview Retrieves the current height of the input field's content area. ```go func (i *InputField) GetFieldHeight() int ``` -------------------------------- ### Set DropDown Text Options Source: https://pkg.go.dev/github.com/rivo/tview Configures the text displayed before and after each option, the currently selected option, and when no option is selected. Defaults to empty strings. ```go func (d *DropDown) SetTextOptions(prefix, suffix, currentPrefix, currentSuffix, noSelection string) *DropDown ``` -------------------------------- ### SetAfterDrawFunc Source: https://pkg.go.dev/github.com/rivo/tview Installs a callback function to be executed after the root primitive is drawn. Provide nil to uninstall. ```APIDOC ## SetAfterDrawFunc ### Description Installs a callback function which is invoked after the root primitive was drawn during screen updates. Provide nil to uninstall the callback function. ### Signature ```go func (a *Application) SetAfterDrawFunc(handler func(screen tcell.Screen)) *Application ``` ``` -------------------------------- ### tview Tab Size Configuration Source: https://pkg.go.dev/github.com/rivo/tview Sets the number of spaces a tab character will be replaced with. Defaults to 4 spaces. ```go var TabSize = 4 ``` -------------------------------- ### Get the paste handler for the tview Grid Source: https://pkg.go.dev/github.com/rivo/tview Returns the function responsible for handling paste events for the grid. ```go func (g *Grid) PasteHandler() func(pastedText string, setFocus func(p Primitive)) ``` -------------------------------- ### New Image Widget Source: https://pkg.go.dev/github.com/rivo/tview Creates a new Image widget with an empty image. Use Image.SetImage to specify the image. Dithering is set to Floyd-Steinberg by default. ```go func NewImage() *Image ``` -------------------------------- ### Get the mouse handler for the tview Grid Source: https://pkg.go.dev/github.com/rivo/tview Returns the function responsible for handling mouse events within the grid. ```go func (g *Grid) MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) ``` -------------------------------- ### NewButton Constructor Source: https://pkg.go.dev/github.com/rivo/tview Creates and returns a new Button primitive with the specified label. This is the entry point for creating interactive buttons in the UI. ```go func NewButton(label string) *Button ``` -------------------------------- ### Draw the tview Grid on the screen Source: https://pkg.go.dev/github.com/rivo/tview Renders the grid and its contained primitives onto the provided tcell.Screen. ```go func (g *Grid) Draw(screen tcell.Screen) ``` -------------------------------- ### Box MouseHandler Method Source: https://pkg.go.dev/github.com/rivo/tview MouseHandler returns nil, as Box primitives do not have default mouse handling. Custom handling must be implemented via SetMouseCapture. ```go func (b *Box) MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) ``` -------------------------------- ### GetScrollOffset Source: https://pkg.go.dev/github.com/rivo/tview Gets the current scroll offset, indicating how many node rows are skipped at the top. This value updates after redraws. ```APIDOC ## GetScrollOffset ### Description Returns the number of node rows that were skipped at the top of the tree view. Note that when the user navigates the tree view, this value is only updated after the tree view has been redrawn. ### Signature ```go func (t *TreeView) GetScrollOffset() int ``` ``` -------------------------------- ### Pages Get Page Count - tview Source: https://pkg.go.dev/github.com/rivo/tview Returns the total number of pages currently stored within the Pages container. ```go func (p *Pages) GetPageCount() int ``` -------------------------------- ### Basic Style Tags in tview Source: https://pkg.go.dev/github.com/rivo/tview Demonstrates simple style tags for text color. Use W3C color names or hexadecimal color codes within square brackets. ```go This is a [red]warning[white]! The sky is [#8080ff]blue[#ffffff]. ``` -------------------------------- ### DropDown Methods Source: https://pkg.go.dev/github.com/rivo/tview This section provides documentation for various methods available on the DropDown primitive, allowing users to interact with and configure its behavior and appearance. ```APIDOC ## GetFieldHeight ### Description GetFieldHeight returns this primitive's field height. ### Signature ```go func (d *DropDown) GetFieldHeight() int ``` ## GetFieldWidth ### Description GetFieldWidth returns this primitive's field screen width. ### Signature ```go func (d *DropDown) GetFieldWidth() int ``` ## GetLabel ### Description GetLabel returns the text to be displayed before the input area. ### Signature ```go func (d *DropDown) GetLabel() string ``` ## GetOptionCount ### Description GetOptionCount returns the number of options in the drop-down. ### Signature ```go func (d *DropDown) GetOptionCount() int ``` ## HasFocus ### Description HasFocus returns whether or not this primitive has focus. ### Signature ```go func (d *DropDown) HasFocus() bool ``` ## InputHandler ### Description InputHandler returns the handler for this primitive. ### Signature ```go func (d *DropDown) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) ``` ## IsOpen ### Description IsOpen returns true if the drop-down list is currently open. ### Signature ```go func (d *DropDown) IsOpen() bool ``` ## MouseHandler ### Description MouseHandler returns the mouse handler for this primitive. ### Signature ```go func (d *DropDown) MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) ``` ## PasteHandler ### Description PasteHandler returns the handler for this primitive. ### Signature ```go func (d *DropDown) PasteHandler() func(pastedText string, setFocus func(p Primitive)) ``` ## RemoveOption ### Description RemoveOption removes the specified option from the drop-down. Panics if the index is out of range. If the currently selected option is removed, no option will be selected. ### Signature ```go func (d *DropDown) RemoveOption(index int) *DropDown ``` ## SetCurrentOption ### Description SetCurrentOption sets the index of the currently selected option. This may be a negative value to indicate that no option is currently selected. Calling this function will also trigger the "selected" callback (if there is one). ### Signature ```go func (d *DropDown) SetCurrentOption(index int) *DropDown ``` ## SetDisabled ### Description SetDisabled sets whether or not the item is disabled / read-only. ### Signature ```go func (d *DropDown) SetDisabled(disabled bool) FormItem ``` ## SetDisabledStyle ### Description SetDisabledStyle sets the style of the options area when the drop-down is disabled. ### Signature ```go func (d *DropDown) SetDisabledStyle(style tcell.Style) *DropDown ``` ## SetDoneFunc ### Description 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. ### Signature ```go func (d *DropDown) SetDoneFunc(handler func(key tcell.Key)) *DropDown ``` ## SetFieldBackgroundColor ### Description SetFieldBackgroundColor sets the background color of the selected field. This also overrides the prefix background color. ### Signature ```go func (d *DropDown) SetFieldBackgroundColor(color tcell.Color) *DropDown ``` ## SetFieldStyle ### Description SetFieldStyle sets the style of the options area. ### Signature ```go func (d *DropDown) SetFieldStyle(style tcell.Style) *DropDown ``` ## SetFieldTextColor ### Description SetFieldTextColor sets the text color of the options area. ### Signature ```go func (d *DropDown) SetFieldTextColor(color tcell.Color) *DropDown ``` ## SetFieldWidth ### Description SetFieldWidth sets the screen width of the options area. A value of 0 means extend to as long as the longest option text. ### Signature ```go func (d *DropDown) SetFieldWidth(width int) *DropDown ``` ## SetFinishedFunc ### Description SetFinishedFunc sets a callback invoked when the user leaves this form item. ### Signature ```go func (d *DropDown) SetFinishedFunc(handler func(key tcell.Key)) FormItem ``` ## SetFocusedStyle ### Description SetFocusedStyle sets the style of the options area when the drop-down is focused and closed. ### Signature ```go func (d *DropDown) SetFocusedStyle(style tcell.Style) *DropDown ``` ## SetFormAttributes ### Description SetFormAttributes sets attributes shared by all form items. ### Signature ```go func (d *DropDown) SetFormAttributes(labelWidth int, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem ``` ## SetLabel ### Description SetLabel sets the text to be displayed before the input area. ### Signature ```go func (d *DropDown) SetLabel(label string) *DropDown ``` ## SetLabelColor ### Description SetLabelColor sets the color of the label. ### Signature ```go func (d *DropDown) SetLabelColor(color tcell.Color) *DropDown ``` ## SetLabelStyle ### Description SetLabelStyle sets the style of the label. ### Signature ```go func (d *DropDown) SetLabelStyle(style tcell.Style) *DropDown ``` ``` -------------------------------- ### Get Image Field Height Source: https://pkg.go.dev/github.com/rivo/tview Returns the image's field height, defaulting to 8 if the height is 0 or less. ```go func (i *Image) GetFieldHeight() int ``` -------------------------------- ### Provide Custom Screen with Application.SetScreen Source: https://pkg.go.dev/github.com/rivo/tview SetScreen allows the use of a custom tcell.Screen implementation. This is generally not needed for most applications and requires familiarity with tcell.Screen. ```go func (a *Application) SetScreen(screen tcell.Screen) *Application ``` -------------------------------- ### Get Highlighted Regions in TextView Source: https://pkg.go.dev/github.com/rivo/tview Returns the IDs of all currently highlighted regions within the TextView. Useful for managing text highlighting. ```go func (t *TextView) GetHighlights() (regionIDs []string) ``` -------------------------------- ### Create New Text Area Source: https://pkg.go.dev/github.com/rivo/tview Instantiates a new tview Text Area primitive. Use SetText to initialize its content. ```go func NewTextArea() *TextArea ``` -------------------------------- ### Box InputHandler Method Source: https://pkg.go.dev/github.com/rivo/tview InputHandler returns nil, as Box primitives do not have default input handling. Custom handling must be implemented via SetInputCapture. ```go func (b *Box) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) ``` -------------------------------- ### Pages Add Page - tview Source: https://pkg.go.dev/github.com/rivo/tview Adds a page with a given name and primitive to the Pages container. Overwrites existing pages with the same name. 'resize' controls automatic resizing, and 'visible' controls initial visibility. Non-empty names are recommended. ```go func (p *Pages) AddPage(name string, item Primitive, resize, visible bool) *Pages ``` -------------------------------- ### Get Image Colors Source: https://pkg.go.dev/github.com/rivo/tview Returns the number of colors used for drawing the image. 0 indicates the actual number of colors used. ```go func (i *Image) GetColors() int ``` -------------------------------- ### NewTextArea Source: https://pkg.go.dev/github.com/rivo/tview Creates and returns a new instance of a text area. Use SetText to initialize its content. ```APIDOC ## func NewTextArea() ### Description Creates and returns a new text area. ### Signature ```go func NewTextArea() *TextArea ``` ### Usage ```go textArea := NewTextArea() textArea.SetText("Initial text") ``` ``` -------------------------------- ### Set Grid Minimum Size Source: https://pkg.go.dev/github.com/rivo/tview Sets an absolute minimum width for rows and an absolute minimum height for columns. Panics if negative values are provided. ```go func (g *Grid) SetMinSize(row, column int) *Grid ``` ```go grid.SetMinSize(15, 20) ``` -------------------------------- ### DropDown Methods Source: https://pkg.go.dev/github.com/rivo/tview Details the methods for the DropDown primitive, including creating a new DropDown, adding options, and retrieving the current selection. ```APIDOC ## type DropDown ### Description 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 NewDropDown ### Description Returns a new drop-down. ### Signature ```go func NewDropDown() *DropDown ``` ## func (*DropDown) AddOption ### Description Adds a new selectable option to this drop-down. The "selected" callback is called when this option was selected. It may be nil. ### Signature ```go func (d *DropDown) AddOption(text string, selected func()) *DropDown ``` ## func (*DropDown) Draw ### Description Draws this primitive onto the screen. ### Signature ```go func (d *DropDown) Draw(screen tcell.Screen) ``` ## func (*DropDown) Focus ### Description Focus is called by the application when the primitive receives focus. ### Signature ```go func (d *DropDown) Focus(delegate func(p Primitive)) ``` ## func (*DropDown) GetCurrentOption ### Description 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. ### Signature ```go func (d *DropDown) GetCurrentOption() (int, string) ``` ``` -------------------------------- ### NewTextView Source: https://pkg.go.dev/github.com/rivo/tview Creates and returns a new instance of the TextView primitive. ```APIDOC ## NewTextView ### Description Creates and returns a new instance of the TextView primitive. ### Signature ```go func NewTextView() *TextView ``` ``` -------------------------------- ### TableContentReadOnly.InsertColumn Implementation Source: https://pkg.go.dev/github.com/rivo/tview The InsertColumn method for TableContentReadOnly does nothing. ```go func (t TableContentReadOnly) InsertColumn(column int) {} ``` -------------------------------- ### TextView Navigation Keys Source: https://pkg.go.dev/github.com/rivo/tview Lists the default Vim-like key bindings for navigating content within a scrollable TextView. ```text * 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. ``` -------------------------------- ### ScrollToBeginning Source: https://pkg.go.dev/github.com/rivo/tview Scrolls the table to display the top-left corner. ```APIDOC ## ScrollToBeginning ### Description 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. ### Function Signature ```go func (t *Table) ScrollToBeginning() *Table ``` ``` -------------------------------- ### Get TreeView Row Count Source: https://pkg.go.dev/github.com/rivo/tview Retrieves the number of visible nodes in the tree view. This count excludes children of collapsed nodes and is only accurate after the tree has been drawn. ```go func (t *TreeView) GetRowCount() int ``` -------------------------------- ### Get TextView Scroll Offset Source: https://pkg.go.dev/github.com/rivo/tview Returns the current scroll offset of the TextView, indicating how many rows and columns are skipped at the top-left corner due to scrolling. ```go func (t *TextView) GetScrollOffset() (row, column int) ``` -------------------------------- ### Button Methods Source: https://pkg.go.dev/github.com/rivo/tview Provides documentation for various methods available on the Button primitive, allowing for customization and interaction. ```APIDOC ## Button.Draw ### Description Draws the button primitive onto the screen. ### Signature ```go func (b *Button) Draw(screen tcell.Screen) ``` ## Button.GetLabel ### Description Retrieves the current text label of the button. ### Signature ```go func (b *Button) GetLabel() string ``` ## Button.InputHandler ### Description Returns the input handler function for the button, managing keyboard events. ### Signature ```go func (b *Button) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) ``` ## Button.IsDisabled ### Description Checks if the button is currently disabled. ### Signature ```go func (b *Button) IsDisabled() bool ``` ## Button.MouseHandler ### Description Returns the mouse handler function for the button, managing mouse interactions. ### Signature ```go func (b *Button) MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) ``` ## Button.SetActivatedStyle ### Description Sets the visual style for the button when it is focused or activated. ### Signature ```go func (b *Button) SetActivatedStyle(style tcell.Style) *Button ``` ## Button.SetBackgroundColorActivated ### Description Sets the background color of the button's text when the button is in focus. ### Signature ```go func (b *Button) SetBackgroundColorActivated(color tcell.Color) *Button ``` ## Button.SetDisabled ### Description Enables or disables the button. Disabled buttons cannot be activated. ### Signature ```go func (b *Button) SetDisabled(disabled bool) *Button ``` ## Button.SetDisabledStyle ### Description Sets the visual style for the button when it is in a disabled state. ### Signature ```go func (b *Button) SetDisabledStyle(style tcell.Style) *Button ``` ## Button.SetExitFunc ### Description Sets a callback function that is executed when the user leaves the button, typically via navigation keys. ### Signature ```go func (b *Button) SetExitFunc(handler func(key tcell.Key)) *Button ``` ## Button.SetLabel ### Description Sets or updates the text label displayed on the button. ### Signature ```go func (b *Button) SetLabel(label string) *Button ``` ## Button.SetLabelColor ### Description Sets the color of the button's text. ### Signature ```go func (b *Button) SetLabelColor(color tcell.Color) *Button ``` ## Button.SetLabelColorActivated ### Description Sets the color of the button's text when the button is in focus. ### Signature ```go func (b *Button) SetLabelColorActivated(color tcell.Color) *Button ``` ## Button.SetSelectedFunc ### Description Sets a callback function that is executed when the button is selected (activated). ### Signature ```go func (b *Button) SetSelectedFunc(handler func()) *Button ``` ## Button.SetStyle ### Description Sets the default visual style for the button when it is not focused. ### Signature ```go func (b *Button) SetStyle(style tcell.Style) *Button ``` ``` -------------------------------- ### Get Last Drawn Table Cell Position Source: https://pkg.go.dev/github.com/rivo/tview Retrieves the screen coordinates and width of a table cell from its last drawing operation. Useful for event handlers. ```go func (c *TableCell) GetLastPosition() (x, y, width int) ``` -------------------------------- ### SetClipboard Source: https://pkg.go.dev/github.com/rivo/tview Allows for custom clipboard implementation by providing functions for copying to and pasting from the clipboard. Nil values revert to the default, instance-local clipboard behavior. ```APIDOC ## SetClipboard ### Description Allows you to implement your own clipboard by providing a function that is called when the user wishes to store text in the clipboard (copyToClipboard) and a function that is called when the user wishes to retrieve text from the clipboard (pasteFromClipboard). Providing nil values will cause the default clipboard implementation to be used. Note that the default clipboard is local to this text area instance. Copying text to other widgets will not work. ### Signature ```go func (t *TextArea) SetClipboard(copyToClipboard func(string), pasteFromClipboard func() string) *TextArea ``` ``` -------------------------------- ### Set DropDown Prefix Text Color Source: https://pkg.go.dev/github.com/rivo/tview Sets the color of the prefix string, which is displayed when the user types to select the first option starting with the typed characters. ```go func (d *DropDown) SetPrefixTextColor(color tcell.Color) *DropDown ``` -------------------------------- ### Get TreeView Scroll Offset Source: https://pkg.go.dev/github.com/rivo/tview Returns the number of node rows skipped at the top of the tree view. This value is updated after the tree view is redrawn when the user navigates. ```go func (t *TreeView) GetScrollOffset() int ``` -------------------------------- ### Grid Methods Source: https://pkg.go.dev/github.com/rivo/tview Methods for configuring the Grid layout, including borders, columns, rows, and sizing. ```APIDOC ## Grid Methods ### SetBorders Configures whether the grid displays borders. - **Method**: `SetBorders(borders bool) *Grid` ### SetBordersColor Sets the color of the grid borders. - **Method**: `SetBordersColor(color tcell.Color) *Grid` ### SetColumns Defines the column widths for the grid. - **Method**: `SetColumns(columns ...int) *Grid` ### SetGap Sets the gap between rows and columns in the grid. - **Method**: `SetGap(row, column int) *Grid` ### SetMinSize Sets the minimum size for rows and columns. - **Method**: `SetMinSize(row, column int) *Grid` ### SetOffset Sets the offset for rows and columns. - **Method**: `SetOffset(rows, columns int) *Grid` ### SetRows Defines the row heights for the grid. - **Method**: `SetRows(rows ...int) *Grid` ### SetSize Sets the number of rows and columns, and their default sizes. - **Method**: `SetSize(numRows, numColumns, rowSize, columnSize int) *Grid` ``` -------------------------------- ### Flex Methods Source: https://pkg.go.dev/github.com/rivo/tview Methods for creating and managing the Flexbox layout container. ```APIDOC ## NewFlex ### Description Creates a new Flexbox layout container. ### Method func NewFlex() *Flex ### Returns - *Flex: A new Flex primitive. ``` ```APIDOC ## AddItem ### Description Adds a new item to the Flex container. ### Method func (f *Flex) AddItem(item Primitive, fixedSize, proportion int, focus bool) *Flex ### Parameters - **item** (Primitive) - The primitive to add. Can be nil. - **fixedSize** (int) - The fixed width or height of the item. 0 means flexible. - **proportion** (int) - The relative size compared to other flexible items. Must be >= 1 if fixedSize is 0. - **focus** (bool) - Whether this item should receive focus when the Flex primitive receives focus. ``` ```APIDOC ## Clear ### Description Removes all items from the Flex container. ### Method func (f *Flex) Clear() *Flex ``` ```APIDOC ## Draw ### Description Draws the Flex primitive onto the screen. ### Method func (f *Flex) Draw(screen tcell.Screen) ``` ```APIDOC ## Focus ### Description Called when this primitive receives focus. ### Method func (f *Flex) Focus(delegate func(p Primitive)) ``` -------------------------------- ### Write Source: https://pkg.go.dev/github.com/rivo/tview Implements the io.Writer interface, allowing the TextView to be written to. ```APIDOC ## Write ### Description Lets us implement the io.Writer interface. ### Signature ```go func (t *TextView) Write(p []byte) (n int, err error) ``` ``` -------------------------------- ### FormItem Interface Definition Source: https://pkg.go.dev/github.com/rivo/tview Defines the FormItem interface, which all form elements must implement. It includes methods for getting labels, setting attributes, and handling user input completion. ```go 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 field width is flexible and may use as much space as // required. GetFieldWidth() int // GetFieldHeight returns the height of the form item's field (the area which // is manipulated by the user). This value must be greater than 0. GetFieldHeight() int // SetFinishedFunc 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), the Backtab key (move to previous field), or a negative // value, indicating that the action for the last known key should be // repeated. SetFinishedFunc(handler func(key tcell.Key)) FormItem // SetDisabled sets whether or not the item is disabled / read-only. A form // must have at least one item that is not disabled. SetDisabled(disabled bool) FormItem } ``` -------------------------------- ### List Methods Source: https://pkg.go.dev/github.com/rivo/tview Methods for creating and managing items within a List. ```APIDOC ## NewList ### Description Creates a new list. ### Signature ```go func NewList() *List ``` ``` ```APIDOC ## AddItem ### Description Adds an item to the list. This is a convenience function that calls List.InsertItem with an index of -1. ### Signature ```go func (l *List) AddItem(mainText, secondaryText string, shortcut rune, selected func()) *List ``` ``` ```APIDOC ## Clear ### Description Removes all items from the list. ### Signature ```go func (l *List) Clear() *List ``` ``` ```APIDOC ## Draw ### Description Draws the list primitive onto the screen. ### Signature ```go func (l *List) Draw(screen tcell.Screen) ``` ``` ```APIDOC ## FindItems ### Description Searches the main and secondary texts for the given strings and returns a list of item indices in which those strings are found. One of the two search strings may be empty, it will then be ignored. Indices are always returned in ascending order. If mustContainBoth is set to true, mainSearch must be contained in the main text AND secondarySearch must be contained in the secondary text. If it is false, only one of the two search strings must be contained. Set ignoreCase to true for case-insensitive search. ### Signature ```go func (l *List) FindItems(mainSearch, secondarySearch string, mustContainBoth, ignoreCase bool) (indices []int) ``` ``` ```APIDOC ## GetCurrentItem ### Description Returns the index of the currently selected list item, starting at 0 for the first item. ### Signature ```go func (l *List) GetCurrentItem() int ``` ``` ```APIDOC ## GetItemCount ### Description Returns the number of items in the list. ### Signature ```go func (l *List) GetItemCount() int ``` ``` ```APIDOC ## GetItemSelectedFunc ### Description Returns the function which is called when the user selects the item with the given index, if such a function was set. If no function was set, nil is returned. Panics if the index is out of range. ### Signature ```go func (l *List) GetItemSelectedFunc(index int) func() ``` ``` ```APIDOC ## GetItemText ### Description Returns an item's texts (main and secondary). Panics if the index is out of range. ### Signature ```go func (l *List) GetItemText(index int) (main, secondary string) ``` ``` ```APIDOC ## GetOffset ### Description Returns the number of items skipped while drawing, as well as the number of cells item text is moved to the left. See also SetOffset() for more information on these values. ### Signature ```go func (l *List) GetOffset() (int, int) ``` ``` ```APIDOC ## GetSelectedFunc ### Description Returns the function set with List.SetSelectedFunc or nil if no such function was set. ### Signature ```go func (l *List) GetSelectedFunc() func(int, string, string, rune) ``` ``` ```APIDOC ## GetUseStyleTags ### Description Returns whether style tags are used in the main and secondary texts. ### Signature ```go func (l *List) GetUseStyleTags() (mainStyleTags, secondaryStyleTags bool) ``` ``` -------------------------------- ### GetCursor Source: https://pkg.go.dev/github.com/rivo/tview GetCursor returns the current cursor position. The "from" and "to" values refer to the start and end of a selection (exclusive), or the cursor position if no text is selected. ```APIDOC ## GetCursor ### Description GetCursor returns the current cursor position where the first character of the entire text is in row 0, column 0. If the user has selected text, the "from" values will refer to the beginning of the selection and the "to" values to the end of the selection (exclusive). They are the same if there is no selection. ### Signature ```go func (t *TextArea) GetCursor() (fromRow, fromColumn, toRow, toColumn int) ``` ``` -------------------------------- ### Escape Source: https://pkg.go.dev/github.com/rivo/tview 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. ```APIDOC ## func Escape ### Signature ```go func Escape(text string) string ``` ### Description Escapes text to prevent recognition of tview style tags. ``` -------------------------------- ### Pages Draw Method - tview Source: https://pkg.go.dev/github.com/rivo/tview Renders the Pages primitive and its visible content onto the provided tcell.Screen. ```go func (p *Pages) Draw(screen tcell.Screen) ``` -------------------------------- ### Advanced Style Tag Formatting Source: https://pkg.go.dev/github.com/rivo/tview Illustrates the full style tag format: [:::]. Fields can be omitted or set to '-' for default/reset. ```go [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 [::i]Italic and [::I]not italic Click [:::https://example.com]here[:::-] for example.com. Send an email to [:::mailto:her@example.com]her/[:::mail:him@example.com]him/[:::mail:them@example.com]them[:::-]. [-:-:-:-]Reset everything [:]No effect []Not a valid style tag, will print square brackets as they are ``` -------------------------------- ### Get TextView Text Content Source: https://pkg.go.dev/github.com/rivo/tview Retrieves the current text content of the TextView. If 'stripAllTags' is true, all style and region tags are removed. Text discarded due to SetMaxLines or SetScrollable is not included. ```go func (t *TextView) GetText(stripAllTags bool) string ``` -------------------------------- ### Theme Type Source: https://pkg.go.dev/github.com/rivo/tview Theme defines the colors used when primitives are initialized. ```APIDOC ## type Theme ### Description Theme defines the colors used when primitives are initialized. ### Fields - **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. ### Signature ```go type Theme struct { PrimitiveBackgroundColor tcell.Color ContrastBackgroundColor tcell.Color MoreContrastBackgroundColor tcell.Color BorderColor tcell.Color TitleColor tcell.Color GraphicsColor tcell.Color PrimaryTextColor tcell.Color SecondaryTextColor tcell.Color TertiaryTextColor tcell.Color InverseTextColor tcell.Color ContrastSecondaryTextColor tcell.Color } ``` ``` -------------------------------- ### Replace Source: https://pkg.go.dev/github.com/rivo/tview Replace replaces a section of the text with new text. The start and end positions define a half-open interval within the entire text string. This operation can be undone and redone by the user. ```APIDOC ## Replace ### Description Replace replaces a section of the text with new text. The start and end positions refer to index positions within the entire text string (as a half-open interval). They may be the same, in which case text is inserted at the given position. If the text is an empty string, text between start and end is deleted. Index positions will be shifted to line up with character boundaries. A "changed" event will be triggered. Previous selections are cleared. The cursor will be located at the end of the replaced text. Scroll offsets will not be changed. A "moved" event will be triggered. The effects of this function can be undone (and redone) by the user. ### Signature ```go func (t *TextArea) Replace(start, end int, text string) *TextArea ``` ``` -------------------------------- ### Select Source: https://pkg.go.dev/github.com/rivo/tview Selects a section of the text within the TextArea. The start and end positions define a half-open interval. Any previous selection is removed, and scroll offsets are preserved. Index positions are adjusted to character boundaries. ```APIDOC ## Select ### Description Selects a section of the text. The start and end positions refer to index positions within the entire text string (as a half-open interval). They may be the same, in which case the cursor is placed at the given position. Any previous selection is removed. Scroll offsets will be preserved. Index positions will be shifted to line up with character boundaries. ### Signature ```go func (t *TextArea) Select(start, end int) *TextArea ``` ``` -------------------------------- ### Pages Focus Method - tview Source: https://pkg.go.dev/github.com/rivo/tview Handles focus events for the Pages primitive, delegating focus to its children as needed. ```go func (p *Pages) Focus(delegate func(p Primitive)) ```