Documentation
¶
Overview ¶
Package errorretry is a small interactive widget for showing an error with a retry/dismiss keybinding — Enter or 'r' retries (up to MaxRetries), Esc always dismisses.
Stability: experimental. Its API may change in any minor release.
Example ¶
Enter asks for a retry until the allowed number is used up.
package main
import (
"fmt"
"github.com/ows4444/tui"
"github.com/ows4444/tui/errorretry"
)
func main() {
m := errorretry.New("request failed", 1)
m, cmd := m.Update(tui.Key{Type: tui.KeyEnter})
fmt.Printf("%T %d %v\n", cmd(), m.RetryCount(), m.Exhausted())
}
Output: errorretry.RetryMsg 1 true
Index ¶
- type DismissedMsg
- type KeyMap
- type Model
- func (m Model) Bindings() []keymap.Binding
- func (m Model) Exhausted() bool
- func (m Model) LayoutNode() layout.Node
- func (m Model) Linearize() string
- func (m Model) RetryCount() int
- func (m Model) SetTheme(t theme.Theme) Model
- func (m Model) Tokens() theme.Tokens
- func (m Model) Update(msg tui.Msg) (Model, tui.Cmd)
- func (m Model) View() string
- func (m Model) WithTokens(tok theme.Tokens) Model
- type RetryMsg
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DismissedMsg ¶
type DismissedMsg struct{}
DismissedMsg is delivered (via the Cmd Update returns) when the user dismisses the error with Esc.
type KeyMap ¶
type KeyMap struct {
Retry keymap.Binding // request a retry while retries remain
Dismiss keymap.Binding // dismiss the error
}
KeyMap names the keys of each action of a Model.
func DefaultKeyMap ¶
func DefaultKeyMap() KeyMap
DefaultKeyMap returns the keys a Model used before KeyMap existed.
type Model ¶
type Model struct {
Message string
MaxRetries int
Theme theme.Theme
// KeyMap holds the keys for each action. New fills it with
// DefaultKeyMap; a Model built as a struct literal with a zero KeyMap
// behaves as if it held DefaultKeyMap. The hint line View draws names the
// default keys.
KeyMap KeyMap
// Mouse, when true, makes Update handle tui.MouseEvent: a left click on the
// "retry" part of the hint line retries and on the "dismiss" part dismisses,
// as the keys would. Off (the default) ignores the mouse.
Mouse bool
// Bounds is the screen rectangle where the app draws the widget (its first
// row is the first line of Message); clicks outside it are ignored.
Bounds hittest.Rect
// contains filtered or unexported fields
}
Model shows an error Message and lets the user retry (Enter or 'r', up to MaxRetries times) or dismiss (Esc). Retrying past MaxRetries is a no-op; Esc always works regardless of retryCount.
func (Model) Bindings ¶
Bindings returns the actions the widget currently honours, with descriptions, for help text. Retry is left out once retries are exhausted.
func (Model) Exhausted ¶
Exhausted reports whether retries have been used up — further Enter/'r' presses are a no-op once true.
func (Model) LayoutNode ¶
LayoutNode adapts the error to a layout.Node: the message and the hint beneath it each word-wrap to the allotted width, keeping their styles. The Model is not changed.
func (Model) Linearize ¶
Linearize renders the error as plain text for accessible output (see tui.Linearizer): the message, how many retries have been used, and the keys that are available, e.g. "Error: connection lost", "Retries used: 1 of 3", "Press Enter or r to retry, Escape to dismiss".
func (Model) RetryCount ¶
RetryCount reports how many retries have been requested so far.
func (Model) SetTheme ¶
SetTheme returns m with t applied. It makes Model a tui.ThemeSetter, so a root model can forward the Program's theme (see tui.WithTheme).
func (Model) Tokens ¶
Tokens returns the colour tokens the widget renders with: its theme's roles, overridden by any theme.WithTokens(theme.ComponentErrorRetry, ...) and then by WithTokens.
func (Model) Update ¶
Update handles Enter/'r' (retry, while retryCount < MaxRetries) and Esc (dismiss, always). Any other Msg, or Enter/'r' once retries are exhausted, is a no-op. With Mouse on, a left click on the retry or dismiss part of the hint line does the same as the key.