ui

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 46 Imported by: 0

Documentation

Overview

Package ui is the Bubble Tea front end. Inside the grid it behaves like Google Sheets (keys, selection, entry); around it, the control panel and mode indicator give it a 1-2-3 look.

Index

Constants

View Source
const (
	// FrameRate is how many frames a second Bubble Tea may draw, its
	// maximum (tea.WithFPS). A key's answer waits for the next frame, so
	// this halves the wait at the default 60. The renderer writes a frame
	// only when the view changed, so an idle screen costs no more.
	FrameRate = 120
	// FrameInterval is the time between frames.
	FrameInterval = time.Second / FrameRate
)
View Source
const RecoveryDir = ".012-recovery"

RecoveryDir is the directory, inside the served one, recovery files are kept in.

Variables

This section is empty.

Functions

This section is empty.

Types

type Model

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

Model is the root of the UI, the tea.Model Bubble Tea runs. It holds the file, the mode and the grid, owns a component for everything that takes input or draws a part of the screen, routes each message to the one it's for, and composes the screen from what they draw (panel.go, view.go, overlay.go).

func New

func New(s *sheet.Sheet, filename string) *Model

New returns a model editing s. filename may be empty.

func (*Model) AllowEditor

func (m *Model) AllowEditor()

AllowEditor lets the user edit macro scripts in their own editor ($VISUAL or $EDITOR), which runs as a program of theirs with the screen handed over. Only the local app allows it: a session served over SSH must not start programs on the server.

func (*Model) Configure

func (m *Model) Configure(s Settings)

Configure applies settings: the theme, chart images, notifications, and notes for the context line.

func (*Model) EnableJEV

func (m *Model) EnableJEV(client jev.Client, cache *jev.Cache)

EnableJEV turns on JEV functions: the cache answers them, for this workbook and those opened later, and the client asks what it lacks.

func (*Model) Filename

func (m *Model) Filename() string

Filename is the open file's name as typed, "" for a book never saved.

func (*Model) Import

func (m *Model) Import(name string)

Import sets a file to import when the program starts, e.g. from "012 sales.csv".

func (*Model) Init

func (m *Model) Init() tea.Cmd

Init implements tea.Model. It asks the terminal for its background color so the theme can adapt to light terminals.

func (*Model) OpenOnStart

func (m *Model) OpenOnStart(name string)

OpenOnStart makes a served session start on name, as `ssh -t host name` asks: a sheet to open (or a new one to save as name, when there's no such file) or a file to import. Either way, or with name empty, the session then offers unsaved changes kept for that name.

func (*Model) Recover

func (m *Model) Recover(now time.Time) (string, error)

Recover writes the workbook to a new recovery file for its name, removing the oldest beyond recoveryKeep, and returns the file's name relative to the served directory. It's for 012 serve, when the program has stopped; a model that isn't served has nowhere to put one.

func (*Model) Serve

func (m *Model) Serve(root confine.Root, env []string)

Serve prepares m for a session served over SSH: file names resolve inside root, and env (KEY=value pairs) is the client's environment, used instead of the server's to learn about the client's terminal.

func (*Model) SetMachine

func (m *Model) SetMachine(id string)

SetMachine tells the model which computer it runs on, as an id kept in the user's configuration, so macros saved here run without asking and macros from files made elsewhere ask once.

func (*Model) SetVimKeys

func (m *Model) SetVimKeys(on bool)

SetVimKeys turns vim keys on or off, as the setting does, for callers that know the user's choice at startup.

func (*Model) TraceUnder

func (m *Model) TraceUnder(p telemetry.Parent)

TraceUnder nests every span the model starts under p for good: 012 serve's session span holds each session's commands.

func (*Model) Unsaved

func (m *Model) Unsaved() bool

Unsaved reports whether the workbook has changes a recovery file would keep: it was changed since it was last saved or opened, and isn't empty.

func (*Model) Update

func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update implements tea.Model.

func (*Model) View

func (m *Model) View() tea.View

View implements tea.Model.

type Settings

type Settings struct {
	Config    *config.Config
	Reload    func() *config.Config // reads the config file again; nil disables Reload config
	ThemesDir string                // the user's theme files
	Keys      keyring.Store         // where JEV API key stores the key; nil disables it
	// Connect makes a JEV client for the configured service with key.
	Connect func(key string) (jev.Client, error)
	Notes   []string // said on the context line at startup, e.g. config warnings
}

Settings are what the app takes from outside the workbook: the config file's options, and the credential store the JEV API key lives in. cmd/012 passes them to Configure; tests pass fakes, so the user's own config and keychain are never touched.

Directories

Path Synopsis
Package cmdline is the command line (: with vim keys, or from the palette): what's typed on the context line, with completions from the command registry in a box under it.
Package cmdline is the command line (: with vim keys, or from the palette): what's typed on the context line, with completions from the command registry in a box under it.
Package findbar is find and replace: a bar on the context line rather than a dialog, in the spirit of less and vim.
Package findbar is find and replace: a bar on the context line rather than a dialog, in the spirit of less and vim.
Package formula reads the formula being typed in the UI: the reference F4 cycles through absolute markers, and the word and function call around the caret that formula assistance follows.
Package formula reads the formula being typed in the UI: the reference F4 cycles through absolute markers, and the word and function call around the caret that formula assistance follows.
Package lineedit is the one-line text editor behind every text field of the UI.
Package lineedit is the one-line text editor behind every text field of the UI.
Package overlay is the contract between the UI's root model and the components that take over input while open: menus, pickers, bars on the context line and dialogs.
Package overlay is the contract between the UI's root model and the components that take over input while open: menus, pickers, bars on the context line and dialogs.
Package picker is the searchable list behind the command palette and every other picker of the UI (functions, sheets, named ranges, macros, themes, files to import): a search field on top, results below with matched characters highlighted, in the manner of fzf.
Package picker is the searchable list behind the command palette and every other picker of the UI (functions, sheets, named ranges, macros, themes, files to import): a search field on top, results below with matched characters highlighted, in the manner of fzf.
Package rowtext lays out the text of one row of cells across the columns on screen, as Sheets does: values formatted and aligned, text running on into blank neighbors, cut to column boundaries in a single pass.
Package rowtext lays out the text of one row of cells across the columns on screen, as Sheets does: values formatted and aligned, text running on into blank neighbors, cut to column boundaries in a single pass.
Package tabstrip is the sheet tabs at the left of the status line, the way tmux lists windows: the sheet shown is highlighted, a + adds a sheet, and when the tabs don't all fit, ‹ and › step through them.
Package tabstrip is the sheet tabs at the left of the status line, the way tmux lists windows: the sheet shown is highlighted, a + adds a sheet, and when the tabs don't all fit, ‹ and › step through them.
Package theme is the look of the UI: the style roles every view draws with, and the small widgets built from them (framed boxes, key chips, key hints).
Package theme is the look of the UI: the style roles every view draws with, and the small widgets built from them (framed boxes, key chips, key hints).
Package themepicker is File > Settings > Theme: every theme in a picker, fuzzy searched by name, "dark" or "light".
Package themepicker is File > Settings > Theme: every theme in a picker, fuzzy searched by name, "dark" or "light".
Package transfer runs imports in the background and draws their progress: the mode indicator says WAIT, the context line offers Esc, the status line counts rows with a progress bar, and the terminal shows its own progress indicator.
Package transfer runs imports in the background and draws their progress: the mode indicator says WAIT, the context line offers Esc, the status line counts rows with a progress bar, and the terminal shows its own progress indicator.

Jump to

Keyboard shortcuts

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