Documentation
¶
Overview ¶
Package helpscreen is a full-screen key-binding help overlay: a bordered box listing widgets.Hint entries one per line via widgets.KeyHint, unlike widgets.KeyHints which joins them into a single line. Its open/dismiss lifecycle mirrors dialog.Model exactly, the same contract popover.Model already reuses.
Example ¶
A helpscreen lists a registry's bindings as an overlay on the screen.
package main
import (
"fmt"
"strings"
"github.com/ows4444/tui/ansi"
"github.com/ows4444/tui/helpscreen"
"github.com/ows4444/tui/keymap"
)
func main() {
var reg keymap.Registry
reg.Add(keymap.NewBinding("quit", "q"))
m := helpscreen.FromRegistry(®, "")
m.Show()
base := strings.TrimRight(strings.Repeat(strings.Repeat(" ", 30)+"\n", 8), "\n")
out := ansi.StripANSI(m.Render(base))
fmt.Println(m.Open(), strings.Contains(out, "quit"))
}
Output: true true
Index ¶
- type DismissedMsg
- type Model
- func (m *Model) Hide()
- func (m Model) LayoutNode() layout.Node
- func (m Model) Linearize() string
- func (m Model) Open() bool
- func (m Model) Render(base string) string
- func (m Model) SetTheme(t theme.Theme) Model
- func (m *Model) Show()
- func (m Model) Tokens() theme.Tokens
- func (m Model) Update(msg tui.Msg) (Model, tui.Cmd)
- func (m Model) WithTokens(tok theme.Tokens) Model
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 help screen is dismissed with Enter or Esc.
type Model ¶
type Model struct {
// Hints is the list of key bindings shown, one per line, via
// widgets.KeyHint.
Hints []widgets.Hint
Theme theme.Theme
// Mouse, when true, makes Update handle tui.MouseEvent: a left click
// outside Bounds dismisses the screen, as Esc does; other mouse events are
// swallowed while it is open. Off (the default) ignores the mouse. There is
// no wheel handling: the screen does not scroll.
Mouse bool
// Bounds is the screen rectangle the help box occupies (top-left at the
// origin, as many columns as the base view, Hints plus 4 rows). A click
// inside it does nothing; with a zero Bounds every click dismisses.
Bounds hittest.Rect
// contains filtered or unexported fields
}
Model is a full-width help overlay. Render composites it over a base view when open; when closed, Render returns base unchanged, so a parent can unconditionally call it every frame without checking Open itself.
func FromKeymap ¶
FromKeymap returns an already-open Model listing the bindings of scope in reg, so the help screen reads the same registry as the key-hint widget.
func FromRegistry ¶
FromRegistry returns an open Model listing the bindings r holds in scope ("" is the default scope widgets register in), one hint per binding with its keys joined by "/". Pass tui.Program.Keymap() so the screen shows the keys the focused widget actually honours, including any the app rebound through the widget's KeyMap; build it again when the screen is opened (not once at start-up) and it follows the focus and the rebinding with no other code.
func New ¶
New returns an already-open Model listing hints — the common case is showing help immediately in response to some trigger, not constructing one ahead of time and opening it later (though Show/Hide support that too).
func (*Model) Hide ¶
func (m *Model) Hide()
Hide closes the help screen without dismissing it via Update (no DismissedMsg is sent).
func (Model) LayoutNode ¶
LayoutNode returns the help box as an ordinary layout.Node: one row per key binding inside a bordered box, cut to the size it is given. While the screen is closed it measures as nothing and renders blank. The Model is not changed.
func (Model) Linearize ¶
Linearize renders the help as plain text for accessible output (see tui.Linearizer): "Help, N key bindings" and one "Key: <key>, <action>" line per binding, or "" while it is closed.
func (Model) Render ¶
Render composites the help screen, spanning the full width of base, at its top-left corner. If the help screen is closed, it returns base unchanged.
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.ComponentHelpScreen, ...) and then by WithTokens.