tview

package module
v0.0.0-...-7549865 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// One item per row.
	FlexRow = 0
	// One item per column.
	FlexColumn = 1
	// As defined in CSS, items distributed along a row.
	FlexRowCSS = 1
	// As defined in CSS, items distributed within a column.
	FlexColumnCSS = 0
)

Flex directions.

View Source
const (
	// General Punctuation U+2000-U+206F
	SemigraphicsHorizontalEllipsis = "\u2026" // …

	// Box Drawing U+2500-U+257F
	BoxDrawingsLightHorizontal                    = "\u2500" // ─
	BoxDrawingsHeavyHorizontal                    = "\u2501" // ━
	BoxDrawingsLightVertical                      = "\u2502" // │
	BoxDrawingsHeavyVertical                      = "\u2503" // ┃
	BoxDrawingsLightTripleDashHorizontal          = "\u2504" // ┄
	BoxDrawingsHeavyTripleDashHorizontal          = "\u2505" // ┅
	BoxDrawingsLightTripleDashVertical            = "\u2506" // ┆
	BoxDrawingsHeavyTripleDashVertical            = "\u2507" // ┇
	BoxDrawingsLightQuadrupleDashHorizontal       = "\u2508" // ┈
	BoxDrawingsHeavyQuadrupleDashHorizontal       = "\u2509" // ┉
	BoxDrawingsLightQuadrupleDashVertical         = "\u250a" // ┊
	BoxDrawingsHeavyQuadrupleDashVertical         = "\u250b" // ┋
	BoxDrawingsLightDownAndRight                  = "\u250c" // ┌
	BoxDrawingsDownLightAndRightHeavy             = "\u250d" // ┍
	BoxDrawingsDownHeavyAndRightLight             = "\u250e" // ┎
	BoxDrawingsHeavyDownAndRight                  = "\u250f" // ┏
	BoxDrawingsLightDownAndLeft                   = "\u2510" // ┐
	BoxDrawingsDownLightAndLeftHeavy              = "\u2511" // ┑
	BoxDrawingsDownHeavyAndLeftLight              = "\u2512" // ┒
	BoxDrawingsHeavyDownAndLeft                   = "\u2513" // ┓
	BoxDrawingsLightUpAndRight                    = "\u2514" // └
	BoxDrawingsUpLightAndRightHeavy               = "\u2515" // ┕
	BoxDrawingsUpHeavyAndRightLight               = "\u2516" // ┖
	BoxDrawingsHeavyUpAndRight                    = "\u2517" // ┗
	BoxDrawingsLightUpAndLeft                     = "\u2518" // ┘
	BoxDrawingsUpLightAndLeftHeavy                = "\u2519" // ┙
	BoxDrawingsUpHeavyAndLeftLight                = "\u251a" // ┚
	BoxDrawingsHeavyUpAndLeft                     = "\u251b" // ┛
	BoxDrawingsLightVerticalAndRight              = "\u251c" // ├
	BoxDrawingsVerticalLightAndRightHeavy         = "\u251d" // ┝
	BoxDrawingsUpHeavyAndRightDownLight           = "\u251e" // ┞
	BoxDrawingsDownHeavyAndRightUpLight           = "\u251f" // ┟
	BoxDrawingsVerticalHeavyAndRightLight         = "\u2520" // ┠
	BoxDrawingsDownLightAndRightUpHeavy           = "\u2521" // ┡
	BoxDrawingsUpLightAndRightDownHeavy           = "\u2522" // ┢
	BoxDrawingsHeavyVerticalAndRight              = "\u2523" // ┣
	BoxDrawingsLightVerticalAndLeft               = "\u2524" // ┤
	BoxDrawingsVerticalLightAndLeftHeavy          = "\u2525" // ┥
	BoxDrawingsUpHeavyAndLeftDownLight            = "\u2526" // ┦
	BoxDrawingsDownHeavyAndLeftUpLight            = "\u2527" // ┧
	BoxDrawingsVerticalHeavyAndLeftLight          = "\u2528" // ┨
	BoxDrawingsDownLightAndLeftUpHeavy            = "\u2529" // ┩
	BoxDrawingsUpLightAndLeftDownHeavy            = "\u252a" // ┪
	BoxDrawingsHeavyVerticalAndLeft               = "\u252b" // ┫
	BoxDrawingsLightDownAndHorizontal             = "\u252c" // ┬
	BoxDrawingsLeftHeavyAndRightDownLight         = "\u252d" // ┭
	BoxDrawingsRightHeavyAndLeftDownLight         = "\u252e" // ┮
	BoxDrawingsDownLightAndHorizontalHeavy        = "\u252f" // ┯
	BoxDrawingsDownHeavyAndHorizontalLight        = "\u2530" // ┰
	BoxDrawingsRightLightAndLeftDownHeavy         = "\u2531" // ┱
	BoxDrawingsLeftLightAndRightDownHeavy         = "\u2532" // ┲
	BoxDrawingsHeavyDownAndHorizontal             = "\u2533" // ┳
	BoxDrawingsLightUpAndHorizontal               = "\u2534" // ┴
	BoxDrawingsLeftHeavyAndRightUpLight           = "\u2535" // ┵
	BoxDrawingsRightHeavyAndLeftUpLight           = "\u2536" // ┶
	BoxDrawingsUpLightAndHorizontalHeavy          = "\u2537" // ┷
	BoxDrawingsUpHeavyAndHorizontalLight          = "\u2538" // ┸
	BoxDrawingsRightLightAndLeftUpHeavy           = "\u2539" // ┹
	BoxDrawingsLeftLightAndRightUpHeavy           = "\u253a" // ┺
	BoxDrawingsHeavyUpAndHorizontal               = "\u253b" // ┻
	BoxDrawingsLightVerticalAndHorizontal         = "\u253c" // ┼
	BoxDrawingsLeftHeavyAndRightVerticalLight     = "\u253d" // ┽
	BoxDrawingsRightHeavyAndLeftVerticalLight     = "\u253e" // ┾
	BoxDrawingsVerticalLightAndHorizontalHeavy    = "\u253f" // ┿
	BoxDrawingsUpHeavyAndDownHorizontalLight      = "\u2540" // ╀
	BoxDrawingsDownHeavyAndUpHorizontalLight      = "\u2541" // ╁
	BoxDrawingsVerticalHeavyAndHorizontalLight    = "\u2542" // ╂
	BoxDrawingsLeftUpHeavyAndRightDownLight       = "\u2543" // ╃
	BoxDrawingsRightUpHeavyAndLeftDownLight       = "\u2544" // ╄
	BoxDrawingsLeftDownHeavyAndRightUpLight       = "\u2545" // ╅
	BoxDrawingsRightDownHeavyAndLeftUpLight       = "\u2546" // ╆
	BoxDrawingsDownLightAndUpHorizontalHeavy      = "\u2547" // ╇
	BoxDrawingsUpLightAndDownHorizontalHeavy      = "\u2548" // ╈
	BoxDrawingsRightLightAndLeftVerticalHeavy     = "\u2549" // ╉
	BoxDrawingsLeftLightAndRightVerticalHeavy     = "\u254a" // ╊
	BoxDrawingsHeavyVerticalAndHorizontal         = "\u254b" // ╋
	BoxDrawingsLightDoubleDashHorizontal          = "\u254c" // ╌
	BoxDrawingsHeavyDoubleDashHorizontal          = "\u254d" // ╍
	BoxDrawingsLightDoubleDashVertical            = "\u254e" // ╎
	BoxDrawingsHeavyDoubleDashVertical            = "\u254f" // ╏
	BoxDrawingsDoubleHorizontal                   = "\u2550" // ═
	BoxDrawingsDoubleVertical                     = "\u2551" // ║
	BoxDrawingsDownSingleAndRightDouble           = "\u2552" // ╒
	BoxDrawingsDownDoubleAndRightSingle           = "\u2553" // ╓
	BoxDrawingsDoubleDownAndRight                 = "\u2554" // ╔
	BoxDrawingsDownSingleAndLeftDouble            = "\u2555" // ╕
	BoxDrawingsDownDoubleAndLeftSingle            = "\u2556" // ╖
	BoxDrawingsDoubleDownAndLeft                  = "\u2557" // ╗
	BoxDrawingsUpSingleAndRightDouble             = "\u2558" // ╘
	BoxDrawingsUpDoubleAndRightSingle             = "\u2559" // ╙
	BoxDrawingsDoubleUpAndRight                   = "\u255a" // ╚
	BoxDrawingsUpSingleAndLeftDouble              = "\u255b" // ╛
	BoxDrawingsUpDoubleAndLeftSingle              = "\u255c" // ╜
	BoxDrawingsDoubleUpAndLeft                    = "\u255d" // ╝
	BoxDrawingsVerticalSingleAndRightDouble       = "\u255e" // ╞
	BoxDrawingsVerticalDoubleAndRightSingle       = "\u255f" // ╟
	BoxDrawingsDoubleVerticalAndRight             = "\u2560" // ╠
	BoxDrawingsVerticalSingleAndLeftDouble        = "\u2561" // ╡
	BoxDrawingsVerticalDoubleAndLeftSingle        = "\u2562" // ╢
	BoxDrawingsDoubleVerticalAndLeft              = "\u2563" // ╣
	BoxDrawingsDownSingleAndHorizontalDouble      = "\u2564" // ╤
	BoxDrawingsDownDoubleAndHorizontalSingle      = "\u2565" // ╥
	BoxDrawingsDoubleDownAndHorizontal            = "\u2566" // ╦
	BoxDrawingsUpSingleAndHorizontalDouble        = "\u2567" // ╧
	BoxDrawingsUpDoubleAndHorizontalSingle        = "\u2568" // ╨
	BoxDrawingsDoubleUpAndHorizontal              = "\u2569" // ╩
	BoxDrawingsVerticalSingleAndHorizontalDouble  = "\u256a" // ╪
	BoxDrawingsVerticalDoubleAndHorizontalSingle  = "\u256b" // ╫
	BoxDrawingsDoubleVerticalAndHorizontal        = "\u256c" // ╬
	BoxDrawingsLightArcDownAndRight               = "\u256d" // ╭
	BoxDrawingsLightArcDownAndLeft                = "\u256e" // ╮
	BoxDrawingsLightArcUpAndLeft                  = "\u256f" // ╯
	BoxDrawingsLightArcUpAndRight                 = "\u2570" // ╰
	BoxDrawingsLightDiagonalUpperRightToLowerLeft = "\u2571" // ╱
	BoxDrawingsLightDiagonalUpperLeftToLowerRight = "\u2572" // ╲
	BoxDrawingsLightDiagonalCross                 = "\u2573" // ╳
	BoxDrawingsLightLeft                          = "\u2574" // ╴
	BoxDrawingsLightUp                            = "\u2575" // ╵
	BoxDrawingsLightRight                         = "\u2576" // ╶
	BoxDrawingsLightDown                          = "\u2577" // ╷
	BoxDrawingsHeavyLeft                          = "\u2578" // ╸
	BoxDrawingsHeavyUp                            = "\u2579" // ╹
	BoxDrawingsHeavyRight                         = "\u257a" // ╺
	BoxDrawingsHeavyDown                          = "\u257b" // ╻
	BoxDrawingsLightLeftAndHeavyRight             = "\u257c" // ╼
	BoxDrawingsLightUpAndHeavyDown                = "\u257d" // ╽
	BoxDrawingsHeavyLeftAndLightRight             = "\u257e" // ╾
	BoxDrawingsHeavyUpAndLightDown                = "\u257f" // ╿

	// Block Elements U+2580–U+259F
	BlockUpperHalfBlock                              = "\u2580" // ▀
	BlockLowerOneEighthBlock                         = "\u2581" // ▁
	BlockLowerOneQuarterBlock                        = "\u2582" // ▂
	BlockLowerThreeEighthsBlock                      = "\u2583" // ▃
	BlockLowerHalfBlock                              = "\u2584" // ▄
	BlockLowerFiveEighthsBlock                       = "\u2585" // ▅
	BlockLowerThreeQuartersBlock                     = "\u2586" // ▆
	BlockLowerSevenEighthsBlock                      = "\u2587" // ▇
	BlockFullBlock                                   = "\u2588" // █
	BlockLeftSevenEighthsBlock                       = "\u2589" // ▉
	BlockLeftThreeQuartersBlock                      = "\u258A" // ▊
	BlockLeftFiveEighthsBlock                        = "\u258B" // ▋
	BlockLeftHalfBlock                               = "\u258C" // ▌
	BlockLeftThreeEighthsBlock                       = "\u258D" // ▍
	BlockLeftOneQuarterBlock                         = "\u258E" // ▎
	BlockLeftOneEighthBlock                          = "\u258F" // ▏
	BlockRightHalfBlock                              = "\u2590" // ▐
	BlockLightShade                                  = "\u2591" // ░
	BlockMediumShade                                 = "\u2592" // ▒
	BlockDarkShade                                   = "\u2593" // ▓
	BlockUpperOneEighthBlock                         = "\u2594" // ▔
	BlockRightOneEighthBlock                         = "\u2595" // ▕
	BlockQuadrantLowerLeft                           = "\u2596" // ▖
	BlockQuadrantLowerRight                          = "\u2597" // ▗
	BlockQuadrantUpperLeft                           = "\u2598" // ▘
	BlockQuadrantUpperLeftAndLowerLeftAndLowerRight  = "\u2599" // ▙
	BlockQuadrantUpperLeftAndLowerRight              = "\u259A" // ▚
	BlockQuadrantUpperLeftAndUpperRightAndLowerLeft  = "\u259B" // ▛
	BlockQuadrantUpperLeftAndUpperRightAndLowerRight = "\u259C" // ▜
	BlockQuadrantUpperRight                          = "\u259D" // ▝
	BlockQuadrantUpperRightAndLowerLeft              = "\u259E" // ▞
	BlockQuadrantUpperRightAndLowerLeftAndLowerRight = "\u259F" // ▟
)

