Skip to content
Jakub Sobon edited this page Nov 14, 2020 · 10 revisions

Doc Status

The termbox package implements the Terminal API using the termbox-go. Termbox provides cell based access to the terminal.

Prefer to use Tcell API instead, nsf/termbox-go is no longer maintained.

The public API surface of this package consists of the following:

Users of Termdash need to provide Termdash API with a terminal instance. Termbox is one of the valid options. Use the New function to create a Terminal instance.

tb, err := termbox.New()
if err != nil {
  return fmt.Errorf("termbox.New => %v", err)
}

This interface is used to provide optional arguments to New.

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, Termbox is initialised in a color mode that supports all 256 terminal colors. Refer to the Cell API for an explanation of terminal colors.

tb, err := termbox.New(termbox.ColorMode(terminalapi.ColorModeGrayscale))
if err != nil {
  return fmt.Errorf("termbox.New => %v", err)
}

This function should be used to close the terminal and return it to a sane state once the Termbox instance isn't needed anymore. A good practice is to defer the call right after Termbox instance is created:

tb, err := termbox.New()
if err != nil {
  return fmt.Errorf("termbox.New => %v", err)
}
defer tb.Close()
Clone this wiki locally