mirror of https://github.com/mum4k/termdash.git
Updated Termdash API (markdown)
parent
5194a5a218
commit
58effb3de2
|
@ -94,4 +94,31 @@ defer ctrl.Close()
|
|||
if err := ctrl.Redraw(); err != nil {
|
||||
return fmt.Errorf("ctrl.Redraw => %v", err)
|
||||
}
|
||||
```
|
||||
|
||||
## [termdash.ErrorHandler](https://github.com/mum4k/termdash/blob/1c6947618b08ae236959763efd07278be5f03211/termdash.go#L64-L71):
|
||||
|
||||
The **termdash.ErrorHandler** function is used to provide a custom error handler. If not provided, the application will panic on all runtime errors. An error handler is a function that receives the error and decides what to do. This function must be thread-safe, since Termdash delivers events concurrently.
|
||||
|
||||
The following example shows initialisation of Termdash with an error handler that just logs the error message:
|
||||
|
||||
```go
|
||||
// Create context ctx, terminal t and container c as in the examples above.
|
||||
|
||||
// An error handler that just logs the error.
|
||||
eh := func(err error) {
|
||||
log.Printf("Termdash runtime error: %v", err)
|
||||
}
|
||||
|
||||
// When running Termdash via the Run function.
|
||||
if err := termdash.Run(ctx, t, c, termdash.ErrorHandler(eh)); err != nil {
|
||||
return fmt.Errorf("termdash.Run => %v", err)
|
||||
}
|
||||
|
||||
// When running Termdash via the Controller type.
|
||||
ctrl, err := termdash.NewController(t, c, termdash.ErrorHandler(eh))
|
||||
if err != nil {
|
||||
return fmt.Errorf("termdash.NewController => %v", err)
|
||||
}
|
||||
defer ctrl.Close()
|
||||
```
|
Loading…
Reference in New Issue