Semigraphics provides easy access to Unicode characters for drawing. Using strings with \u escapes to keep the source ASCII-safe.

Variables

View Source
var (
	// 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.
	DefaultFormFieldWidth = 10

	// DefaultFormFieldHeight is the default field height of multi-line form
	// elements whose field height is flexible (0).
	DefaultFormFieldHeight = 5
)
View Source
var DoubleClickInterval = 500 * time.Millisecond

DoubleClickInterval specifies the maximum time between clicks to register a double click rather than click.

View Source
var SemigraphicJoints = map[string]string{

	BoxDrawingsLightHorizontal + BoxDrawingsLightVertical: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightHorizontal + BoxDrawingsLightDownAndRight: BoxDrawingsLightDownAndHorizontal,

	BoxDrawingsLightHorizontal + BoxDrawingsLightDownAndLeft: BoxDrawingsLightDownAndHorizontal,

	BoxDrawingsLightHorizontal + BoxDrawingsLightUpAndRight: BoxDrawingsLightUpAndHorizontal,

	BoxDrawingsLightHorizontal + BoxDrawingsLightUpAndLeft: BoxDrawingsLightUpAndHorizontal,

	BoxDrawingsLightHorizontal + BoxDrawingsLightVerticalAndRight: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightHorizontal + BoxDrawingsLightVerticalAndLeft: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightHorizontal + BoxDrawingsLightDownAndHorizontal: BoxDrawingsLightDownAndHorizontal,

	BoxDrawingsLightHorizontal + BoxDrawingsLightUpAndHorizontal: BoxDrawingsLightUpAndHorizontal,

	BoxDrawingsLightHorizontal + BoxDrawingsLightVerticalAndHorizontal: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightVertical + BoxDrawingsLightDownAndRight: BoxDrawingsLightVerticalAndRight,

	BoxDrawingsLightVertical + BoxDrawingsLightDownAndLeft: BoxDrawingsLightVerticalAndLeft,

	BoxDrawingsLightVertical + BoxDrawingsLightUpAndRight: BoxDrawingsLightVerticalAndRight,

	BoxDrawingsLightVertical + BoxDrawingsLightUpAndLeft: BoxDrawingsLightVerticalAndLeft,

	BoxDrawingsLightVertical + BoxDrawingsLightVerticalAndRight: BoxDrawingsLightVerticalAndRight,

	BoxDrawingsLightVertical + BoxDrawingsLightVerticalAndLeft: BoxDrawingsLightVerticalAndLeft,

	BoxDrawingsLightVertical + BoxDrawingsLightDownAndHorizontal: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightVertical + BoxDrawingsLightUpAndHorizontal: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightVertical + BoxDrawingsLightVerticalAndHorizontal: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightDownAndRight + BoxDrawingsLightDownAndLeft: BoxDrawingsLightDownAndHorizontal,

	BoxDrawingsLightDownAndRight + BoxDrawingsLightUpAndRight: BoxDrawingsLightVerticalAndRight,

	BoxDrawingsLightDownAndRight + BoxDrawingsLightUpAndLeft: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightDownAndRight + BoxDrawingsLightVerticalAndRight: BoxDrawingsLightVerticalAndRight,

	BoxDrawingsLightDownAndRight + BoxDrawingsLightVerticalAndLeft: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightDownAndRight + BoxDrawingsLightDownAndHorizontal: BoxDrawingsLightDownAndHorizontal,

	BoxDrawingsLightDownAndRight + BoxDrawingsLightUpAndHorizontal: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightDownAndRight + BoxDrawingsLightVerticalAndHorizontal: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightDownAndLeft + BoxDrawingsLightUpAndRight: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightDownAndLeft + BoxDrawingsLightUpAndLeft: BoxDrawingsLightVerticalAndLeft,

	BoxDrawingsLightDownAndLeft + BoxDrawingsLightVerticalAndRight: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightDownAndLeft + BoxDrawingsLightVerticalAndLeft: BoxDrawingsLightVerticalAndLeft,

	BoxDrawingsLightDownAndLeft + BoxDrawingsLightDownAndHorizontal: BoxDrawingsLightDownAndHorizontal,

	BoxDrawingsLightDownAndLeft + BoxDrawingsLightUpAndHorizontal: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightDownAndLeft + BoxDrawingsLightVerticalAndHorizontal: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightUpAndRight + BoxDrawingsLightUpAndLeft: BoxDrawingsLightUpAndHorizontal,

	BoxDrawingsLightUpAndRight + BoxDrawingsLightVerticalAndRight: BoxDrawingsLightVerticalAndRight,

	BoxDrawingsLightUpAndRight + BoxDrawingsLightVerticalAndLeft: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightUpAndRight + BoxDrawingsLightDownAndHorizontal: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightUpAndRight + BoxDrawingsLightUpAndHorizontal: BoxDrawingsLightUpAndHorizontal,

	BoxDrawingsLightUpAndRight + BoxDrawingsLightVerticalAndHorizontal: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightUpAndLeft + BoxDrawingsLightVerticalAndRight: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightUpAndLeft + BoxDrawingsLightVerticalAndLeft: BoxDrawingsLightVerticalAndLeft,

	BoxDrawingsLightUpAndLeft + BoxDrawingsLightDownAndHorizontal: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightUpAndLeft + BoxDrawingsLightUpAndHorizontal: BoxDrawingsLightUpAndHorizontal,

	BoxDrawingsLightUpAndLeft + BoxDrawingsLightVerticalAndHorizontal: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightVerticalAndRight + BoxDrawingsLightVerticalAndLeft: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightVerticalAndRight + BoxDrawingsLightDownAndHorizontal: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightVerticalAndRight + BoxDrawingsLightUpAndHorizontal: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightVerticalAndRight + BoxDrawingsLightVerticalAndHorizontal: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightVerticalAndLeft + BoxDrawingsLightDownAndHorizontal: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightVerticalAndLeft + BoxDrawingsLightUpAndHorizontal: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightVerticalAndLeft + BoxDrawingsLightVerticalAndHorizontal: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightDownAndHorizontal + BoxDrawingsLightUpAndHorizontal: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightDownAndHorizontal + BoxDrawingsLightVerticalAndHorizontal: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsLightUpAndHorizontal + BoxDrawingsLightVerticalAndHorizontal: BoxDrawingsLightVerticalAndHorizontal,

	BoxDrawingsDoubleHorizontal + BoxDrawingsDoubleVertical: BoxDrawingsDoubleVerticalAndHorizontal,
}

SemigraphicJoints maps pairs of semigraphics strings to the resulting joint. All combinations for light and double lines are included.

View Source
var Styles = Theme{
	PrimitiveBackgroundColor:    color.Black,
	ContrastBackgroundColor:     color.Blue,
	MoreContrastBackgroundColor: color.Green,
	BorderColor:                 color.White,
	TitleColor:                  color.White,
	GraphicsColor:               color.White,
	PrimaryTextColor:            color.White,
	SecondaryTextColor:          color.Yellow,
	TertiaryTextColor:           color.Green,
	InverseTextColor:            color.Blue,
	ContrastSecondaryTextColor:  color.Navy,
}

Styles defines the theme for applications. The default is for a black background and some basic colors: black, white, yellow, green, cyan, and blue.

View Source
var TabSize = 4

TabSize is the number of spaces with which a tab character will be replaced.

View Source
var TextAreaNewLine = "\n"

TextAreaNewLine is the string sequence to be inserted when hitting the Enter key in a TextArea. The default is "\n" but you may change it to "\r\n" if required.

Functions

func Print

func Print(screen tcell.Screen, text string, x, y, maxWidth int, alignment Alignment, color tcell.Color) (int, int)

Print prints text onto the screen into the given box at (x,y,maxWidth,1), not exceeding that box. The screen's background color will not be changed.

Returns the number of actual bytes of the text printed and the actual width used for the printed runes.

func PrintJoinedSemigraphics

func PrintJoinedSemigraphics(screen tcell.Screen, x, y int, str string, style tcell.Style)

PrintJoinedSemigraphics prints a semigraphics string into the screen at the given position with the given style, joining it with any existing semigraphics.

func PrintSimple

func PrintSimple(screen tcell.Screen, text string, x, y int)

PrintSimple prints white text to the screen at the given position.

func PrintWithStyle

func PrintWithStyle(screen tcell.Screen, text string, x, y, maxWidth int, alignment Alignment, style tcell.Style) (int, int)

PrintWithStyle prints text onto the screen into the given box at (x,y,maxWidth,1), not exceeding that box, using the provided style.

Returns the number of actual bytes of the text printed and the actual width used for the printed runes.

func TaggedStringWidth

func TaggedStringWidth(text string) (width int)

TaggedStringWidth returns the width of the given string needed to print it on screen.

func WordWrap

func WordWrap(text string, width int) (lines []string)

WordWrap splits a text such that each resulting line does not exceed the given screen width.

Types

type Alignment

type Alignment int
const (
	AlignmentLeft Alignment = iota
	AlignmentCenter
	AlignmentRight
)

type Application

type Application struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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.

The following command displays a primitive p on the screen until the application is stopped (for example via QuitCommand):

if err := tview.NewApplication().SetRoot(p, true).Run(); err != nil {
    panic(err)
}

func NewApplication

func NewApplication() *Application

NewApplication creates and returns a new application.

func (*Application) Draw

func (a *Application) Draw() *Application

Draw refreshes the screen (during the next update cycle). It calls the Draw() function of the application's root primitive and then syncs the screen buffer. It is almost never necessary to call this function. It can actually deadlock your application if you call it from the main thread (e.g. in a callback function of a widget). Please see https://github.com/ayn2op/tview/wiki/Concurrency for details.

func (*Application) ForceDraw

func (a *Application) ForceDraw() *Application

ForceDraw refreshes the screen immediately. Use this function with caution as it may lead to race conditions with updates to primitives in other goroutines. It is always preferable to call Application.Draw instead. Never call this function from a goroutine.

It is safe to call this function during queued updates and direct event handling.

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) QueueEvent

