Documentation
¶
Overview ¶
Package gui hosts the pgsavvy TUI's focus-stack manager and (in later epics) the bootstrap that wires gocui to the Contexts declared in pkg/gui/context.
Index ¶
- Variables
- type ContextTree
- func (t *ContextTree) Current() types.IBaseContext
- func (t *ContextTree) CurrentKind() types.ContextKind
- func (t *ContextTree) Pop() error
- func (t *ContextTree) PopIfTop(key types.ContextKey) error
- func (t *ContextTree) Push(c types.IBaseContext) error
- func (t *ContextTree) RegisterSwapHook(fn func())
- func (t *ContextTree) Replace(c types.IBaseContext) error
- func (t *ContextTree) SetSessionLog(l *slog.Logger)
- func (t *ContextTree) Stack() []types.IBaseContext
- func (t *ContextTree) TakeEvictedMain() types.IBaseContext
Constants ¶
This section is empty.
Variables ¶
var ErrPopAtBottom = errors.New("gui: cannot pop the root context")
ErrPopAtBottom is returned by ContextTree.Pop when the stack contains a single context (the root cannot be popped).
Functions ¶
This section is empty.
Types ¶
type ContextTree ¶
type ContextTree struct {
// contains filtered or unexported fields
}
ContextTree serializes stack access with an internal mutex: mutations (Push/Pop/Replace) happen on the MainLoop, but background goroutines (the spinner drain reading Current via promptOnTop) race them, and test drivers execute Update callbacks inline on the calling goroutine. Lifecycle hooks (HandleFocus/HandleFocusLost) and swap hooks always run AFTER the mutex is released — they may re-enter the tree (e.g. the result-tabs swap hook calls Current).
Push/Pop/Replace semantics mirror DESIGN.md §8 lines 596-604:
- Pushing a SIDE_CONTEXT wipes the stack and installs the new context as root.
- Pushing a MAIN_CONTEXT removes any existing MAIN_CONTEXT from the stack before pushing on top (popups above main are preserved).
- Pushing a TEMPORARY_POPUP first pops a top-of-stack TEMPORARY_POPUP if present.
- Pushing PERSISTENT_POPUP, EXTRAS_CONTEXT, GLOBAL_CONTEXT, or DISPLAY_CONTEXT just appends without disturbing the rest of the stack.
- Pushing the same key already on top is a no-op (no lifecycle hooks fire).
- Replace swaps the top entry without firing pop/push lifecycle hooks.
SwapHooks are functions invoked by Push/Pop/Replace whenever the stack composition changes (specifically: after a successful Push that did not short-circuit on duplicate-top, after Pop, and after Replace). Hooks receive no arguments and are intended for cross-cutting cancellation concerns (e.g. keys.OneshotArm cancels any pending arm on context switch). Keeps the OneshotArm cancel path simple without polling on every keypress.
func NewContextTree ¶
func NewContextTree() *ContextTree
NewContextTree returns an empty ContextTree. Callers are expected to Push a root context immediately; Pop refuses to drop the final entry.
func (*ContextTree) Current ¶
func (t *ContextTree) Current() types.IBaseContext
Current returns the top context, or nil if the stack is empty.
func (*ContextTree) CurrentKind ¶
func (t *ContextTree) CurrentKind() types.ContextKind
CurrentKind returns the top context's kind. The zero value (SIDE_CONTEXT) is returned when the stack is empty; callers needing to distinguish must consult Current().
func (*ContextTree) Pop ¶
func (t *ContextTree) Pop() error
Pop removes the top context, fires HandleFocusLost on it and HandleFocus on the new top. Returns ErrPopAtBottom if the stack has only the root entry.
func (*ContextTree) PopIfTop ¶
func (t *ContextTree) PopIfTop(key types.ContextKey) error
PopIfTop pops the stack only when the top context's key matches key. If the top is something else (e.g. a dialog pushed by the ex handler), the pop is skipped and nil is returned. This prevents a deferred pop from accidentally dismissing a context pushed during command execution.
func (*ContextTree) Push ¶
func (t *ContextTree) Push(c types.IBaseContext) error
Push installs c on top of the stack per the kind-specific rules documented on ContextTree. Returns nil on success.
func (*ContextTree) RegisterSwapHook ¶
func (t *ContextTree) RegisterSwapHook(fn func())
RegisterSwapHook appends fn to the list of callbacks invoked when the stack composition changes (Push that actually pushed, Pop, Replace). A nil fn is silently dropped. Hooks are called in registration order on the same goroutine that performed the mutation (the MainLoop in production). Used by keys.OneshotArm to cancel any pending arm when the active context switches.
func (*ContextTree) Replace ¶
func (t *ContextTree) Replace(c types.IBaseContext) error
Replace swaps the top entry with c without firing pop/push lifecycle hooks. Used for tab switches within a single window slot.
func (*ContextTree) SetSessionLog ¶
func (t *ContextTree) SetSessionLog(l *slog.Logger)
SetSessionLog installs the per-session logger used by Push/Pop/ Replace/wipeStack/removeMain to emit cat=input ctx_* events. nil disables emission. Wired by the orchestrator at bootstrap; the nil-default keeps test fixtures that never call this method silent.
func (*ContextTree) Stack ¶
func (t *ContextTree) Stack() []types.IBaseContext
Stack returns a copy of the current stack from bottom to top.
func (*ContextTree) TakeEvictedMain ¶
func (t *ContextTree) TakeEvictedMain() types.IBaseContext
TakeEvictedMain returns and clears the MAIN_CONTEXT most recently displaced by removeMain (nil when none). The connection-manager close path uses it to re-push the pane the modal covered so focus returns where the user was.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package clipboard provides the shared clipboard seam used by the vim editor and the results grid + exporter.
|
Package clipboard provides the shared clipboard seam used by the vim editor and the results grid + exporter. |
|
Package commands defines the CommandRegistry: the named-action table that the keybinding system dispatches into.
|
Package commands defines the CommandRegistry: the named-action table that the keybinding system dispatches into. |
|
Package context contains the concrete Context implementations the pgsavvy TUI focus stack manages: the five side-rail contexts (Connections, Schemas, Tables, Columns, Indexes), the four popup contexts (Menu, Confirmation, Prompt, Suggestions), the command-log EXTRAS context, the GLOBAL context (no view), the LIMIT terminal-too-small overlay, and six StubContext placeholders for Contexts that ship in later epics (QUERY_EDITOR, TABLE_DATA_EDITOR, RESULT_GRID, PLAN, WHICH_KEY, HISTORY).
|
Package context contains the concrete Context implementations the pgsavvy TUI focus stack manages: the five side-rail contexts (Connections, Schemas, Tables, Columns, Indexes), the four popup contexts (Menu, Confirmation, Prompt, Suggestions), the command-log EXTRAS context, the GLOBAL context (no view), the LIMIT terminal-too-small overlay, and six StubContext placeholders for Contexts that ship in later epics (QUERY_EDITOR, TABLE_DATA_EDITOR, RESULT_GRID, PLAN, WHICH_KEY, HISTORY). |
|
Package controllers wires keyboard bindings to context state.
|
Package controllers wires keyboard bindings to context state. |
|
helpers
Package helpers ...
|
Package helpers ... |
|
helpers/data
Package data hosts data-access helpers that adapt drivers.Session into the shape the gui controllers consume.
|
Package data hosts data-access helpers that adapt drivers.Session into the shape the gui controllers consume. |
|
helpers/ui
Package ui hosts UI-presentation helpers consumed by the gui controllers: confirm/prompt/toast popups, the table double-click stub, the first-run tip dismissal, and the boxlayout-driven window arrangement.
|
Package ui hosts UI-presentation helpers consumed by the gui controllers: confirm/prompt/toast popups, the table double-click stub, the first-run tip dismissal, and the boxlayout-driven window arrangement. |
|
Package editor hosts the canonical *Buffer + UndoTree state for one QUERY_EDITOR pane and the per-context gocui.Editor implementations pgsavvy ships outside the COMMAND_LINE master editor.
|
Package editor hosts the canonical *Buffer + UndoTree state for one QUERY_EDITOR pane and the per-context gocui.Editor implementations pgsavvy ships outside the COMMAND_LINE master editor. |
|
format
Package format provides SQL formatting via sqlfmt.
|
Package format provides SQL formatting via sqlfmt. |
|
highlight
Package highlight wraps the Chroma v2 PostgreSQL lexer to provide SQL syntax highlighting for the query editor.
|
Package highlight wraps the Chroma v2 PostgreSQL lexer to provide SQL syntax highlighting for the query editor. |
|
sqlcontext
Package sqlcontext is the detection brain for schema-aware SQL completion.
|
Package sqlcontext is the detection brain for schema-aware SQL completion. |
|
Package grid ...
|
Package grid ... |
|
internal
|
|
|
testfake
Package testfake supplies an in-memory GuiDriver fake used by tests in pkg/gui.
|
Package testfake supplies an in-memory GuiDriver fake used by tests in pkg/gui. |
|
textcells
Package textcells reconciles the pinned gocui and tcell grapheme widths.
|
Package textcells reconciles the pinned gocui and tcell grapheme widths. |
|
Package keys is the single call site for registering keyboard and mouse bindings with the gocui runtime.
|
Package keys is the single call site for registering keyboard and mouse bindings with the gocui runtime. |
|
Package modes is intentionally empty.
|
Package modes is intentionally empty. |
|
Package orchestrator wires the pgsavvy TUI: it owns the focus-stack tree, the GuiDriver instance, every UI/data helper and controller, and the gocui MainLoop entry point.
|
Package orchestrator wires the pgsavvy TUI: it owns the focus-stack tree, the GuiDriver instance, every UI/data helper and controller, and the gocui MainLoop entry point. |
|
Package popup ...
|
Package popup ... |
|
Package presentation supplies render-time helpers that derive border styling and header text from a *models.Connection, plus the closures the context layer consumes through ContextTreeDeps.
|
Package presentation supplies render-time helpers that derive border styling and header text from a *models.Connection, plus the closures the context layer consumes through ContextTreeDeps. |
|
Package services ...
|
Package services ... |
|
custom_commands
Package custom_commands ...
|
Package custom_commands ... |
|
Package status assembles the status-bar string rendered along the bottom of the gui.
|
Package status assembles the status-bar string rendered along the bottom of the gui. |
|
Package style ships a chainable TextStyle builder used across the gui rendering layer.
|
Package style ships a chainable TextStyle builder used across the gui rendering layer. |
|
Package types declares the foundational type system shared by every pkg/gui subpackage: ContextKind/ContextKey enums, the IBaseContext interface, the Views holder, focus/refresh option structs, the Mode bitmask, KeyBinding, the GuiCommon/HelperCommon aggregators, and the GuiDriver interface that abstracts the underlying gocui runtime.
|
Package types declares the foundational type system shared by every pkg/gui subpackage: ContextKind/ContextKey enums, the IBaseContext interface, the Views holder, focus/refresh option structs, the Mode bitmask, KeyBinding, the GuiCommon/HelperCommon aggregators, and the GuiDriver interface that abstracts the underlying gocui runtime. |