Table of Contents
The tcell package implements the Terminal API using the tcell library. Tcell provides cell based access to the terminal.
The public API surface of this package consists of the following:
tcell.New
Users of Termdash need to provide Termdash API with a terminal instance. Tcell is one of the valid options. Use the New function to create a Terminal instance.
t, err := tcell.New()
if err != nil {
return fmt.Errorf("tcell.New => %v", err)
}
tcell.Option
This interface is used to provide optional arguments to New.
tcell.ColorMode
Used to set the color mode in which the terminal will be initialised. The available color modes are documented in the Terminal API. The following example sets the color mode to grayscale. Note that when no options are provided, Tcell is initialised in a color mode that supports all 256 terminal colors. Refer to the Cell API for an explanation of terminal colors.
t, err := tcell.New(tcell.ColorMode(terminalapi.ColorModeGrayscale))
if err != nil {
return fmt.Errorf("tcell.New => %v", err)
}
tcell.ClearStyle
Used to set the foreground and background color style to use when the screen is cleared. The following example sets the clear style to a yellow foreground and blue background. Note that when no options are provided, by default the foreground and background clear style is set to cell.ColorDefault
which will use whatever default foreground and background colors are associated with the terminal emulator (typically white and black). Refer to the Cell API for an explanation of terminal colors.
t, err := tcell.New(tcell.ClearStyle(cell.ColorYellow, cell.ColorBlue))
if err != nil {
return fmt.Errorf("tcell.New => %v", err)
}
tcell.Close
This function should be used to close the terminal and return it to a sane state once the Tcell instance isn't needed anymore. A good practice is to defer the call right after the Tcell instance is created:
t, err := tcell.New()
if err != nil {
return fmt.Errorf("tcell.New => %v", err)
}
defer tb.Close()
Help
API Documentation
Terminal layer
Infrastructure layer
Container layer
Widgets layer
Tips and tricks
See a typo, something missing or outright wrong? Feel free to edit the Wiki pages directly, alternatively talk to us.