func (a *Application) QueueEvent(event tcell.Event) *Application

QueueEvent sends an event to the Application event loop.

It is not recommended for event to be nil.

func (*Application) QueueUpdate

func (a *Application) QueueUpdate(f func()) *Application

QueueUpdate is used to synchronize access to primitives from non-main goroutines. The provided function will be executed as part of the event loop and thus will not cause race conditions with other such update functions or the Draw() function.

Note that Draw() is not implicitly called after the execution of f as that may not be desirable. You can call Draw() from f if the screen should be refreshed after each update. Alternatively, use QueueUpdateDraw() to follow up with an immediate refresh of the screen.

This function returns after f has executed.

func (*Application) QueueUpdateDraw

func (a *Application) QueueUpdateDraw(f func()) *Application

QueueUpdateDraw works like QueueUpdate() except it refreshes the screen immediately after executing f.

func (*Application) Run

func (a *Application) Run() error

Run 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.

func (*Application) SetFocus

func (a *Application) SetFocus(p Primitive) *Application

SetFocus sets the focus to a new primitive. All key events will be directed down the hierarchy (starting at the root) until a primitive handles them, which per default goes towards the focused primitive.

Blur() will be called on the previously focused primitive. Focus() will be called on the new primitive.

func (*Application) SetRoot

func (a *Application) SetRoot(root Primitive) *Application

SetRoot sets the root primitive for this application. 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) SetScreen

func (a *Application) SetScreen(screen tcell.Screen) *Application

SetScreen sets the application's screen.

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.

func (*Application) Sync

func (a *Application) Sync() *Application

Sync forces a full re-sync of the screen buffer with the actual screen during the next event cycle. This is useful for when the terminal screen is corrupted so you may want to offer your users a keyboard shortcut to refresh the screen.

type BatchCommand

type BatchCommand []Command

BatchCommand groups multiple commands into a single command.

type BorderSet

type BorderSet struct {
	Top         string
	Bottom      string
	Left        string
	Right       string
	TopLeft     string
	TopRight    string
	BottomLeft  string
	BottomRight string
	TopT        string
	BottomT     string
	LeftT       string
	RightT      string
}

BorderSet defines various borders used when primitives are drawn.

func BorderSetDouble

func BorderSetDouble() BorderSet

func BorderSetHidden

func BorderSetHidden() BorderSet

func BorderSetPlain

func BorderSetPlain() BorderSet

func BorderSetRound

func BorderSetRound() BorderSet

func BorderSetThick

func BorderSetThick() BorderSet

type Borders

type Borders uint
const (
	BordersTop Borders = 1 << iota
	BordersBottom
	BordersLeft
	BordersRight

	BordersNone Borders = 0
	BordersAll  Borders = BordersTop | BordersBottom | BordersLeft | BordersRight
)

func (Borders) Has

func (b Borders) Has(flag Borders) bool

type Box

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

Box implements the Primitive interface with an empty background and optional elements such as a border and a title. Box itself does not hold any content but serves as the superclass of all other primitives. Subclasses add their own content, typically (but not necessarily) keeping their content within the box's rectangle.

Box provides a number of utility functions available to all primitives.

See https://github.com/ayn2op/tview/wiki/Box for an example.

func NewBox

func NewBox() *Box

NewBox returns a Box without a border.

func (*Box) Blur

func (b *Box) Blur()

Blur is called when this primitive directly loses focus.

func (*Box) Draw

func (b *Box) Draw(screen tcell.Screen)

Draw draws this primitive onto the screen.

func (*Box) DrawForSubclass

func (b *Box) DrawForSubclass(screen tcell.Screen, p Primitive)

DrawForSubclass draws this box under the assumption that primitive p is a subclass of this box. This is needed e.g. to draw proper box frames which depend on the subclass's focus.

Only call this function from your own custom primitives. It is not needed in applications that have no custom primitives.

func (*Box) Focus

func (b *Box) Focus(delegate func(p Primitive))

Focus is called when this primitive directly receives focus.

func (*Box) GetBackgroundColor

func (b *Box) GetBackgroundColor() tcell.Color

GetBackgroundColor returns the box's background color.

func (*Box) GetBorderSet

func (b *Box) GetBorderSet() BorderSet

GetBorderSet returns the box' borderSet

func (*Box) GetBorders

func (b *Box) GetBorders() Borders

GetBorders returns the borders.

func (*Box) GetFooter

func (b *Box) GetFooter() string

GetFooter returns the box's current footer.

func (*Box) GetInnerRect

func (b *Box) GetInnerRect() (int, int, int, int)

GetInnerRect returns the position of the inner rectangle (x, y, width, height), without the border and without any padding. Width and height values will clamp to 0 and thus never be negative.

func (*Box) GetRect

func (b *Box) GetRect() (int, int, int, int)

GetRect returns the current position of the rectangle, x, y, width, and height.

func (*Box) GetTitle

func (b *Box) GetTitle() string

GetTitle returns the box's current title.

func (*Box) HandleEvent

func (b *Box) HandleEvent(event tcell.Event) Command

HandleEvent handles input events for this primitive.

func (*Box) HasFocus

func (b *Box) HasFocus() bool

HasFocus returns whether or not this primitive has focus.

func (*Box) InInnerRect

func (b *Box) InInnerRect(x, y int) bool

InInnerRect returns true if the given coordinate is within the bounds of the box's inner rectangle (within the border and padding).

func (*Box) InRect

func (b *Box) InRect(x, y int) bool

InRect returns true if the given coordinate is within the bounds of the box's rectangle.

func (*Box) SetBackgroundColor

func (b *Box) SetBackgroundColor(color tcell.Color) *Box

SetBackgroundColor sets the box's background color.

func (*Box) SetBlurFunc

func (b *Box) SetBlurFunc(callback func()) *Box

SetBlurFunc sets a callback function which is invoked when this primitive loses focus. Container primitives such as Flex or Grid will also be notified if one of their descendents lose focus. Note that this may result in a blur notification, immediately followed by a focus notification, when the focus is set to a different different descendent of the container primitive.

At this point, the order in which the blur callbacks are invoked during one draw cycle, is not defined. However, the blur callbacks are always invoked before the focus callbacks.

Set to nil to remove the callback function.

func (*Box) SetBorderPadding

func (b *Box) SetBorderPadding(top, bottom, left, right int) *Box

SetBorderPadding sets the size of the borders around the box content.

func (*Box) SetBorderSet

func (b *Box) SetBorderSet(borderSet BorderSet) *Box

SetBorderSet sets the box' borderset

func (*Box) SetBorderStyle

func (b *Box) SetBorderStyle(style tcell.Style) *Box

SetBorderStyle sets the box's border style.

func (*Box) SetBorders

func (b *Box) SetBorders(flag Borders) *Box

SetBorders sets which borders to draw.

func (*Box) SetFocusFunc

func (b *Box) SetFocusFunc(callback func()) *Box

SetFocusFunc sets a callback function which is invoked when this primitive receives focus. Container primitives such as Flex or Grid will also be notified if one of their descendents receive focus directly. Note that this may result in a blur notification, immediately followed by a focus notification, when the focus is set to a different descendent of the container primitive.

At this point, the order in which the focus callbacks are invoked during one draw cycle, is not defined. However, the blur callbacks are always invoked before the focus callbacks.

Set to nil to remove the callback function.

func (*Box) SetFooter

func (b *Box) SetFooter(footer string) *Box

SetFooter sets the box's footer.

func (*Box) SetFooterAlignment

func (b *Box) SetFooterAlignment(alignment Alignment) *Box

SetFooterAlignment sets the alignment of the footer.

func (*Box) SetFooterStyle

func (b *Box) SetFooterStyle(style tcell.Style) *Box

SetFooterStyle sets the style of the footer.

func (*Box) SetRect

func (b *Box) SetRect(x, y, width, height int)

SetRect sets a new position of the primitive. Note that this has no effect if this primitive is part of a layout (e.g. Flex, Grid) or if it was added like this:

application.SetRoot(p, true)

func (*Box) SetTitle

func (b *Box) SetTitle(title string) *Box

SetTitle sets the box's title.

func (*Box) SetTitleAlignment

func (b *Box) SetTitleAlignment(alignment Alignment) *Box

SetTitleAlignment sets the alignment of the title.

func (*Box) SetTitleStyle

func (b *Box) SetTitleStyle(style tcell.Style) *Box

SetTitleStyle sets the style of the title.

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/ayn2op/tview/wiki/Button for an example.

func NewButton

func NewButton(label string) *Button

NewButton returns a new input field.

func (*Button) Draw

func (b *Button) Draw(screen tcell.Screen)

Draw draws this primitive onto the screen.

func (*Button) GetDisabled

func (b *Button) GetDisabled() bool

GetDisabled returns whether or not the button is disabled.

func (*Button) GetLabel

func (b *Button) GetLabel() string

GetLabel returns the button text.

func (*Button) HandleEvent

func (b *Button) HandleEvent(event tcell.Event) Command

HandleEvent handles input events for this primitive.

func (*Button) SetActivatedStyle

func (b *Button) SetActivatedStyle(style tcell.Style) *Button

SetActivatedStyle sets the style of the button used when it is focused.

func (*Button) SetBackgroundColorActivated

func (b *Button) SetBackgroundColorActivated(color tcell.Color) *Button

SetBackgroundColorActivated sets the background color of the button text when the button is in focus.

func (*Button) SetDisabled

func (b *Button) SetDisabled(disabled bool) *Button

SetDisabled sets whether or not the button is disabled. Disabled buttons cannot be activated.

If the button is part of a form, you should set focus to the form itself after calling this function to set focus to the next non-disabled form item.

func (*Button) SetDisabledStyle

func (b *Button) SetDisabledStyle(style tcell.Style) *Button

SetDisabledStyle sets the style of the button used when it is disabled.

func (*Button) SetExitFunc

func (b *Button) SetExitFunc(handler func(key tcell.Key)) *Button

SetExitFunc 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) SetLabel

func (b *Button) SetLabel(label string) *Button

SetLabel sets the button text.

func (*Button) SetLabelColor

func (b *Button) SetLabelColor(color tcell.Color) *Button

SetLabelColor sets the color of the button text.

func (*Button) SetLabelColorActivated

func (b *Button) SetLabelColorActivated(color tcell.Color) *Button

SetLabelColorActivated sets the color of the button text when the button is in focus.

func (*Button) SetSelectedFunc

func (b *Button) SetSelectedFunc(handler func()) *Button

SetSelectedFunc sets a handler which is called when the button was selected.

func (*Button) SetStyle

func (b *Button) SetStyle(style tcell.Style) *Button

SetStyle sets the style of the button used when it is not focused.

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/ayn2op/tview/wiki/Checkbox for an example.

func NewCheckbox

func NewCheckbox() *Checkbox

NewCheckbox returns a new input field.

func (*Checkbox) Draw

func (c *Checkbox) Draw(screen tcell.Screen)

Draw draws this primitive onto the screen.

func (*Checkbox) Focus

func (c *Checkbox) Focus(delegate func(p Primitive))

Focus is called when this primitive receives focus.

func (*Checkbox) GetDisabled

func (c *Checkbox) GetDisabled() bool

GetDisabled returns whether or not the item is disabled / read-only.

func (*Checkbox) GetFieldHeight

func (c *Checkbox) GetFieldHeight() int

GetFieldHeight returns this primitive's field height.

func (*Checkbox) GetFieldWidth

func (c *Checkbox) GetFieldWidth() int

GetFieldWidth returns this primitive's field width.

func (*Checkbox) GetLabel

func (c *Checkbox) GetLabel() string

GetLabel returns the text to be displayed before the input area.

func (*Checkbox) HandleEvent

func (c *Checkbox) HandleEvent(event tcell.Event) Command

HandleEvent handles input events for this primitive.

func (*Checkbox) IsChecked

func (c *Checkbox) IsChecked() bool

IsChecked returns whether or not the box is checked.

func (*Checkbox) SetActivatedStyle

func (c *Checkbox) SetActivatedStyle(style tcell.Style) *Checkbox

