ui

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 34 Imported by: 0

Documentation

Overview

Package ui assembles the terminal interface.

The rule this package follows is that widgets never hold application state. Anything a decision depends on — the current statement, the guard verdict, the result buffer — lives outside tview, so it can be tested without a terminal. Widgets only render what they are handed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

App is the running interface for one datasource.

func New

func New(sess *session.Session, cfg *config.Config, deps Deps) *App

New builds the interface for an open session.

The session rather than the connection, because switching datasource has to close what it left — and a tunnel closed by nobody outlives the thing it was carrying.

func (*App) Run

func (a *App) Run() error

Run starts the event loop and blocks until the user quits.

func (*App) SetScreen

func (a *App) SetScreen(screen tcell.Screen)

SetScreen replaces the terminal the interface draws on. Tests pass a tcell simulation screen so the real interface — layout, key handling, guard dialogs — can be exercised without a terminal.

func (*App) Snapshot added in v0.7.0

func (a *App) Snapshot(ctx context.Context) (*snapshot.Session, error)

Snapshot describes the session for something outside it.

Like State, it runs on the interface's own goroutine: a.running, the connection, the buffer and the vim state all belong to it, and reading them from anywhere else is a race. The context bounds the wait, because whatever asked has to be able to give up and say so.

func (*App) State added in v0.7.0

func (a *App) State(ctx context.Context) (RuntimeState, error)

State reports the session's datasource and whether a statement is in flight.

It goes through the interface's own goroutine because that is who owns a.running and the connection; reading them from anywhere else is a race. The context bounds the wait: a caller deciding whether it may take the session somewhere else must be able to give up and refuse, which is the safe answer when the interface is not talking.

func (*App) Stop

func (a *App) Stop()

Stop ends the event loop.

func (*App) SwitchTo added in v0.7.0

func (a *App) SwitchTo(name string)

SwitchTo moves the session to a configured datasource by name.

It hands off to the same switch the keyboard reaches, so an open transaction is asked about and a running statement is refused, in front of the person who will see the answer. Nothing is reported back: the interface is where the outcome belongs.

type Deps

type Deps struct {
	Keys    *keymap.Map
	Cache   *catalog.Cache
	History *history.Store
	// Worktree is the directory named by --dir, if any. Nil means the session
	// starts unattached, which is the ordinary case.
	Worktree *worktree.Worktree
	// Recent is the list of directories attached before. Nil costs the
	// shortcut and nothing else.
	Recent *recent.List
	// Connect opens another datasource, for switching mid-session. Nil leaves
	// the session on the datasource it started with, and the switch says so
	// rather than failing silently.
	Connect func(context.Context, *config.DataSource) (*session.Session, error)
	// Detach leaves the terminal without ending the session. Nil means there
	// is no server holding one — a monolithic run — and the action says so
	// rather than appearing dead.
	Detach func()
	// IntroPath is where "the first-run card has been shown" is recorded.
	// Empty means never show it, which is what a session with no usable state
	// directory gets — and what every test that is not about the card gets.
	IntroPath string
	// PresetAssumed says the configuration named no keyboard preset, so Keys
	// is the default rather than a choice. False — "they chose it" — is the
	// safe default for tests and for a config that did name one.
	PresetAssumed bool
}

Deps are the optional collaborators an interface can be given.

They are optional so that the interface still opens when the cache cannot be created — a read-only home directory should cost the user completion, not the whole application.

type RuntimeState added in v0.7.0

type RuntimeState struct {
	DataSource string
	Busy       bool
}

RuntimeState is what something outside the interface may need to know before it changes the session underneath it.

Jump to

Keyboard shortcuts

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