ui

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 21 Imported by: 0 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 ui is the interactive terminal UI behind `apic ui`: a request list on the left, a tabbed detail pane on the right, and a status bar. The model is driven entirely by messages and renders to a string, so tests call Update and View directly and need no terminal; program.go is the only part that touches one.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, m *Model, in *os.File, out io.Writer) error

Run drives the model on a real terminal: raw mode, the alternate screen, a size poller and a spinner ticker. It restores the terminal on the way out, including when the model panics.

Types

type Cmd

type Cmd func() Msg

Cmd is work run off the event loop; its Msg comes back to the model.

type Config

type Config struct {
	Root      string                                   // project root shown in the status bar
	Env       string                                   // initial environment
	Runner    *runner.Runner                           // initial runner
	NewRunner func(env string) (*runner.Runner, error) // rebuilds the runner on env change or reload
	Editor    string                                   // command for the o key; empty disables it
	Redact    bool                                     // --redact
	Demo      bool                                     // shows a demo badge in the status bar
	Theme     output.Theme
}

Config is everything the CLI hands the UI; tests build it directly.

type Key

type Key struct {
	Type KeyType
	Rune rune
}

Key is one decoded keypress.

func ParseKey

func ParseKey(name string) Key

ParseKey turns a binding name — "j", "enter", "ctrl+d", "shift+tab" — into a keypress. Anything else is taken as the literal rune, so "?" and "/" work as written.

func (Key) String

func (k Key) String() string

String is the name used in key bindings: "j", "enter", "ctrl+c", "up".

type KeyType

type KeyType int

KeyType names the keys the UI reacts to. Anything printable arrives as KeyRune with the rune set.

const (
	KeyRune KeyType = iota
	KeyEnter
	KeyEsc
	KeyTab
	KeyShiftTab
	KeyBackspace
	KeyUp
	KeyDown
	KeyLeft
	KeyRight
	KeyHome
	KeyEnd
	KeyPgUp
	KeyPgDown
	KeyCtrlC
	KeyCtrlD
	KeyCtrlU
)

Key types.

type Model

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

Model is the whole UI state.

func New

func New(cfg Config) *Model

New builds the model from a config.

func (*Model) Env

func (m *Model) Env() string

Env returns the current environment (for tests).

func (*Model) Press

func (m *Model) Press(name string)

Press feeds one key and settles everything it starts, so a run sent by enter has landed by the time Press returns.

func (*Model) PressAll

func (m *Model) PressAll(keys string)

PressAll presses several keys in order, splitting a space-separated list for brevity: "j enter 3".

func (*Model) Resize

func (m *Model) Resize(width, height int)

Resize tells the model how big the terminal is. The program loop does this from the real terminal; callers without one say so themselves.

func (*Model) Result

func (m *Model) Result(req *httpfile.Request) *runner.Result

Result returns the recorded result for a request (for tests).

func (*Model) Running

func (m *Model) Running() bool

Running reports whether a run is in flight (for tests).

func (*Model) Selected

func (m *Model) Selected() *httpfile.Request

Selected returns the request under the cursor (for tests).

func (*Model) Status

func (m *Model) Status() string

Status returns the transient status text (for tests).

func (*Model) Update

func (m *Model) Update(msg Msg) Cmd

Update handles one message and returns any follow-up work.

func (*Model) View

func (m *Model) View() string

View renders the whole screen.

type Msg

type Msg any

Msg is an event delivered to the model.

func Quit

func Quit() Msg

Quit is the command that ends the UI.

Jump to

Keyboard shortcuts

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