SetActivatedStyle sets the style of the checkbox when it is currently focused.

func (*Checkbox) SetChangedFunc

func (c *Checkbox) SetChangedFunc(handler func(checked bool)) *Checkbox

SetChangedFunc sets a handler which is called when the checked state of this checkbox was changed. The handler function receives the new state.

func (*Checkbox) SetChecked

func (c *Checkbox) SetChecked(checked bool) *Checkbox

SetChecked sets the state of the checkbox. This also triggers the "changed" callback if the state changes with this call.

func (*Checkbox) SetCheckedString

func (c *Checkbox) SetCheckedString(checked string) *Checkbox

SetCheckedString sets the string to be displayed when the checkbox is checked (defaults to "X").

func (*Checkbox) SetCheckedStyle

func (c *Checkbox) SetCheckedStyle(style tcell.Style) *Checkbox

SetCheckedStyle sets the style of the checked checkbox.

func (*Checkbox) SetDisabled

func (c *Checkbox) SetDisabled(disabled bool) FormItem

SetDisabled sets whether or not the item is disabled / read-only.

func (*Checkbox) SetDoneFunc

func (c *Checkbox) SetDoneFunc(handler func(key tcell.Key)) *Checkbox

SetDoneFunc sets a handler which is called when the user is done using the checkbox. 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

func (c *Checkbox) SetFieldBackgroundColor(color tcell.Color) *Checkbox

SetFieldBackgroundColor sets the background color of the input area.

func (*Checkbox) SetFieldTextColor

func (c *Checkbox) SetFieldTextColor(color tcell.Color) *Checkbox

SetFieldTextColor sets the text color of the input area.

func (*Checkbox) SetFinishedFunc

func (c *Checkbox) SetFinishedFunc(handler func(key tcell.Key)) FormItem

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) SetLabel

func (c *Checkbox) SetLabel(label string) *Checkbox

SetLabel sets the text to be displayed before the input area.

func (*Checkbox) SetLabelColor

func (c *Checkbox) SetLabelColor(color tcell.Color) *Checkbox

SetLabelColor sets the color of the label.

func (*Checkbox) SetLabelStyle

func (c *Checkbox) SetLabelStyle(style tcell.Style) *Checkbox

SetLabelStyle sets the style of the label.

func (*Checkbox) SetLabelWidth

func (c *Checkbox) SetLabelWidth(width int) *Checkbox

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 (*Checkbox) SetUncheckedString

func (c *Checkbox) SetUncheckedString(unchecked string) *Checkbox

SetUncheckedString sets the string to be displayed when the checkbox is not checked (defaults to the empty space " ").

func (*Checkbox) SetUncheckedStyle

func (c *Checkbox) SetUncheckedStyle(style tcell.Style) *Checkbox

SetUncheckedStyle sets the style of the unchecked checkbox.

type Command

type Command any

Command is a side effect requested by a primitive during input handling. Commands are executed by the Application event loop.

type EventCommand

type EventCommand func() tcell.Event

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/ayn2op/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 not clear its contents 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 a box with the desired color:

flex.Box = NewBox()

func (*Flex) AddItem

func (f *Flex) AddItem(item Primitive, fixedSize, proportion int, focus bool) *Flex

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) Clear

func (f *Flex) Clear() *Flex

Clear removes all items from the container.

func (*Flex) Draw

func (f *Flex) Draw(screen tcell.Screen)

Draw draws this primitive onto the screen.

func (*Flex) Focus

func (f *Flex) Focus(delegate func(p Primitive))

Focus is called when this primitive receives focus.

func (*Flex) GetItem

func (f *Flex) GetItem(index int) Primitive

GetItem returns the primitive at the given index, starting with 0 for the first primitive in this container.

This function will panic for out of range indices.

func (*Flex) GetItemCount

func (f *Flex) GetItemCount() int

GetItemCount returns the number of items in this container.

func (*Flex) HandleEvent

func (f *Flex) HandleEvent(event tcell.Event) Command

HandleEvent handles input events for this primitive.

func (*Flex) HasFocus

func (f *Flex) HasFocus() bool

HasFocus returns whether or not this primitive has focus.

func (*Flex) RemoveItem

func (f *Flex) RemoveItem(p Primitive) *Flex

RemoveItem removes all items for the given primitive from the container, keeping the order of the remaining items intact.

func (*Flex) ResizeItem

func (f *Flex) ResizeItem(p Primitive, fixedSize, proportion int) *Flex

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

func (f *Flex) SetDirection(direction int) *Flex

SetDirection sets the direction in which the contained primitives are distributed. This can be either FlexColumn (default) or FlexRow. Note that these are the opposite of what you would expect coming from CSS. You may also use FlexColumnCSS or FlexRowCSS, to remain in line with the CSS definition.

func (*Flex) SetFullScreen

func (f *Flex) SetFullScreen(fullScreen bool) *Flex

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 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/ayn2op/tview/wiki/Form for an example.

func NewForm

func NewForm() *Form

NewForm returns a new form.

func (*Form) AddButton

func (f *Form) AddButton(label string, selected func()) *Form

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

func (f *Form) AddCheckbox(label string, checked bool, changed func(checked bool)) *Form

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) AddFormItem

func (f *Form) AddFormItem(item FormItem) *Form

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, 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), 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) AddTextArea

func (f *Form) AddTextArea(label, text string, fieldWidth, fieldHeight, maxLength int, changed func(text string)) *Form

AddTextArea adds a text area to the form. It has a label, an optional initial text, a size (width and height) referring to the actual input area (a fieldWidth of 0 extends it as far right as possible, a fieldHeight of 0 will cause it to be DefaultFormFieldHeight), and a maximum number of bytes of text allowed (0 means no limit).

The optional callback function is invoked when the content of the text area has changed. Note that especially for larger texts, this is an expensive operation due to technical constraints of the TextArea primitive (every key stroke leads to a new reallocation of the entire text).

func (*Form) AddTextView

func (f *Form) AddTextView(label, text string, fieldWidth, fieldHeight int, scrollable bool) *Form

AddTextView adds a text view to the form. It has a label and text, a size (width and height) referring to the actual text element (a fieldWidth of 0 extends it as far right as possible, a fieldHeight of 0 will cause it to be DefaultFormFieldHeight), and a flag to turn on/off scrolling. If scrolling is turned off, the text view will not receive focus.

func (*Form) Clear

func (f *Form) Clear(includeButtons bool) *Form

Clear removes all input elements from the form, including the buttons if specified.

func (*Form) ClearButtons

func (f *Form) ClearButtons() *Form

ClearButtons removes all buttons from the form.

func (*Form) Draw

func (f *Form) Draw(screen tcell.Screen)

Draw draws this primitive onto the screen.

func (*Form) Focus

func (f *Form) Focus(delegate func(p Primitive))

Focus is called by the application when the primitive receives focus.

func (*Form) GetButton

func (f *Form) GetButton(index int) *Button

GetButton returns the button at the specified 0-based index. Note that buttons have been specially prepared for this form and modifying some of their attributes may have unintended side effects.

func (*Form) GetButtonCount

func (f *Form) GetButtonCount() int

GetButtonCount returns the number of buttons in this form.

func (*Form) GetButtonIndex

func (f *Form) GetButtonIndex(label string) int

GetButtonIndex returns the index of the button with the given label, starting with 0 for the button that was added first. If no such label was found, -1 is returned.

func (*Form) GetFocusedItemIndex

func (f *Form) GetFocusedItemIndex() (formItem, button int)

GetFocusedItemIndex returns the indices of the form element or button which currently has focus. If they don't, -1 is returned respectively.

func (*Form) GetFormItem

func (f *Form) GetFormItem(index int) FormItem

GetFormItem returns the form item at the given position, starting with index 0. Elements are referenced in the order they were added. Buttons are not included.

func (*Form) GetFormItemByLabel

func (f *Form) GetFormItemByLabel(label string) FormItem

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) GetFormItemCount

func (f *Form) GetFormItemCount() int

GetFormItemCount returns the number of items in the form (not including the buttons).

func (*Form) GetFormItemIndex

func (f *Form) GetFormItemIndex(label string) int

GetFormItemIndex returns the index of the first form element with the given label. If no such element is found, -1 is returned. Buttons are not searched and will therefore not be returned.

func (*Form) HandleEvent

func (f *Form) HandleEvent(event tcell.Event) Command

HandleEvent handles input events for this primitive.

func (*Form) HasFocus

func (f *Form) HasFocus() bool

HasFocus returns whether or not this primitive has focus.

func (*Form) RemoveButton

func (f *Form) RemoveButton(index int) *Form

RemoveButton removes the button at the specified position, starting with 0 for the button that was added first.

func (*Form) RemoveFormItem

func (f *Form) RemoveFormItem(index int) *Form

RemoveFormItem removes 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) SetButtonActivatedStyle

func (f *Form) SetButtonActivatedStyle(style tcell.Style) *Form

SetButtonActivatedStyle sets the style of the buttons when they are focused.

func (*Form) SetButtonDisabledStyle

func (f *Form) SetButtonDisabledStyle(style tcell.Style) *Form

SetButtonDisabledStyle sets the style of the buttons when they are disabled.

func (*Form) SetButtonStyle

func (f *Form) SetButtonStyle(style tcell.Style) *Form

SetButtonStyle sets the style of the buttons when they are not focused.

func (*Form) SetButtonsAlignment

func (f *Form) SetButtonsAlignment(alignment Alignment) *Form

SetButtonsAlignment sets how the buttons align horizontally.

func (*Form) SetCancelFunc

func (f *Form) SetCancelFunc(callback func()) *Form

SetCancelFunc sets a handler which is called when the user hits the Escape key.

func (*Form) SetFieldStyle

func (f *Form) SetFieldStyle(style tcell.Style) *Form

SetFieldStyle sets the style of the input areas.

func (*Form) SetFocus

func (f *Form) SetFocus(index int) *Form

SetFocus shifts the focus to the form element with the given index, counting non-button items first and buttons last. This does not change the application's focus immediately, but the next time the form itself receives focus, the given element will be focused once. Set to a negative value to focus the first (enabled) element.

func (*Form) SetHorizontal

func (f *Form) SetHorizontal(horizontal bool) *Form

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

func (f *Form) SetItemPadding(padding int) *Form

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. In vertical layouts, there is always at least one empty line between the last item and the buttons, if any.

func (*Form) SetLabelColor

func (f *Form) SetLabelColor(color tcell.Color) *Form

SetLabelColor sets the color of the labels.

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 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

	// GetDisabled returns whether or not the item is disabled / read-only.
	GetDisabled() bool
}

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 space around another primitive. In addition, the top area (header) and the bottom area (footer) may also contain text.

See https://github.com/ayn2op/tview/wiki/Frame for an example.

func NewFrame

func NewFrame(primitive Primitive) *Frame

NewFrame returns a new frame around the given primitive. The primitive's size will be changed to fit within this frame. The primitive may be nil, in which case no other primitive is embedded in the frame.

func (*Frame) AddText

func (f *Frame) AddText(text string, header bool, alignment Alignment, color tcell.Color) *Frame

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. 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) Clear

func (f *Frame) Clear() *Frame

Clear removes all text from the frame.

func (*Frame) Draw

func (f *Frame) Draw(screen tcell.Screen)

Draw draws this primitive onto the screen.

func (*Frame) Focus

func (f *Frame) Focus(delegate func(p Primitive))

Focus is called when this primitive receives focus.

func (*Frame) GetPrimitive

func (f *Frame) GetPrimitive() Primitive

GetPrimitive returns the primitive contained in this frame.

func (*Frame) HandleEvent

func (f *Frame) HandleEvent(event tcell.Event) Command

HandleEvent handles input events for this primitive.

func (*Frame) HasFocus

func (f *Frame) HasFocus() bool

HasFocus returns whether or not this primitive has focus.

func (*Frame) SetBorders

func (f *Frame) SetBorders(top, bottom, header, footer, left, right int) *Frame

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).

func (*Frame) SetPrimitive

