tui

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 30 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 tui holds PlugIt's terminal screens (SPEC §2.3), built on Bubble Tea. Spec-derived text is untrusted: everything drawn is stripped of control and format characters first, so a spec can't drive the terminal.

Index

Constants

This section is empty.

Variables

View Source
var ErrCancelled = errors.New("cancelled; nothing saved")

ErrCancelled means the user left the picker without saving.

Functions

func HumanBytes

func HumanBytes(n int64) string

HumanBytes formats a byte count for people.

func Millis

func Millis(d time.Duration) string

Millis formats a latency.

func NoColor

func NoColor() bool

NoColor reports whether --no-color is in effect.

func RunChooser

func RunChooser(ctx context.Context, title, subtitle string, choices []Choice, r io.Reader, w io.Writer) ([]int, error)

RunChooser shows a chooser on a terminal and returns the chosen indexes, or ErrCancelled.

func RunInspector

func RunInspector(ctx context.Context, in InspectorInput, r io.Reader, w io.Writer) error

RunInspector shows the inspector until the user quits.

func RunPicker

func RunPicker(ctx context.Context, in PickerInput, r io.Reader, w io.Writer) (config.Toolset, policy.Mode, error)

RunPicker runs the picker on a terminal and returns the saved selection and policy mode, or ErrCancelled.

func RunStats

func RunStats(ctx context.Context, in StatsInput, r io.Reader, w io.Writer) error

RunStats shows the stats screen until the user quits.

func RunSync

func RunSync(ctx context.Context, in SyncInput, r io.Reader, w io.Writer) ([]model.OpKey, error)

RunSync shows the screen and returns the chosen new operations, or ErrCancelled.

func RunTryIt

func RunTryIt(ctx context.Context, in TryInput, r io.Reader, w io.Writer) error

RunTryIt shows the Try it screen until the user quits.

func Safe

func Safe(s string) string

Safe strips control and format characters from untrusted text before it is printed to a terminal.

func SafeText added in v0.2.0

func SafeText(s string) string

SafeText is Safe for text of several lines: line breaks and tabs are kept, every other control or format character is removed.

func SetNoColor

func SetNoColor(on bool)

SetNoColor turns colour off (or back on) for every screen: the global --no-color flag. NO_COLOR in the environment works without it.

Types

type CallsMsg

type CallsMsg struct {
	Calls []store.Call
	Err   error
}

CallsMsg delivers calls newer than the last ones seen (or a read error).

type Choice

type Choice struct {
	Label  string
	Detail string
	Note   string
}

Choice is one row of a Chooser.

type Chooser

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

Chooser is a small inline multi-select (used to pick MCP clients).

func NewChooser

func NewChooser(title, subtitle string, choices []Choice) *Chooser

NewChooser builds a chooser with nothing selected.

func (*Chooser) Init

func (c *Chooser) Init() tea.Cmd

Init implements tea.Model.

func (*Chooser) Result

func (c *Chooser) Result() ([]int, bool)

Result returns the chosen indexes in order, and false if the user cancelled.

func (*Chooser) Update

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

Update implements tea.Model.

func (*Chooser) View

func (c *Chooser) View() tea.View

View implements tea.Model.

type Inspector

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

Inspector is a live tail of the call log: a Bubble Tea model.

func NewInspector

func NewInspector(in InspectorInput) *Inspector

NewInspector builds an inspector.

func (*Inspector) Init

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

Init implements tea.Model: ask for the background colour and read the log.

func (*Inspector) Update

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

Update implements tea.Model.

func (*Inspector) View

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

View implements tea.Model.

type InspectorInput

type InspectorInput struct {
	Title    string
	AllAPIs  bool
	Source   func(ctx context.Context, afterID int64) ([]store.Call, error)
	Interval time.Duration
}

InspectorInput configures the call inspector (SPEC §2.3).

type Picker

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

Picker is the tool picker: a Bubble Tea model.

func NewPicker

func NewPicker(in PickerInput) *Picker

NewPicker builds a picker.

func (*Picker) Init

func (p *Picker) Init() tea.Cmd

Init implements tea.Model. It asks the terminal for its background colour to pick the palette.

func (*Picker) Mode

func (p *Picker) Mode() policy.Mode

Mode returns the API's policy mode as set in the picker.

func (*Picker) Result

func (p *Picker) Result() (config.Toolset, bool)

Result returns the selection and whether the user saved it.

func (*Picker) Update

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

Update implements tea.Model.

func (*Picker) View

func (p *Picker) View() tea.View

View implements tea.Model.

type PickerInput

type PickerInput struct {
	API      string
	Tools    []model.Tool
	Prefix   string
	Mode     policy.Mode
	Selected config.Toolset
	Lint     func(config.Toolset) []lint.Finding
}

PickerInput is what the picker edits.

type Stats

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

Stats is the per-API, per-tool summary of the call log.

func NewStats

func NewStats(in StatsInput) *Stats

NewStats builds the stats screen, showing the last 7 days.

func (*Stats) Init

func (s *Stats) Init() tea.Cmd

Init implements tea.Model.

func (*Stats) Update

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

Update implements tea.Model.

func (*Stats) View

func (s *Stats) View() tea.View

View implements tea.Model.

type StatsInput

type StatsInput struct {
	Title    string
	Source   func(ctx context.Context, since time.Time) ([]store.ToolStats, error)
	Budgets  map[string]string
	Interval time.Duration
	Now      func() time.Time
}

StatsInput configures the stats screen (SPEC §2.3).

type StatsMsg

type StatsMsg struct {
	Stats []store.ToolStats
	Err   error
}

StatsMsg delivers fresh numbers (or a read error).

type SyncInput

type SyncInput struct {
	API      string
	Diff     curate.SyncDiff
	BaseURL  string
	Toolset  string
	LintNote string
}

SyncInput configures the Sync diff screen (SPEC §2.3).

type SyncScreen

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

SyncScreen shows what a new spec changes and lets the user pick which new operations to add. Overrides are always kept.

func NewSyncScreen

func NewSyncScreen(in SyncInput) *SyncScreen

NewSyncScreen builds the screen with no new operations chosen.

func (*SyncScreen) Init

func (s *SyncScreen) Init() tea.Cmd

Init implements tea.Model.

func (*SyncScreen) Result

func (s *SyncScreen) Result() ([]model.OpKey, bool)

Result returns the chosen new operations and whether to apply.

func (*SyncScreen) Update

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

Update implements tea.Model.

func (*SyncScreen) View

func (s *SyncScreen) View() tea.View

View implements tea.Model.

type TryInput

type TryInput struct {
	API     string
	Tool    model.Tool
	Mode    policy.Mode
	Confirm string
	Send    func(ctx context.Context, args map[string]string) TryResult
}

TryInput configures the Try it screen (SPEC §2.3).

type TryIt

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

TryIt is a form generated from a tool's parameters that makes one call and shows the redacted request and the response.

func NewTryIt

func NewTryIt(in TryInput) *TryIt

NewTryIt builds the form. Hidden params (credentials, fixed values) get no field: plugit fills them in.

func (*TryIt) Init

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

Init implements tea.Model.

func (*TryIt) Update

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

Update implements tea.Model.

func (*TryIt) View

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

View implements tea.Model.

type TryResult

type TryResult struct {
	Request  string
	Status   int
	Response string
	IsError  bool
	Err      string
}

TryResult is one call's outcome, already redacted.

Jump to

Keyboard shortcuts

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