ui

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package ui holds hive's shared UI descriptions — data that both the TUI and the WUI render from, so a single edit propagates to both frontends. See CLAUDE.md § Shared UI descriptions for the design intent.

The keymap lives here rather than in internal/tui so the HTTP layer can serve it via GET /api/keymap without pulling in Bubble Tea types.

Index

Constants

View Source
const (
	// FrontendTUI — the Bubble Tea terminal frontend. Key strings
	// use Bubble Tea's notation ("up", "esc", "alt+t").
	FrontendTUI = "tui"
	// FrontendWUI — the browser-hosted web user interface (the Lit
	// app under internal/wui/dist). Key strings use KeyboardEvent.key values
	// with a "modifier+" prefix convention matching Bubble Tea
	// ("ArrowUp", "Escape", "alt+t") so both frontends can share the
	// same parsing convention. The "WUI" spelling is deliberately
	// symmetric with TUI: hive calls its frontends by their medium
	// (terminal / web) rather than by implementation detail (Bubble
	// Tea / Lit). See CLAUDE.md for the reasoning; the app directory
	// still lives at web/ pending a wider rename.
	FrontendWUI = "wui"
)

Frontend target identifiers used as keys in Shortcut.Keys.

Variables

This section is empty.

Functions

func TUIKeysFor

func TUIKeysFor(action string) []string

TUIKeysFor returns the TUI key strings for the given action, or nil if the action has no TUI binding. Convenience wrapper used by the TUI's Bubble Tea keymap construction.

Types

type ChildRank

type ChildRank struct {
	ID         string `json:"id"`
	TypicalUse bool   `json:"typical_use"`
}

ChildRank is one entry in the child-rank list returned to callers. TypicalUse pairs with a picker-side "show all" affordance: default display shows only typical ranks; a curator can widen via search or an explicit toggle to see everything else.

func ValidChildRanks

func ValidChildRanks(codeSfga, parentRankID string) []ChildRank

ValidChildRanks returns the rank IDs valid as children of a taxon whose rank is parentRankID under the given nomenclatural code (sfga's nom_code value — ZOOLOGICAL / BOTANICAL / BACTERIAL / VIRUS). Each returned entry carries a typical_use flag so the picker can default to the common set and reveal the rest via search or an explicit "show all" affordance.

Filter combines:

  1. Group-level truncation (TW's truncateAtRank + isMajor): exclude groups above the parent's group; within the parent's own group exclude ranks at or above the parent's position.
  2. valid_parents_override enforcement: a rank with an explicit override list is only valid under those parents, regardless of the group-truncation result (e.g. subspecies is offered under species but not under genus).

Empty codeSfga, unmapped code, or an unresolvable parent rank all return nil, signaling "no filter" — callers show every rank in the vocab. Empty parentRankID (root-taxon create) returns every rank under the code, all marked typical_use per their own row.

type Scope

type Scope string

Scope identifies which pane / focus context a shortcut is active under. The help modal groups shortcuts by scope so curators can see at a glance which pane a binding needs focus on.

const (
	// ScopeGlobal — binding fires from anywhere. Reserved for keys
	// with clear, non-surprising intent (view switch, search focus,
	// help). See PARITY.md § Focus semantics.
	ScopeGlobal Scope = "global"
	// ScopeTree — binding fires only when the taxon tree has focus.
	ScopeTree Scope = "tree"
	// ScopeDetail — binding fires from the taxon detail pane in
	// view mode (edit, new, delete).
	ScopeDetail Scope = "detail"
	// ScopeForm — binding fires inside an edit form (save, cancel,
	// modal-open shortcuts).
	ScopeForm Scope = "form"
)

type Shortcut

type Shortcut struct {
	Action      string              `json:"action"`
	Description string              `json:"description"`
	Display     string              `json:"display"`
	Scope       Scope               `json:"scope"`
	Keys        map[string][]string `json:"keys"`
}

Shortcut describes one keyboard binding. Populated once in Keymap() and consumed by both TUI keymap construction and the WUI via the /api/keymap endpoint.

Keys is a per-frontend map. Absence of a frontend key means the binding is not available there — used for browser-preempted combinations (Ctrl+S/A/O), TUI-only affordances (Tab, :, q), and WUI-only affordances (? for help).

func ForFrontend

func ForFrontend(frontend string) []Shortcut

ForFrontend returns the subset of Keymap() available in the given frontend (FrontendTUI or FrontendWUI). Both frontends' help renderers use this to filter — a curator using the WUI shouldn't be shown TUI-only bindings that can't fire in the browser.

func Keymap

func Keymap() []Shortcut

Keymap returns the canonical hive keymap. Slice order is the display order for the help modal within each scope; scope grouping is done by the renderer.

Jump to

Keyboard shortcuts

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