func (f *Frame) SetPrimitive(p Primitive) *Frame

SetPrimitive replaces the contained primitive with the given one. To remove a primitive, set it to nil.

type GetClipboardCommand

type GetClipboardCommand struct{}

type GlyphSet

type GlyphSet struct {
	TrackVertical string

	ArrowVerticalStart string
	ArrowVerticalEnd   string

	ThumbVerticalLower [8]string
	ThumbVerticalUpper [8]string
}

GlyphSet defines vertical track, arrow, and fractional thumb glyphs.

func BoxDrawingGlyphSet

func BoxDrawingGlyphSet() GlyphSet

BoxDrawingGlyphSet returns box-drawing track glyphs with legacy fractional symbols.

func LegacyComputingGlyphSet

func LegacyComputingGlyphSet() GlyphSet

LegacyComputingGlyphSet returns legacy-computing symbols for full 1/8 fractional fidelity.

func MinimalGlyphSet

func MinimalGlyphSet() GlyphSet

MinimalGlyphSet returns the minimal glyph set (space track, fractional thumbs).

func UnicodeGlyphSet

func UnicodeGlyphSet() GlyphSet

UnicodeGlyphSet returns a standard-unicode-only approximation set.

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 be 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, reset its Box to one with the desired color:

grid.Box = NewBox()

func (*Grid) AddItem

func (g *Grid) AddItem(p Primitive, row, column, rowSpan, colSpan, 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 "rowSpan" rows and "colSpan" columns. For example, for a primitive to occupy rows 2, 3, and 4 and columns 5 and 6:

grid.AddItem(p, 2, 5, 3, 2, 0, 0, true)

If rowSpan or colSpan 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 with the highest minimum value (width or height, whatever is higher) 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) Clear

func (g *Grid) Clear() *Grid

Clear removes all items from the grid.

func (*Grid) Draw

func (g *Grid) Draw(screen tcell.Screen)

Draw draws this primitive onto the screen.

func (*Grid) Focus

func (g *Grid) Focus(delegate func(p Primitive))

Focus is called when this primitive receives focus.

func (*Grid) GetOffset

func (g *Grid) GetOffset() (rows, columns int)

GetOffset returns the current row and column offset (see SetOffset() for details).

func (*Grid) HandleEvent

func (g *Grid) HandleEvent(event tcell.Event) Command

HandleEvent handles input events for this primitive.

func (*Grid) HasFocus

func (g *Grid) HasFocus() bool

HasFocus returns whether or not this primitive has focus.

func (*Grid) RemoveItem

func (g *Grid) RemoveItem(p Primitive) *Grid

RemoveItem removes all items for the given primitive from the grid, keeping the order of the remaining items intact.

func (*Grid) SetBorders

func (g *Grid) SetBorders(borders bool) *Grid

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

func (g *Grid) SetBordersColor(color tcell.Color) *Grid

SetBordersColor sets the color of the item borders.

func (*Grid) SetColumns

func (g *Grid) SetColumns(columns ...int) *Grid

SetColumns defines how the columns of the grid are distributed. Each value defines the size of one column, starting with the leftmost column. Values greater than 0 represent absolute column widths (gaps not included). Values less than or equal to 0 represent proportional column widths or fractions of the remaining free space, where 0 is treated the same as -1. That is, a column with a value of -3 will have three times the width of a column with a value of -1 (or 0). The minimum width set with SetMinSize() is always observed.

Primitives may extend beyond the columns defined explicitly with this function. A value of 0 is assumed for any undefined column. In fact, if you never call this function, all columns occupied by primitives will have the same width. On the other hand, unoccupied columns 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 columns with widths of 30, 10, 15, 15, and 30 cells:

grid.SetColumns(30, 10, -1, -1, -2)

If a primitive were then placed in the 6th and 7th column, 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.

func (*Grid) SetGap

func (g *Grid) SetGap(row, column int) *Grid

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

func (g *Grid) SetMinSize(row, column int) *Grid

SetMinSize sets an absolute minimum width for rows and an absolute minimum height for columns. Panics if negative values are provided.

func (*Grid) SetOffset

func (g *Grid) SetOffset(rows, columns int) *Grid

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 remain visible.

func (*Grid) SetRows

func (g *Grid) SetRows(rows ...int) *Grid

SetRows defines how the rows of the grid are distributed. These values behave the same as the column values provided with Grid.SetColumns, see there for a definition and examples.

The provided values correspond to row heights, the first value defining the height of the topmost row.

func (*Grid) SetSize

func (g *Grid) SetSize(numRows, numColumns, rowSize, columnSize int) *Grid

SetSize is a shortcut for Grid.SetRows and Grid.SetColumns where all row and column values are set to the given size values. See Grid.SetColumns for details on sizes.

type InitEvent

type InitEvent struct{ tcell.EventTime }

func NewInitEvent

func NewInitEvent() *InitEvent

type InputField

type InputField struct {
	*Box
	// contains filtered or unexported fields
}

InputField is a one-line box into which the user can enter text. Use [InputField.SetAcceptanceFunc] to accept or reject input, InputField.SetChangedFunc to listen for changes, and InputField.SetMaskCharacter to hide input from onlookers (e.g. for password input).

Navigation and editing is the same as for a TextArea, with the following exceptions:

  • Tab, BackTab, Enter, Escape: Finish editing.

Note that while pressing Tab or Enter is intercepted by the input field, it is possible to paste such characters into the input field, possibly resulting in multi-line input. You can use [InputField.SetAcceptanceFunc] to prevent this.

See https://github.com/ayn2op/tview/wiki/InputField for an example.

func NewInputField

func NewInputField() *InputField

NewInputField returns a new input field.

func (*InputField) Blur

func (i *InputField) Blur()

Blur is called when this primitive loses focus.

func (*InputField) Draw

func (i *InputField) Draw(screen tcell.Screen)

Draw draws this primitive onto the screen.

func (*InputField) Focus

func (i *InputField) Focus(delegate func(p Primitive))

Focus is called when this primitive receives focus.

func (*InputField) GetDisabled

func (i *InputField) GetDisabled() bool

GetDisabled returns whether or not the item is disabled / read-only.

func (*InputField) GetFieldHeight

func (i *InputField) GetFieldHeight() int

GetFieldHeight returns this primitive's field height.

func (*InputField) GetFieldStyle

func (i *InputField) GetFieldStyle() tcell.Style

GetFieldStyle returns the style of the input area (when no placeholder is shown).

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) GetLabelStyle

func (i *InputField) GetLabelStyle() tcell.Style

GetLabelStyle returns the style of the label.

func (*InputField) GetText

func (i *InputField) GetText() string

GetText returns the current text of the input field.

func (*InputField) HandleEvent

func (i *InputField) HandleEvent(event tcell.Event) Command

HandleEvent handles input events for this primitive.

func (*InputField) HasFocus

func (i *InputField) HasFocus() bool

HasFocus returns whether or not this primitive has focus.

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) SetDisabled

func (i *InputField) SetDisabled(disabled bool) FormItem

SetDisabled sets whether or not the item is disabled / read-only.

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) SetFieldStyle

func (i *InputField) SetFieldStyle(style tcell.Style) *InputField

SetFieldStyle sets the style of the input area (when no placeholder is shown).

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 text color of the label.

func (*InputField) SetLabelStyle

func (i *InputField) SetLabelStyle(style tcell.Style) *InputField

SetLabelStyle sets the style 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(line Line) *InputField

SetPlaceholder sets the styled text to be displayed when the input text is empty.

func (*InputField) SetText

func (i *InputField) SetText(text string) *InputField

SetText sets the current text of the input field. This can be undone by the user. Calling this function will also trigger a "changed" event.

type KeyEvent

type KeyEvent = tcell.EventKey

type Line

type Line []Segment

Line is a list of styled segments.

func NewLine

func NewLine(segments ...Segment) Line

NewLine returns a line from the provided segments, skipping empty segments.

func (Line) Clone

func (l Line) Clone() Line

Clone returns a copy of this line with an independent backing array.

type LineBuilder

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

LineBuilder incrementally builds styled lines from text writes.

func NewLineBuilder

func NewLineBuilder() *LineBuilder

NewLineBuilder returns a new line builder.

func (*LineBuilder) AppendLines

func (b *LineBuilder) AppendLines(lines []Line)

AppendLines appends fully built lines into the builder.

func (*LineBuilder) Finish

func (b *LineBuilder) Finish() []Line

Finish returns all built lines.

func (*LineBuilder) HasCurrentLine

func (b *LineBuilder) HasCurrentLine() bool

HasCurrentLine returns true when unflushed segments exist.

func (*LineBuilder) NewLine

func (b *LineBuilder) NewLine()

NewLine flushes the current line into the builder output.

func (*LineBuilder) Write

func (b *LineBuilder) Write(text string, style tcell.Style)

Write appends text with style and splits on newline boundaries.

type List

type List struct {
	*Box

	Builder ListBuilder
	// contains filtered or unexported fields
}

List displays a virtual list of primitives returned by a builder function.

func NewList

func NewList() *List

NewList returns a new scroll list.

func (*List) Clear

func (l *List) Clear() *List

Clear removes all items from the list by clearing the builder and resetting scroll state.

func (*List) Cursor

func (l *List) Cursor() int

Cursor returns the current cursor index.

func (*List) Draw

func (l *List) Draw(screen tcell.Screen)

Draw draws this primitive onto the screen.

func (*List) HandleEvent

func (l *List) HandleEvent(event tcell.Event) Command

HandleEvent handles input events for this primitive.

func (*List) NextItem

func (l *List) NextItem() bool

NextItem moves the cursor to the next item, if any.

func (*List) PrevItem

func (l *List) PrevItem() bool

PrevItem moves the cursor to the previous item, if any.

func (*List) ScrollDown

func (l *List) ScrollDown() *List

ScrollDown scrolls the list down by one line.

func (*List) ScrollToEnd

func (l *List) ScrollToEnd() *List

ScrollToEnd scrolls the view so the last items are visible.

func (*List) ScrollToStart

func (l *List) ScrollToStart() *List

ScrollToStart resets the scroll position to the top (index 0), without changing the cursor.

func (*List) ScrollUp

func (l *List) ScrollUp() *List

ScrollUp scrolls the list up by one line.

func (*List) SetBuilder

func (l *List) SetBuilder(builder ListBuilder) *List

SetBuilder sets the builder used to create list items on demand.

func (*List) SetCenterCursor

func (l *List) SetCenterCursor(center bool) *List

SetCenterCursor controls whether the cursor is kept centered whenever possible.

func (*List) SetChangedFunc

func (l *List) SetChangedFunc(handler func(index int)) *List

SetChangedFunc sets a handler that is called when the cursor changes.

func (*List) SetCursor

func (l *List) SetCursor(index int) *List

SetCursor sets the currently selected item index.

func (*List) SetGap

func (l *List) SetGap(gap int) *List

SetGap sets the number of blank rows between items.

func (*List) SetPendingScroll

func (l *List) SetPendingScroll(lines int) *List

SetPendingScroll sets a pending scroll amount, in lines. Positive numbers scroll down.

func (*List) SetScrollBar

func (l *List) SetScrollBar(scrollBar *ScrollBar) *List

SetScrollBar sets the ScrollBar primitive used by this list.

func (*List) SetScrollBarVisibility

func (l *List) SetScrollBarVisibility(visibility ScrollBarVisibility) *List

SetScrollBarVisibility sets when the list scrollBar is rendered.

func (*List) SetSnapToItems

func (l *List) SetSnapToItems(snap bool) *List

SetSnapToItems toggles snapping so only fully visible items are shown.

func (*List) SetTrackEnd

func (l *List) SetTrackEnd(track bool) *List

SetTrackEnd toggles auto-scrolling when the view is already at the end.

type ListBuilder

type ListBuilder func(index int, cursor int) ListItem

ListBuilder returns a list item for the given index and cursor position. It must return nil when the index is out of range.

type ListItem

type ListItem interface {
	Primitive
	Height(width int) int
}

ListItem represents a primitive which can be measured for a given width.

