tview

package module
v0.0.0-...-77dc5f1 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 14 Imported by: 2

Documentation

Index

Constants

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 MergeStyle

func MergeStyle(a, b tcell.Style) tcell.Style

MergeStyle layers b on top of a and returns the result, merging every style component. Colors (foreground, background, underline) set on b — i.e. not tcell.ColorDefault — override a's; otherwise a's are kept. The underline style and hyperlink set on b likewise win over a's. Boolean attributes (bold, dim, italic, blink, reverse, strikethrough) are the union of both.

func ModelInRect

func ModelInRect(m Model, x, y int) bool

ModelInRect reports whether x,y is inside m's rectangle.

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 PrintStyled

func PrintStyled(screen tcell.Screen, text string, x, y, skipWidth, maxWidth int, alignment Alignment, style tcell.Style, maintainBackground bool) (start, end, printedWidth int)

PrintStyled works like Print but it takes a style instead of just a foreground color. The skipWidth parameter specifies the number of cells skipped at the beginning of the text. It returns the start index, end index (exclusively), and screen width of the text actually printed. If maintainBackground is "true", the existing screen background is not changed (i.e. the style's background color is ignored).

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 WordWrap

func WordWrap(text string, width int) []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.

func NewApplication

func NewApplication(options ...ApplicationOption) *Application

NewApplication creates and returns a new application.

func (*Application) Focused

func (a *Application) Focused() Model

Focused returns the model which has the current focus. If none has it, nil is returned.

func (*Application) Run

func (a *Application) Run() error

Run starts the application and thus the messages loop.

func (*Application) SetRoot

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

SetRoot sets the root model for this application. This function must be called at least once or nothing will be displayed when the application starts.

func (*Application) Suspend

func (a *Application) Suspend(f func()) bool

Suspend temporarily suspends the application by exiting terminal UI mode and invoking the provided function "f". When "f" returns, terminal UI mode is entered again and the application resumes.

A return value of true indicates that the application was suspended and "f" was called. If false is returned, the application was already suspended, terminal UI mode was not exited, and "f" was not called.

type ApplicationOption

type ApplicationOption func(*Application)

func WithScreen

func WithScreen(screen tcell.Screen) ApplicationOption

func WithoutCatchPanics

func WithoutCatchPanics() ApplicationOption

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 models 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 Model 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 models. 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 models.

func NewBox

func NewBox() *Box

NewBox returns a Box without a border.

func (*Box) BackgroundColor

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

BackgroundColor returns the box's background color.

func (*Box) Blur

func (b *Box) Blur()

Blur is called when this model directly loses focus.

func (*Box) BorderPadding

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

BorderPadding returns the configured border padding.

func (*Box) BorderSet

func (b *Box) BorderSet() BorderSet

BorderSet returns the border set.

func (*Box) Borders

func (b *Box) Borders() Borders

Borders returns the borders.

func (*Box) Focus

func (b *Box) Focus(delegate func(m Model))

Focus is called when this model directly receives focus.

func (*Box) Footer

func (b *Box) Footer() string

Footer returns the box's current footer.

func (*Box) HasFocus

func (b *Box) HasFocus() bool

HasFocus returns whether or not this model 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) InnerRect

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

InnerRect 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) Rect

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

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

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 model loses focus. Container models 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 descendent of the container model.

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 border set.

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

func (b *Box) SetDontClear(dontClear bool) *Box

SetDontClear sets whether drawing should skip clearing the background.

func (*Box) SetFocusFunc

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

SetFocusFunc sets a callback function which is invoked when this model receives focus. Container models 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 model.

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 model. Note that this has no effect if this model 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.

func (*Box) Title

func (b *Box) Title() string

Title returns the box's current title.

func (*Box) Update

func (b *Box) Update(msg Msg) Cmd

func (*Box) View

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

type Button

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

Button is labeled box that triggers an action when selected.

func NewButton

func NewButton(label string) *Button

NewButton returns a new input field.

func (*Button) Disabled

func (b *Button) Disabled() bool

Disabled returns whether or not the button is disabled.

func (*Button) Label

func (b *Button) Label() string

Label returns the button text.

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

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

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

func (*Button) Update

func (b *Button) Update(msg Msg) Cmd

Update handles input events for this model.

func (*Button) View

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

View draws this model onto the screen.

type ButtonExitMsg

type ButtonExitMsg struct {
	tcell.Key
}

type ButtonSelectedMsg

type ButtonSelectedMsg struct {
	Label string
}

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.

func NewCheckbox

func NewCheckbox() *Checkbox

NewCheckbox returns a new input field.

func (*Checkbox) Checked

func (c *Checkbox) Checked() bool

Checked returns whether or not the box is checked.

func (*Checkbox) Disabled

func (c *Checkbox) Disabled() bool

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

func (*Checkbox) Focus

func (c *Checkbox) Focus(delegate func(m Model))

Focus is called when this model receives focus.

func (*Checkbox) GetFieldHeight

func (c *Checkbox) GetFieldHeight() int

GetFieldHeight returns this model's field height.

