mirror of https://github.com/mum4k/termdash.git
Updated Termdash API (markdown)
parent
c95b0388ab
commit
b24ebfa1f4
|
@ -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)
|
||||
}
|
||||
```
|
Loading…
Reference in New Issue