Scroll list items are responsible for reporting their own height so the list can layout and scroll variable-height items.

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 Modal.AddButtons) or it will never disappear.

See https://github.com/ayn2op/tview/wiki/Modal for an example.

func NewModal

func NewModal() *Modal

NewModal returns a new modal message window.

func (*Modal) AddButtons

func (m *Modal) AddButtons(labels []string) *Modal

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) ClearButtons

func (m *Modal) ClearButtons() *Modal

ClearButtons removes all buttons from the window.

func (*Modal) Draw

func (m *Modal) Draw(screen tcell.Screen)

Draw draws this primitive onto the screen.

func (*Modal) Focus

func (m *Modal) Focus(delegate func(p Primitive))

Focus is called when this primitive receives focus.

func (*Modal) HandleEvent

func (m *Modal) HandleEvent(event tcell.Event) Command

HandleEvent handles input events for this primitive.

func (*Modal) HasFocus

func (m *Modal) HasFocus() bool

HasFocus returns whether or not this primitive has focus.

func (*Modal) SetBackgroundColor

func (m *Modal) SetBackgroundColor(color tcell.Color) *Modal

SetBackgroundColor sets the color of the modal frame background.

func (*Modal) SetButtonActivatedStyle

func (m *Modal) SetButtonActivatedStyle(style tcell.Style) *Modal

SetButtonActivatedStyle sets the style of the buttons when they are focused.

func (*Modal) SetButtonStyle

func (m *Modal) SetButtonStyle(style tcell.Style) *Modal

SetButtonStyle sets the style of the buttons when they are not focused.

func (*Modal) SetDoneFunc

func (m *Modal) SetDoneFunc(handler func(buttonIndex int, buttonLabel string)) *Modal

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 empty string.

func (*Modal) SetFocus

func (m *Modal) SetFocus(index int) *Modal

SetFocus shifts the focus to the button with the given index.

func (*Modal) SetText

func (m *Modal) SetText(text string) *Modal

SetText sets the message text of the window. The text may contain line breaks. Note that words are wrapped, too, based on the final size of the window.

func (*Modal) SetTextColor

func (m *Modal) SetTextColor(color tcell.Color) *Modal

SetTextColor sets the color of the message text.

type MouseAction

type MouseAction int16

MouseAction indicates one of the actions the mouse is logically doing.

const (
	MouseMove MouseAction = iota
	MouseLeftDown
	MouseLeftUp
	MouseLeftClick
	MouseLeftDoubleClick
	MouseMiddleDown
	MouseMiddleUp
	MouseMiddleClick
	MouseMiddleDoubleClick
	MouseRightDown
	MouseRightUp
	MouseRightClick
	MouseRightDoubleClick
	MouseScrollUp
	MouseScrollDown
	MouseScrollLeft
	MouseScrollRight
)

Available mouse actions.

type MouseEvent

type MouseEvent struct {
	tcell.EventMouse
	Action MouseAction
}

func NewMouseEvent

func NewMouseEvent(mouseEvent tcell.EventMouse, action MouseAction) *MouseEvent

type NotifyCommand

type NotifyCommand struct{ Title, Body string }

type PasteEvent

type PasteEvent struct {
	tcell.EventTime
	Content string
}

func NewPasteEvent

func NewPasteEvent(content string) *PasteEvent

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)
	// HandleEvent receives events when this primitive has focus.
	HandleEvent(event tcell.Event) Command

	// 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)

	// HasFocus determines if the primitive has focus. This function must return
	// true also if one of this primitive's child elements has focus.
	HasFocus() bool
	// 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()
}

Primitive is the top-most interface for all graphical primitives.

type QuitCommand

type QuitCommand struct{}

type RedrawCommand

type RedrawCommand struct{}

type ScrollBar

type ScrollBar struct {
	*Box
	// contains filtered or unexported fields
}

ScrollBar renders a vertical customizable scrollBar widget.

func NewScrollBar

func NewScrollBar() *ScrollBar

NewScrollBar returns a new vertical scrollBar.

func NewVerticalScrollBar

func NewVerticalScrollBar(lengths ScrollLengths) *ScrollBar

NewVerticalScrollBar creates a vertical scrollBar from lengths.

func (*ScrollBar) Draw

func (s *ScrollBar) Draw(screen tcell.Screen)

Draw draws the scrollBar.

func (*ScrollBar) SetArrowStyle

func (s *ScrollBar) SetArrowStyle(style tcell.Style) *ScrollBar

SetArrowStyle sets the arrow endcap style.

func (*ScrollBar) SetArrows

func (s *ScrollBar) SetArrows(arrows ScrollBarArrows) *ScrollBar

SetArrows sets which arrow endcaps are rendered.

func (*ScrollBar) SetAutoHide

func (s *ScrollBar) SetAutoHide(autoHide bool) *ScrollBar

SetAutoHide controls whether the scrollBar is hidden when there is nothing to scroll.

func (*ScrollBar) SetGlyphSet

func (s *ScrollBar) SetGlyphSet(g GlyphSet) *ScrollBar

SetGlyphSet applies a glyph set.

func (*ScrollBar) SetLengths

func (s *ScrollBar) SetLengths(lengths ScrollLengths) *ScrollBar

SetLengths sets content and viewport lengths.

func (*ScrollBar) SetOffset

func (s *ScrollBar) SetOffset(offset int) *ScrollBar

SetOffset sets the logical offset.

func (*ScrollBar) SetScrollStep

func (s *ScrollBar) SetScrollStep(step int) *ScrollBar

SetScrollStep sets scroll step used by wheel and arrow interactions.

func (*ScrollBar) SetThumbGlyph

func (s *ScrollBar) SetThumbGlyph(glyph string) *ScrollBar

SetThumbGlyph sets all thumb glyphs to a single symbol.

func (*ScrollBar) SetThumbStyle

func (s *ScrollBar) SetThumbStyle(style tcell.Style) *ScrollBar

SetThumbStyle sets the thumb style.

func (*ScrollBar) SetTrackClickBehavior

func (s *ScrollBar) SetTrackClickBehavior(behavior TrackClickBehavior) *ScrollBar

SetTrackClickBehavior sets behavior used for track clicks.

func (*ScrollBar) SetTrackGlyph

func (s *ScrollBar) SetTrackGlyph(glyph string, visible bool) *ScrollBar

SetTrackGlyph sets the track symbol and visibility.

func (*ScrollBar) SetTrackStyle

func (s *ScrollBar) SetTrackStyle(style tcell.Style) *ScrollBar

SetTrackStyle sets the track style.

type ScrollBarArrows

type ScrollBarArrows uint8

ScrollBarArrows controls which endcaps are rendered.

const (
	ScrollBarArrowsNone ScrollBarArrows = iota
	ScrollBarArrowsStart
	ScrollBarArrowsEnd
	ScrollBarArrowsBoth
)

type ScrollBarVisibility

type ScrollBarVisibility uint8

ScrollBarVisibility controls when List renders its vertical scrollBar.

const (
	ScrollBarVisibilityAutomatic ScrollBarVisibility = iota
	ScrollBarVisibilityAlways
	ScrollBarVisibilityNever
)

type ScrollLengths

type ScrollLengths struct {
	ContentLen  int
	ViewportLen int
}

ScrollLengths bundles content and viewport lengths in logical units.

type Segment

type Segment struct {
	Text  string
	Style tcell.Style
}

Segment is a styled piece of text.

func NewSegment

func NewSegment(text string, style tcell.Style) Segment

NewSegment returns a styled segment.

type SetClipboardCommand

type SetClipboardCommand string

type SetFocusCommand

type SetFocusCommand struct {
	Target Primitive
}

type SetMouseCaptureCommand

type SetMouseCaptureCommand struct {
	Target Primitive
}

type SetTitleCommand

type SetTitleCommand string

type TextArea

type TextArea struct {
	*Box
	// contains filtered or unexported fields
}

TextArea implements a simple text editor for multi-line text. Multi-color text is not supported. Word-wrapping is enabled by default but can be turned off or be changed to character-wrapping.

Navigation and Editing

A text area is always in editing mode and no other mode exists. The following keys can be used to move the cursor (subject to what the user's terminal supports and how it is configured):

  • Left arrow: Move left.
  • Right arrow: Move right.
  • Down arrow: Move down.
  • Up arrow: Move up.
  • Ctrl-A, Home: Move to the beginning of the current line.
  • Ctrl-E, End: Move to the end of the current line.
  • Ctrl-F, page down: Move down by one page.
  • Ctrl-B, page up: Move up by one page.
  • Alt-Up arrow: Scroll the page up, leaving the cursor in its position.
  • Alt-Down arrow: Scroll the page down, leaving the cursor in its position.
  • Alt-Left arrow: Scroll the page to the left, leaving the cursor in its position. Ignored if wrapping is enabled.
  • Alt-Right arrow: Scroll the page to the right, leaving the cursor in its position. Ignored if wrapping is enabled.
  • Alt-B, Ctrl-Left arrow: Jump to the beginning of the current or previous word.
  • Alt-F, Ctrl-Right arrow: Jump to the end of the current or next word.

Words are defined according to Unicode Standard Annex #29. We skip any words that contain only spaces or punctuation.

Entering a character will insert it at the current cursor location. Subsequent characters are shifted accordingly. If the cursor is outside the visible area, any changes to the text will move it into the visible area. The following keys can also be used to modify the text:

  • Enter: Insert a newline character (see TextAreaNewLine).
  • Tab: Insert a tab character (\t). It will be rendered like TabSize spaces. (This may eventually be changed to behave like regular tabs.)
  • Ctrl-H, Backspace: Delete one character to the left of the cursor.
  • Ctrl-D, Delete: Delete the character under the cursor (or the first character on the next line if the cursor is at the end of a line).
  • Alt-Backspace: Delete the word to the left of the cursor.
  • Ctrl-K: Delete everything under and to the right of the cursor until the next newline character.
  • Ctrl-W: Delete from the start of the current word to the left of the cursor.
  • Ctrl-U: Delete the current line, i.e. everything after the last newline character before the cursor up until the next newline character. This may span multiple visible rows if wrapping is enabled.

Text can be selected by moving the cursor while holding the Shift key, to the extent that this is supported by the user's terminal. The Ctrl-L key can be used to select the entire text. (Ctrl-A already binds to the "Home" key.)

When text is selected:

  • Entering a character will replace the selected text with the new character.
  • Backspace, delete, Ctrl-H, Ctrl-D: Delete the selected text.
  • Ctrl-Q: Copy the selected text into the clipboard, unselect the text.
  • Ctrl-X: Copy the selected text into the clipboard and delete it.
  • Ctrl-V: Replace the selected text with the clipboard text. If no text is selected, the clipboard text will be inserted at the cursor location.

The Ctrl-Q key was chosen for the default "copy" function to avoid clashing with common Ctrl-C quit bindings in user applications. You may remap keys in your primitive's HandleEvent and implement copying to the clipboard. Note that using your terminal's / operating system's key bindings for copy+paste functionality may not have the expected effect as tview will not be able to handle these keys. Pasting text using your operating system's or terminal's own methods may be very slow as each character will be pasted individually. However, some terminals support pasting text blocks which is supported by the text area, see [Application.EnablePaste] for details.

The default clipboard is an internal text buffer local to this text area instance, i.e. the operating system's clipboard is not used. If you want to implement your own clipboard (or make use of your operating system's clipboard), you can use TextArea.SetClipboard which provides all the functionality needed to implement your own clipboard.

The text area also supports Undo:

  • Ctrl-Z: Undo the last change.
  • Ctrl-Y: Redo the last Undo change.

Undo does not affect the clipboard.

If the mouse is enabled, the following actions are available:

  • Left click: Move the cursor to the clicked position or to the end of the line if past the last character.
  • Left double-click: Select the word under the cursor.
  • Left click while holding the Shift key: Select text.
  • Scroll wheel: Scroll the text.

func NewTextArea

func NewTextArea() *TextArea

NewTextArea returns a new text area. Use TextArea.SetText to set the initial text.

