helpscreen

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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(&reg, "")
	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

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

func FromKeymap(reg *keymap.Registry, scope string) Model

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

func FromRegistry(r *keymap.Registry, scope string) Model

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

func New(hints ...widgets.Hint) Model

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

func (m Model) LayoutNode() layout.Node

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

func (m Model) Linearize() string

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) Open

func (m Model) Open() bool

Open reports whether the help screen is currently shown.

func (Model) Render

func (m Model) Render(base string) string

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

func (m Model) SetTheme(t theme.Theme) Model

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) Show

func (m *Model) Show()

Show opens the help screen.

func (Model) Tokens

func (m Model) Tokens() theme.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.

func (Model) Update

func (m Model) Update(msg tui.Msg) (Model, tui.Cmd)

Update dismisses the help screen on Enter or Esc while open; it's a no-op (including for Enter/Esc) once closed, so a parent doesn't need to guard forwarding to it on Model.Open(). With Mouse on, a left click outside Bounds dismisses it too.

func (Model) WithTokens

func (m Model) WithTokens(tok theme.Tokens) Model

WithTokens returns m with tok as its per-instance colour override. Nil fields inherit from the theme, so only the roles tok names change; the theme and every other widget are untouched. A second call replaces the first.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL