From 60fe055ab56335924083d00e030ff43cca128574 Mon Sep 17 00:00:00 2001 From: Jakub Sobon Date: Sun, 24 Feb 2019 17:46:55 -0500 Subject: [PATCH] Updated Termbox API (markdown) --- Termbox-API.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Termbox-API.md b/Termbox-API.md index ae8ec5d..1d1b0be 100644 --- a/Termbox-API.md +++ b/Termbox-API.md @@ -2,7 +2,7 @@ [![Doc Status](https://godoc.org/github.com/mum4k/termdash/terminal/termbox?status.png)](https://godoc.org/github.com/mum4k/termdash/terminal/termbox) -The [termbox](https://github.com/mum4k/termdash/tree/master/terminal/termbox) package is a shim layer over the [termbox-go](https://github.com/nsf/termbox-go) library that provides cell based access to the terminal. +The [termbox](https://github.com/mum4k/termdash/tree/master/terminal/termbox) package implements the [[Terminal API|terminal-api]] using the [termbox-go](https://github.com/nsf/termbox-go). Termbox provides cell based access to the terminal. The public API surface of this package consists of the following: @@ -23,7 +23,7 @@ This interface is used to provide optional arguments to **New**. ### [termbox.ColorMode](https://github.com/mum4k/termdash/blob/614d6ed82014e343ca40f25ee1bed8dfbd452830/terminal/termbox/termbox.go#L45-L51) -Used to set the color mode in which the terminal will be initialised. The available color modes are documented in the [[Terminal API|terminal-api]]. The following example sets the color mode to support 256 colors. +Used to set the color mode in which the terminal will be initialised. The available color modes are documented in the [[Terminal API|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|cell-api]] for an explanation of terminal colors. ```go tb, err := termbox.New(termbox.ColorMode(terminalapi.ColorMode256)) @@ -34,4 +34,12 @@ if err != nil { ## [termbox.Close](https://github.com/mum4k/termdash/blob/ffbf88caeddb1735dcf2a5f735eec80dc9cf9fe7/terminal/termbox/termbox.go#L158-L164) -This function should be used to close the terminal and return it to a sane state once the Termbox instance isn't needed anymore. \ No newline at end of file +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: + +```go +tb, err := termbox.New(termbox.ColorMode(terminalapi.ColorMode256)) +if err != nil { + return fmt.Errorf("termbox.New => %v", err) +} +defer tb.Close() +```