func (*TextArea) Draw

func (t *TextArea) Draw(screen tcell.Screen)

Draw draws this primitive onto the screen.

func (*TextArea) Focus

func (t *TextArea) Focus(delegate func(p Primitive))

Focus is called when this primitive receives focus.

func (*TextArea) GetClipboardText

func (t *TextArea) GetClipboardText() string

GetClipboardText returns the current text of the clipboard by calling the pasteFromClipboard function set with TextArea.SetClipboard.

func (*TextArea) GetCursor

func (t *TextArea) GetCursor() (fromRow, fromColumn, toRow, toColumn int)

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.

func (*TextArea) GetDisabled

func (t *TextArea) GetDisabled() bool

GetDisabled returns whether or not the item is disabled / read-only.

func (*TextArea) GetFieldHeight

func (t *TextArea) GetFieldHeight() int

GetFieldHeight returns this primitive's field height.

func (*TextArea) GetFieldWidth

func (t *TextArea) GetFieldWidth() int

GetFieldWidth returns this primitive's field width.

func (*TextArea) GetLabel

func (t *TextArea) GetLabel() string

GetLabel returns the text to be displayed before the text area.

func (*TextArea) GetLabelStyle

func (t *TextArea) GetLabelStyle() tcell.Style

GetLabelStyle returns the style of the label.

func (*TextArea) GetLabelWidth

func (t *TextArea) GetLabelWidth() int

GetLabelWidth returns the screen width of the label.

func (*TextArea) GetOffset

func (t *TextArea) GetOffset() (row, column int)

GetOffset returns the text's offset, that is, the number of rows and columns skipped during drawing at the top or on the left, respectively. Note that the column offset is ignored if wrapping is enabled.

func (*TextArea) GetSelection

func (t *TextArea) GetSelection() (text string, start int, end int)

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.

func (*TextArea) GetText

func (t *TextArea) GetText() string

GetText returns the entire text of the text area. Note that this will newly allocate the entire text.

func (*TextArea) GetTextLength

func (t *TextArea) GetTextLength() int

GetTextLength returns the string length of the text in the text area.

func (*TextArea) GetTextStyle

func (t *TextArea) GetTextStyle() tcell.Style

GetTextStyle returns the style of the text.

func (*TextArea) GetWordUnderCursor

func (t *TextArea) GetWordUnderCursor(f func(rune) bool) (int, string, rune)

GetWordUnderCursor returns the absolute cursor position and the word under the cursor (upto but not including the character under the cursor). A word is something that all of its runes satisfy f(r). The last rune that didn't satisfy f(r) is also returned.

func (*TextArea) HandleEvent

func (t *TextArea) HandleEvent(event tcell.Event) Command

HandleEvent handles input events for this primitive.

func (*TextArea) HasSelection

func (t *TextArea) HasSelection() bool

HasSelection returns whether the selected text is non-empty.

func (*TextArea) Replace

func (t *TextArea) Replace(start, end int, text string) *TextArea

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.

func (*TextArea) Select

func (t *TextArea) Select(start, end int) *TextArea

Select 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.

func (*TextArea) SetChangedFunc

func (t *TextArea) SetChangedFunc(handler func()) *TextArea

SetChangedFunc sets a handler which is called whenever the text of the text area has changed.

func (*TextArea) SetClipboard

func (t *TextArea) SetClipboard(copyToClipboard func(string), pasteFromClipboard func() string) *TextArea

SetClipboard 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.

func (*TextArea) SetDisabled

func (t *TextArea) SetDisabled(disabled bool) FormItem

SetDisabled sets whether or not the item is disabled / read-only.

func (*TextArea) SetFinishedFunc

func (t *TextArea) SetFinishedFunc(handler func(key tcell.Key)) FormItem

SetFinishedFunc sets a callback invoked when the user leaves this form item.

func (*TextArea) SetFormAttributes