func (*Checkbox) GetFieldWidth

func (c *Checkbox) GetFieldWidth() int

GetFieldWidth returns this model's field width.

func (*Checkbox) Label

func (c *Checkbox) Label() string

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

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

func (*Checkbox) Update

func (c *Checkbox) Update(msg Msg) Cmd

Update handles input events for this model.

func (*Checkbox) View

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

View draws this model onto the screen.

type Cmd

type Cmd func() Msg

Cmd is a side effect requested by a model during input handling.

func Batch

func Batch(cmds ...Cmd) Cmd

Batch combines multiple commands into a single command.

func GetClipboard

func GetClipboard() Cmd

func Notify

func Notify(title, body string) Cmd

func Quit

func Quit() Cmd

func Raw

func Raw(r any) Cmd

Raw is a command that writes the data to the underlying TTY without any formatting.

func Sequence

func Sequence(cmds ...Cmd) Cmd

Sequence executes commands one at a time, in order.

func SetClipboard

func SetClipboard(data []byte) Cmd

func SetFocus

func SetFocus(target Model) Cmd

func SetMouseCapture

func SetMouseCapture(target Model) Cmd

func SetTitle

func SetTitle(title string) Cmd

type FocusMsg

type FocusMsg = *tcell.EventFocus

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

func NewForm

func NewForm() *Form

NewForm returns a new form.

func (*Form) AddButton

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

AddButton adds a new button to the form.

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) *Form

AddInputField adds an input field to the form. It has a label, an optional initial value, and a field width (a value of 0 extends it as far as possible). Handle InputFieldChangedMsg to react to text changes.

func (*Form) AddPasswordField

func (f *Form) AddPasswordField(label, value string, fieldWidth int, mask rune) *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 a mask character. Handle InputFieldChangedMsg to react to text changes.

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 model (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) Focus

func (f *Form) Focus(delegate func(m Model))

Focus is called by the application when the model 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) HasFocus

func (f *Form) HasFocus() bool

HasFocus returns whether or not this model 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) 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.

func (*Form) Update

func (f *Form) Update(msg Msg) Cmd

Update handles input events for this model.

func (*Form) View

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

View draws this model onto the screen.

type FormCancelMsg

type FormCancelMsg struct{}

type FormItem

type FormItem interface {
	Model

	// Label returns the item's label text.
	Label() 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

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

FormItem is the interface all form items must implement to be able to be included in a form.

type FormSubmitMsg

type FormSubmitMsg struct {
	ButtonIndex int
	ButtonLabel string
}

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 InitMsg

type InitMsg struct{}

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 and InputField.SetMaskCharacter to hide input from onlookers (e.g. for password input). Handle InputFieldChangedMsg to react to text changes.

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.

func NewInputField

func NewInputField() *InputField

NewInputField returns a new input field.

func (*InputField) Blur

func (i *InputField) Blur()

Blur is called when this model loses focus.

func (*InputField) Disabled

func (i *InputField) Disabled() bool

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

func (*InputField) FieldStyle

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

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

func (*InputField) FieldWidth

func (i *InputField) FieldWidth() int

FieldWidth returns this model's field width.

func (*InputField) Focus

func (i *InputField) Focus(delegate func(m Model))

Focus is called when this model receives focus.

func (*InputField) GetFieldHeight

func (i *InputField) GetFieldHeight() int

GetFieldHeight returns this model's field height.

func (*InputField) GetFieldWidth

func (i *InputField) GetFieldWidth() int

GetFieldWidth implements FormItem.

func (*InputField) HasFocus

func (i *InputField) HasFocus() bool

HasFocus returns whether or not this model has focus.

func (*InputField) Label

func (i *InputField) Label() string

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

func (*InputField) LabelStyle

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

LabelStyle returns the style of the label.

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 represents 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. It does not emit InputFieldChangedMsg; only user edits do.

func (*InputField) Text

func (i *InputField) Text() string

Text returns the current text of the input field.

func (*InputField) Update

func (i *InputField) Update(msg Msg) Cmd

Update handles input events for this model.

func (*InputField) View

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

View draws this model onto the screen.

type InputFieldChangedMsg

type InputFieldChangedMsg struct {
	// Text is the field's text after the change.
	Text string
}

InputFieldChangedMsg is emitted by an InputField when its text changes in response to user input.

type KeyMsg

type KeyMsg = *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.

func (*LineBuilder) WriteAll

func (b *LineBuilder) WriteAll(style tcell.Style, list ...any)

WriteAll is just like [Write] but takes a list of strings/segments. All strings will have the same style as the first argument. Unknown types will be discarded.

type Model

type Model interface {
	// Update receives messages when this model has focus.
	Update(Msg) Cmd
	// View draws this model onto the screen.
	View(tcell.Screen)

	// Rect returns the current position of the model, x, y, width, and
	// height.
	Rect() (int, int, int, int)
	// SetRect sets a new position of the model.
	SetRect(x, y, width, height int)

	// HasFocus determines if the model has focus. This function must return
	// true also if one of this model's child elements has focus.
	HasFocus() bool
	// Focus is called by the application when the model receives focus.
	// Implementers may call delegate() to pass the focus on to another model.
	Focus(delegate func(Model))
	// Blur is called by the application when the model loses focus.
	Blur()
}

Model is the top-most interface for all graphical models.

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 MouseMsg

type MouseMsg struct {
	*tcell.EventMouse
	Action MouseAction
}

type Msg

type Msg any

type PasteMsg

type PasteMsg string

type ResizeMsg

type ResizeMsg = *tcell.EventResize

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

func (s *ScrollBar) HasEndArrow() bool

HasEndArrow reports whether an end arrow is rendered.

func (*ScrollBar) HasStartArrow

func (s *ScrollBar) HasStartArrow() bool

HasStartArrow reports whether a start arrow is rendered.

func (*ScrollBar) ScrollStep

func (s *ScrollBar) ScrollStep() int

ScrollStep returns scroll step used by wheel and arrow interactions.

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.

func (*ScrollBar) TrackClickBehavior

func (s *ScrollBar) TrackClickBehavior() TrackClickBehavior

TrackClickBehavior returns behavior used for track clicks.

func (*ScrollBar) TrackLengthExcludingArrowHeads

func (s *ScrollBar) TrackLengthExcludingArrowHeads(length int) int

TrackLengthExcludingArrowHeads returns track length excluding arrow cells.

func (*ScrollBar) View

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

View draws the scrollBar.

type ScrollBarArrows

type ScrollBarArrows uint8

ScrollBarArrows controls which endcaps are rendered.

const (
	ScrollBarArrowsNone ScrollBarArrows = iota
	ScrollBarArrowsStart
	ScrollBarArrowsEnd
	ScrollBarArrowsBoth
)

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 Style

type Style = tcell.Style

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 model's Update 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) Disabled

func (t *TextArea) Disabled() bool

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

func (*TextArea) Focus

func (t *TextArea) Focus(delegate func(m Model))

Focus is called when this model 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) GetFieldHeight

