tui

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package tui is Stampede's interactive terminal UI: slash commands, plain language requests turned into commands, and live run views.

Index

Constants

View Source
const ExecArg = "console-exec"

ExecArg is the hidden subcommand that runs a command on the console's behalf with the terminal and waits for Enter before returning to it.

Variables

This section is empty.

Functions

func ReplayScenario

func ReplayScenario(file, base string, speed float64) (*scenario.Scenario, error)

ReplayScenario builds a scenario that replays a recording against base.

func Run

func Run(c *client.Client, opts Options) error

Run starts the program on the terminal.

func Sparkline

func Sparkline(v []float64, width int) string

Sparkline draws the last width values as block characters.

func SplitArgs added in v1.1.0

func SplitArgs(s string) ([]string, error)

SplitArgs splits a command line like a POSIX shell does for words: whitespace separates, single quotes keep everything literally, double quotes keep spaces, and a backslash escapes the next character.

Types

type Command

type Command struct {
	Name string
	Args []string
	// Flags hold --key value pairs.
	Flags map[string]string
}

Command is a parsed slash command.

func Interpret

func Interpret(text string, scenarios []string) (Command, bool)

Interpret turns a plain-language request into a command. It is deliberately simple and always shows the result for confirmation; it never guesses at anything it cannot name.

func ParseSlash

func ParseSlash(line string) (Command, bool)

ParseSlash parses "/run spike checkout --rate 100/s".

func (Command) String

func (c Command) String() string

String renders the command as the user would type it.

type Kind added in v1.1.0

type Kind int

Kind says how the console runs a stampede command it has no built-in form of.

const (
	// Inline runs the command with its output in the console.
	Inline Kind = iota
	// Terminal hands it the terminal: it may ask for a password, or print
	// something secret (a new token) that must not be kept in the session.
	Terminal
	// Daemon commands run until stopped and belong in their own terminal.
	Daemon
)

type Model

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

Model is the Bubble Tea model.

func New

func New(c *client.Client, opts Options) *Model

New builds the model. c may be nil, in which case /run works on local scenario files with the in-process engine.

func (*Model) Init

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

Init loads the header and scenario names.

func (*Model) Update

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

Update handles input and background messages.

func (*Model) View

func (m *Model) View() string

View renders the screen.

type Options

type Options struct {
	// Init is stampede init with the confirmation already given: it
	// detects the target's product type, installs the matching pack into
	// dir and dry-runs it, writing its progress to w.
	Init func(ctx context.Context, w io.Writer, target, dir string, env []string) error
	// CheckTarget applies stampede run's safety rules to a local run of
	// s and returns the host policy its requests must pass. Messages go
	// to w. Nil leaves local runs without a host policy.
	CheckTarget func(ctx context.Context, w io.Writer, s *scenario.Scenario, env map[string]string) (func(*url.URL) bool, error)
	// Commands are the stampede subcommands the console runs for a /name
	// it has no built-in form of, with how to run each; Self is the
	// stampede executable they run as.
	Commands map[string]Kind
	Self     string
	// Store keeps sessions and the input history; nil keeps nothing.
	Store *Store
	// Resume is a saved session to continue instead of starting a new one.
	Resume *Session
}

Options connect the console to commands that live in the CLI.

type Session added in v1.1.0

type Session struct {
	ID      string    `json:"id"`
	Started time.Time `json:"started"`
	Updated time.Time `json:"updated"`
	Server  string    `json:"server,omitempty"`
	Project string    `json:"project,omitempty"`
	// Title is the first thing typed in the session.
	Title  string   `json:"title,omitempty"`
	Inputs int      `json:"inputs"`
	Lines  []string `json:"lines"`
}

Session is one console conversation, saved so it can be picked up again with `stampede --continue`, `stampede --resume <id>` or /resume.

func NewSession added in v1.1.0

func NewSession() *Session

NewSession starts an empty session.

type Store added in v1.1.0

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

Store keeps sessions and the input history under the user's config directory (~/.config/stampede/console on Linux), readable only by them.

func OpenStore added in v1.1.0

func OpenStore() (*Store, error)

OpenStore opens the default store, creating its directory.

func OpenStoreAt added in v1.1.0

func OpenStoreAt(dir string) (*Store, error)

OpenStoreAt opens a store in dir.

func (*Store) AddHistory added in v1.1.0

func (s *Store) AddHistory(line string) error

AddHistory appends a typed line, keeping the last 1000.

func (*Store) History added in v1.1.0

func (s *Store) History() []string

History returns the lines typed in earlier sessions, oldest first.

func (*Store) List added in v1.1.0

func (s *Store) List(n int) ([]Session, error)

List returns saved sessions, most recently used first, without their transcripts; n <= 0 returns all.

func (*Store) Load added in v1.1.0

func (s *Store) Load(id string) (*Session, error)

Load returns the session whose ID is id or starts with it; an empty id means the most recent one.

func (*Store) Save added in v1.1.0

func (s *Store) Save(sess *Session) error

Save writes the session and drops the oldest beyond the last 50.

Jump to

Keyboard shortcuts

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