func (t *TextArea) SetFormAttributes(labelWidth int, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem

SetFormAttributes sets attributes shared by all form items.

func (*TextArea) SetLabel

func (t *TextArea) SetLabel(label string) *TextArea

SetLabel sets the text to be displayed before the text area.

func (*TextArea) SetLabelStyle

func (t *TextArea) SetLabelStyle(style tcell.Style) *TextArea

SetLabelStyle sets the style of the label.

func (*TextArea) SetLabelWidth

func (t *TextArea) SetLabelWidth(width int) *TextArea

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 (*TextArea) SetMaxLength

func (t *TextArea) SetMaxLength(maxLength int) *TextArea

SetMaxLength sets the maximum number of bytes allowed in the text area. A value of 0 means there is no limit. If the text area currently contains more bytes than this, it may violate this constraint.

func (*TextArea) SetMovedFunc

func (t *TextArea) SetMovedFunc(handler func()) *TextArea

SetMovedFunc sets a handler which is called whenever the cursor position or the text selection has changed.

func (*TextArea) SetOffset

func (t *TextArea) SetOffset(row, column int) *TextArea

SetOffset sets the text's offset, that is, the number of rows and columns skipped during drawing at the top or on the left, respectively. If wrapping is enabled, the column offset is ignored. These values may get adjusted automatically to ensure that some text is always visible.

func (*TextArea) SetPlaceholder

func (t *TextArea) SetPlaceholder(placeholder Line) *TextArea

SetPlaceholder sets the styled line to be displayed when the text area is empty.

func (*TextArea) SetSelectedStyle

func (t *TextArea) SetSelectedStyle(style tcell.Style) *TextArea

SetSelectedStyle sets the style of the selected text.

func (*TextArea) SetSize

func (t *TextArea) SetSize(rows, columns int) *TextArea

SetSize sets the screen size of the input element of the text area. The input element is always located next to the label which is always located in the top left corner. If any of the values are 0 or larger than the available space, the available space will be used.

func (*TextArea) SetText

func (t *TextArea) SetText(text string, cursorAtTheEnd bool) *TextArea

SetText sets the text of the text area. All existing text is deleted and replaced with the new text. Any edits are discarded, no undos are available. This function is typically only used to initialize the text area with a text after it has been created. To clear the text area's text (again, no undos), provide an empty string.

If cursorAtTheEnd is false, the cursor is placed at the start of the text. If it is true, it is placed at the end of the text. For very long texts, placing the cursor at the end can be an expensive operation because the entire text needs to be parsed and laid out.

If you want to set text and preserve undo functionality, use TextArea.Replace instead.

func (*TextArea) SetTextStyle

func (t *TextArea) SetTextStyle(style tcell.Style) *TextArea

SetTextStyle sets the style of the text.

func (*TextArea) SetWordWrap

func (t *TextArea) SetWordWrap(wrapOnWords bool) *TextArea

SetWordWrap sets the flag that causes lines that are longer than the available width to be wrapped onto the next line at spaces or after punctuation marks (according to Unicode Standard Annex #14). This flag is ignored if the flag set with TextArea.SetWrap is false. The text area's default is word-wrapping.

func (*TextArea) SetWrap

func (t *TextArea) SetWrap(wrap bool) *TextArea

SetWrap sets the flag that, if true, leads to lines that are longer than the available width being wrapped onto the next line. If false, any characters beyond the available width are not displayed.

type TextView

type TextView struct {
	sync.Mutex
	*Box
	// contains filtered or unexported fields
}

TextView is a component to display read-only text. The content is represented as styled segments grouped by lines.

func NewTextView

func NewTextView() *TextView

NewTextView returns a new text view.

func (*TextView) AppendLine

func (t *TextView) AppendLine(line Line) *TextView

AppendLine appends a new line made of segments.

func (*TextView) AppendSegments

func (t *TextView) AppendSegments(segments ...Segment) *TextView

AppendSegments appends styled segments to the last line.

func (*TextView) BatchWriter

func (t *TextView) BatchWriter() TextViewWriter

BatchWriter returns a new writer that can be used to write into the buffer but without Locking/Unlocking the buffer on every write.

func (*TextView) Clear

func (t *TextView) Clear() *TextView

Clear removes all text from the buffer. This triggers the "changed" callback.

func (*TextView) Draw

func (t *TextView) Draw(screen tcell.Screen)

Draw draws this primitive onto the screen.

func (*TextView) Focus

func (t *TextView) Focus(delegate func(p Primitive))

Focus is called when this primitive receives focus.

func (*TextView) GetDisabled

func (t *TextView) GetDisabled() bool

GetDisabled returns whether or not the item is disabled / read-only.

func (*TextView) GetFieldHeight

func (t *TextView) GetFieldHeight() int

GetFieldHeight returns this primitive's field height.

func (*TextView) GetFieldWidth

func (t *TextView) GetFieldWidth() int

GetFieldWidth returns this primitive's field width.

func (*TextView) GetLabel

func (t *TextView) GetLabel() string

GetLabel returns the text to be displayed before the text view.

func (*TextView) GetLines

func (t *TextView) GetLines() []Line

GetLines returns a copy of the styled content.

func (*TextView) GetOriginalLineCount

func (t *TextView) GetOriginalLineCount() int

GetOriginalLineCount returns the number of logical lines in the current text.

func (*TextView) GetScrollOffset

func (t *TextView) GetScrollOffset() (row, column int)

GetScrollOffset returns the number of rows and columns that are skipped at the top left corner when the text view has been scrolled.

func (*TextView) GetText

func (t *TextView) GetText() string

GetText returns the current plain text of this text view.

func (*TextView) GetWrappedLineCount

func (t *TextView) GetWrappedLineCount() int

GetWrappedLineCount returns the number of visual lines, taking wrapping into account.

func (*TextView) HandleEvent

func (t *TextView) HandleEvent(event tcell.Event) Command

HandleEvent handles input events for this primitive.

func (*TextView) HasFocus

func (t *TextView) HasFocus() bool

HasFocus returns whether or not this primitive has focus.

func (*TextView) Height

func (t *TextView) Height(width int) int

Height returns the required height for rendering the text view at the given width when used as a scroll list item.

func (*TextView) ScrollTo

func (t *TextView) ScrollTo(row, column int) *TextView

ScrollTo scrolls to the specified row and column (both starting with 0).

func (*TextView) ScrollToBeginning

func (t *TextView) ScrollToBeginning() *TextView

ScrollToBeginning scrolls to the top left corner of the text if the text view is scrollable.

func (*TextView) ScrollToEnd

func (t *TextView) ScrollToEnd() *TextView

ScrollToEnd scrolls to the bottom left corner of the text if the text view is scrollable.

func (*TextView) SetBackgroundColor

func (t *TextView) SetBackgroundColor(color tcell.Color) *Box

SetBackgroundColor overrides its implementation in Box to set the background color of this primitive.

func (*TextView) SetChangedFunc

func (t *TextView) SetChangedFunc(handler func()) *TextView

SetChangedFunc sets a handler function which is called when the text of the text view has changed.

func (*TextView) SetDisabled

func (t *TextView) SetDisabled(disabled bool) FormItem

SetDisabled sets whether or not the item is disabled / read-only.

func (*TextView) SetDoneFunc

func (t *TextView) SetDoneFunc(handler func(key tcell.Key)) *TextView

SetDoneFunc sets a handler which is called when the user presses on the following keys: Escape, Enter, Tab, Backtab.

func (*TextView) SetFinishedFunc

func (t *TextView) SetFinishedFunc(handler func(key tcell.Key)) FormItem

SetFinishedFunc sets a callback invoked when the user leaves this form item.

func (*TextView) SetFormAttributes

func (t *TextView) SetFormAttributes(labelWidth int, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem

SetFormAttributes sets attributes shared by all form items.

func (*TextView) SetLabel

func (t *TextView) SetLabel(label string) *TextView

SetLabel sets the text to be displayed before the text view.

func (*TextView) SetLabelWidth

func (t *TextView) SetLabelWidth(width int) *TextView

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 (*TextView) SetLines

func (t *TextView) SetLines(lines []Line) *TextView

SetLines replaces the content with styled lines.

func (*TextView) SetMaxLines

func (t *TextView) SetMaxLines(maxLines int) *TextView

SetMaxLines sets the maximum number of logical lines for this text view.

func (*TextView) SetScrollable

func (t *TextView) SetScrollable(scrollable bool) *TextView

SetScrollable sets the flag that decides whether or not the text view is scrollable. If false, text that moves above the text view's top row will be permanently deleted.

func (*TextView) SetSize

func (t *TextView) SetSize(rows, columns int) *TextView

SetSize sets the screen size of the main text element of the text view.

func (*TextView) SetText

func (t *TextView) SetText(text string) *TextView

SetText sets the text of this text view to the provided plain string.

func (*TextView) SetTextAlign

func (t *TextView) SetTextAlign(alignment Alignment) *TextView

SetTextAlign sets the text alignment within the text view. This must be either AlignLeft, AlignCenter, or AlignRight.

func (*TextView) SetTextStyle

func (t *TextView) SetTextStyle(style tcell.Style) *TextView

SetTextStyle sets the default style for newly written text.

func (*TextView) SetWordWrap

func (t *TextView) SetWordWrap(wrapOnWords bool) *TextView

SetWordWrap sets the flag that, if true and if the "wrap" flag is also true, wraps according to Unicode line break opportunities.

func (*TextView) SetWrap

func (t *TextView) SetWrap(wrap bool) *TextView

SetWrap sets the flag that, if true, leads to lines that are longer than the available width being wrapped onto the next line. If false, any characters beyond the available width are not displayed.

func (*TextView) Write

func (t *TextView) Write(p []byte) (n int, err error)

Write lets us implement the io.Writer interface.

type TextViewWriter

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

TextViewWriter is a writer that can be used to write to and clear a TextView in batches, i.e. multiple writes with the lock only being acquired once. Don't instantiated this class directly but use the TextView's BatchWriter method instead.

func (TextViewWriter) Clear

func (w TextViewWriter) Clear()

Clear removes all text from the buffer.

func (TextViewWriter) Close

func (w TextViewWriter) Close() error

Close implements io.Closer for the writer by unlocking the original TextView.

func (TextViewWriter) HasFocus

func (w TextViewWriter) HasFocus() bool

HasFocus returns whether the underlying TextView has focus.

func (TextViewWriter) Write

func (w TextViewWriter) Write(p []byte) (n int, err error)

Write implements the io.Writer interface. It behaves like the TextView's Write() method except that it does not acquire the lock.

type Theme

type Theme 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.
}

Theme defines the colors used when primitives are initialized.

type TrackClickBehavior

type TrackClickBehavior uint8

TrackClickBehavior configures behavior when clicking scrollBar track cells outside the thumb.

const (
	TrackClickBehaviorPage TrackClickBehavior = iota
	TrackClickBehaviorJumpToClick
)

type TreeMarkers

type TreeMarkers struct {
	Expanded  string
	Collapsed string
	Leaf      string
}

TreeMarkers are glyphs drawn before node text.

type TreeNode

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

TreeNode represents one node in a tree view.

func NewTreeNode

func NewTreeNode(text string) *TreeNode

NewTreeNode returns a new tree node.

func (*TreeNode) AddChild

func (n *TreeNode) AddChild(node *TreeNode) *TreeNode

AddChild adds a new child node to this node.

func (*TreeNode) ClearChildren

func (n *TreeNode) ClearChildren() *TreeNode

ClearChildren removes all child nodes from this node.

func (*TreeNode) Collapse

func (n *TreeNode) Collapse() *TreeNode

Collapse makes the child nodes of this node disappear.

func (*TreeNode) CollapseAll

func (n *TreeNode) CollapseAll() *TreeNode

CollapseAll collapses this node and all descendent nodes.

func (*TreeNode) Expand

func (n *TreeNode) Expand() *TreeNode

Expand makes the child nodes of this node appear.

func (*TreeNode) ExpandAll

func (n *TreeNode) ExpandAll() *TreeNode

ExpandAll expands this node and all descendent nodes.

func (*TreeNode) GetChildren

func (n *TreeNode) GetChildren() []*TreeNode

GetChildren returns this node's children.

func (*TreeNode) GetLevel

func (n *TreeNode) GetLevel() int

GetLevel returns the node's level within the hierarchy, where 0 corresponds to the root node, 1 corresponds to its children, and so on. This is only guaranteed to be up to date immediately after the tree that contains this node is drawn.

func (*TreeNode) GetLine

func (n *TreeNode) GetLine() Line

GetLine returns the node's styled text line.

func (*TreeNode) GetReference

func (n *TreeNode) GetReference() any

GetReference returns this node's reference object.

func (*TreeNode) GetSelectedTextStyle

func (n *TreeNode) GetSelectedTextStyle() tcell.Style

GetSelectedTextStyle returns the text style for this node when it is selected.

func (*TreeNode) IsExpandable

func (n *TreeNode) IsExpandable() bool

IsExpandable returns whether this node can be expanded even when there are no loaded child nodes yet.

func (*TreeNode) IsExpanded

func (n *TreeNode) IsExpanded() bool

IsExpanded returns whether the child nodes of this node are visible.

func (*TreeNode) RemoveChild

func (n *TreeNode) RemoveChild(node *TreeNode) *TreeNode

RemoveChild removes a child node from this node. If the child node cannot be found, nothing happens.

func (*TreeNode) SetChildren

func (n *TreeNode) SetChildren(childNodes []*TreeNode) *TreeNode

SetChildren sets this node's child nodes.

func (*TreeNode) SetExpandable

func (n *TreeNode) SetExpandable(expandable bool) *TreeNode

SetExpandable sets whether this node can be expanded even when there are no loaded child nodes yet.

func (*TreeNode) SetExpanded

func (n *TreeNode) SetExpanded(expanded bool) *TreeNode

SetExpanded sets whether or not this node's child nodes should be displayed.

func (*TreeNode) SetIndent

func (n *TreeNode) SetIndent(indent int) *TreeNode

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) SetLine

func (n *TreeNode) SetLine(line Line) *TreeNode

SetLine sets the node's styled text line.

func (*TreeNode) SetReference

func (n *TreeNode) SetReference(reference any) *TreeNode

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

func (n *TreeNode) SetSelectable(selectable bool) *TreeNode

SetSelectable sets a flag indicating whether this node can be selected by the user.

func (*TreeNode) SetSelectedFunc

func (n *TreeNode) SetSelectedFunc(handler func()) *TreeNode

SetSelectedFunc sets a function which is called when the user selects this node by hitting Enter when it is selected.

func (*TreeNode) SetSelectedTextStyle

func (n *TreeNode) SetSelectedTextStyle(style tcell.Style) *TreeNode

SetSelectedTextStyle sets the text style for this node when it is selected.

func (*TreeNode) Walk

func (n *TreeNode) Walk(callback func(node, parent *TreeNode) bool) *TreeNode

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 cursor or the tree by using the following keys:

  • j, down arrow, right arrow: Move (the cursor) down by one node.
  • k, up arrow, left arrow: Move (the cursor) up by one node.
  • g, home: Move (the cursor) to the top.
  • G, end: Move (the cursor) to the bottom.
  • J: Move (the cursor) up one level (if that node is selectable).
  • K: Move (the cursor) to the last node one level down (if any).
  • Ctrl-F, page down: Move (the cursor) down by one page.
  • Ctrl-B, page up: Move (the cursor) 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/ayn2op/tview/wiki/TreeView for an example.

func NewTreeView

func NewTreeView() *TreeView

NewTreeView returns a new tree view.

func (*TreeView) Draw

func (t *TreeView) Draw(screen tcell.Screen)

Draw draws this primitive onto the screen.

func (*TreeView) GetCurrentNode

func (t *TreeView) GetCurrentNode() *TreeNode

GetCurrentNode returns the currently selected node or nil of no node is currently selected.

func (*TreeView) GetMarkers

func (t *TreeView) GetMarkers() TreeMarkers

GetMarkers returns the marker strings currently used by this tree view.

func (*TreeView) GetPath

func (t *TreeView) GetPath(node *TreeNode) []*TreeNode

GetPath returns all nodes located on the path from the root to the given node, including the root and the node itself. If there is no root node, nil is returned. If there are multiple paths to the node, a random one is chosen and returned.

func (*TreeView) GetRoot

func (t *TreeView) GetRoot() *TreeNode

GetRoot returns the root node of the tree. If no such node was previously set, nil is returned.

func (*TreeView) GetRowCount

func (t *TreeView) GetRowCount() int

GetRowCount returns the number of "visible" nodes. This includes nodes which fall outside the tree view's box but notably does not include the children of collapsed nodes. Note that this value is only up to date after the tree view has been drawn.

func (*TreeView) GetScrollOffset

func (t *TreeView) GetScrollOffset() int

GetScrollOffset 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.

func (*TreeView) GetSelectedFunc

func (t *TreeView) GetSelectedFunc() func(node *TreeNode)

GetSelectedFunc returns the function set with TreeView.SetSelectedFunc or nil if no such function has been set.

func (*TreeView) HandleEvent

func (t *TreeView) HandleEvent(event tcell.Event) Command

HandleEvent handles input events for this primitive.

func (*TreeView) Move

func (t *TreeView) Move(offset int) *TreeView

Move moves the cursor (if a node is currently selected) or scrolls the tree view (if there is no cursor), by the given offset (positive values to move/scroll down, negative values to move/scroll up). For cursor changes, the offset refers to the number selectable, visible nodes. For scrolling, the offset refers to the number of visible nodes.

If the offset is 0, nothing happens.

func (*TreeView) SetAlign

func (t *TreeView) SetAlign(align bool) *TreeView

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) SetCenterCursor

func (t *TreeView) SetCenterCursor(center bool) *TreeView

SetCenterCursor controls whether the cursor is kept centered whenever possible.

func (*TreeView) SetChangedFunc

func (t *TreeView) SetChangedFunc(handler func(node *TreeNode)) *TreeView

SetChangedFunc sets the function which is called when the currently selected node changes, for example when the user navigates to a new tree node.

func (*TreeView) SetCurrentNode

func (t *TreeView) SetCurrentNode(node *TreeNode) *TreeView

SetCurrentNode sets the currently selected node. Provide nil to clear all cursors. Selected nodes must be visible and selectable, or else the cursor will be changed to the top-most selectable and visible node.

This function does NOT trigger the "changed" callback because the actual node that will be selected is not known until the tree is drawn. Triggering the "changed" callback is thus deferred until the next call to TreeView.Draw.

func (*TreeView) SetDoneFunc

func (t *TreeView) SetDoneFunc(handler func(key tcell.Key)) *TreeView

SetDoneFunc sets a handler which is called whenever the user presses the Escape, Tab, or Backtab key.

func (*TreeView) SetGraphics

func (t *TreeView) SetGraphics(showGraphics bool) *TreeView

SetGraphics sets a flag which determines whether or not line graphics are drawn to illustrate the tree's hierarchy.

func (*TreeView) SetGraphicsColor

func (t *TreeView) SetGraphicsColor(color tcell.Color) *TreeView

SetGraphicsColor sets the colors of the lines used to draw the tree structure.

func (*TreeView) SetMarkers

func (t *TreeView) SetMarkers(markers TreeMarkers) *TreeView

SetMarkers sets the strings drawn before node text depending on node state. Expanded is used for nodes with children whose children are visible, Collapsed is used for nodes with children whose children are hidden, and Leaf is used for nodes without children.

func (*TreeView) SetPrefixes

func (t *TreeView) SetPrefixes(prefixes []string) *TreeView

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 "})

Deeper levels will cycle through the prefixes.

func (*TreeView) SetRoot

func (t *TreeView) SetRoot(root *TreeNode) *TreeView

SetRoot sets the root node of the tree.

func (*TreeView) SetSelectedFunc

func (t *TreeView) SetSelectedFunc(handler func(node *TreeNode)) *TreeView

SetSelectedFunc sets the function which is called when the user selects a node by pressing Enter on the current cursor.

func (*TreeView) SetTopLevel

func (t *TreeView) SetTopLevel(topLevel int) *TreeView

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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