diff --git a/Termdash-API.md b/Termdash-API.md index c6ab767..f44af6d 100644 --- a/Termdash-API.md +++ b/Termdash-API.md @@ -11,10 +11,30 @@ The [termdash](https://github.com/mum4k/termdash/blob/master/termdash.go) packag The public API surface of this package consists of the following: -## [Run](https://github.com/mum4k/termdash/blob/c861ecef303ac648f926597f28c9f44994a1ca8b/termdash.go#L91-L103) function: +## [termdash.Run](https://github.com/mum4k/termdash/blob/c861ecef303ac648f926597f28c9f44994a1ca8b/termdash.go#L91-L103): -The **Run** function provides the simplest way to run a Termdash based application. +The **Run** function provides the simplest way to run a Termdash based application. Run blocks until the provided context expires, therefore we need a trigger to close the context, e.g. a keyboard shortcut or a timeout. When Termdash is started using this function, the screen is redrawn periodically. + +The following code snippet starts Termdash with an empty container and no widgets. Termdash will quit after 5 seconds when the context expires. ```go +// Create the terminal. +t, err := termbox.New() +if err != nil { + fmt.Errorf("termbox.New => %v", err) +} +defer t.Close() +// Create the container without widgets. +c, err := container.New(t) +if err != nil { + fmt.Errorf("termbox.New => %v", err) +} + +// Termdash runs until the context expires. +ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) +defer cancel() +if err := Run(ctx, t, c); err != nil { + panic(err) +} ``` \ No newline at end of file