func (t *TextArea) GetFieldHeight() int

GetFieldHeight returns this model's field height.

func (*TextArea) GetFieldWidth

func (t *TextArea) GetFieldWidth() int

GetFieldWidth returns this model's field width.

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

func (t *TextArea) GetTextLength() int

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

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

func (t *TextArea) HasSelection() bool

HasSelection returns whether the selected text is non-empty.

func (*TextArea) Label

func (t *TextArea) Label() string

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

func (*TextArea) LabelStyle

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

LabelStyle returns the style of the label.

func (*TextArea) LabelWidth

func (t *TextArea) LabelWidth() int

LabelWidth returns the screen width of the label.

func (*TextArea) LineCount

func (t *TextArea) LineCount(limit int) int

LineCount returns the number of visual lines, honoring the current wrap settings and last drawn width. Returns at least 1.

If limit > 0, scanning stops once more than limit lines are found and the result is capped at limit+1 (so the caller can detect overflow in O(limit) work). Pass limit <= 0 for the exact count.

If the text area hasn't been drawn yet (no known width), only explicit newlines are counted.

func (*TextArea) Offset

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

Offset 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) 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 model 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) SetVisibleSize

func (t *TextArea) SetVisibleSize(width, height int)

SetVisibleSize sets the inner width and/or height used for cursor clamping and scroll math before the next draw. Pass 0 (or negative) for a dimension to leave it unchanged.

Needed when the caller resizes the text area externally on a text change (e.g. an auto-growing input): otherwise scroll updates on the same keystroke would use stale dimensions.

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.

func (*TextArea) Text

func (t *TextArea) Text() string

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

func (*TextArea) TextStyle

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

TextStyle returns the style of the text.

func (*TextArea) Update

func (t *TextArea) Update(msg Msg) Cmd

Update handles input events for this model.

func (*TextArea) View

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

View draws this model onto the screen.

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

func (t *TextView) Disabled() bool

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

func (*TextView) Focus

func (t *TextView) Focus(delegate func(m Model))

Focus is called when this model receives focus.

func (*TextView) GetFieldHeight

func (t *TextView) GetFieldHeight() int

GetFieldHeight returns this model's field height.

func (*TextView) GetFieldWidth

func (t *TextView) GetFieldWidth() int

GetFieldWidth returns this model's field width.

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

func (t *TextView) GetWrappedLineCount() int

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

func (*TextView) HasFocus

func (t *TextView) HasFocus() bool

HasFocus returns whether or not this model 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) Label

func (t *TextView) Label() string

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

func (*TextView) Lines

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

Lines returns a copy of the styled content.

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

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 model 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) Text

func (t *TextView) Text() string

Text returns the current plain text of this text view.

func (*TextView) Update

func (t *TextView) Update(msg Msg) Cmd

Update handles input events for this model.

func (*TextView) View

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

View draws this model onto the screen.

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 models.
	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 models are initialized.

type TrackClickBehavior

type TrackClickBehavior uint8

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

const (
	TrackClickBehaviorPage TrackClickBehavior = iota
	TrackClickBehaviorJumpToClick
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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