From 58effb3de24bc02f98e3e732c3225d2f04aa9d2c Mon Sep 17 00:00:00 2001 From: Jakub Sobon Date: Sun, 24 Feb 2019 18:08:40 -0500 Subject: [PATCH] Updated Termdash API (markdown) --- Termdash-API.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Termdash-API.md b/Termdash-API.md index 9d7273c..06fcaf9 100644 --- a/Termdash-API.md +++ b/Termdash-API.md @@ -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() ``` \ No newline at end of file