tui

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 34 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 is the terminal view of the daemon: the task views of its tasks, the plugins' views of their units and the workflows' plan, with the keys of #keys.

Index

Constants

View Source
const (
	KeyUp        = "up"
	KeyDown      = "down"
	KeyEnter     = "enter"
	KeyEsc       = "esc"
	KeyBackspace = "backspace"
	KeyTab       = "tab"
	KeyCtrlC     = "ctrl-c"
	KeyCtrlZ     = "ctrl-z"
	KeyCtrlK     = "ctrl-k"
	KeyCtrlE     = "ctrl-e"
	KeyPaste     = "paste"
)
View Source
const Source = string(turn.TUI)

Source is what every request of the TUI names, an answer included.

Variables

View Source
var ErrNotTerminal = errors.New(brand.Command + " tui needs a terminal on stdin and stdout") //prose:internal the command line's error, English by the spec

Functions

func Run

func Run(ctx context.Context, cfg Config) error

Run draws the views and applies keys until q, Ctrl-C, the end of the keys or ctx. An action sent to the daemon is not cancelled by quitting: q waits for the running ones, and a second q leaves without them.

Types

type Command

type Command struct {
	Unit   unit.Unit
	Label  string
	Action string
	Req    api.ActionRequest
	PlanID string
	// contains filtered or unexported fields
}

Command is an action for the daemon on one unit; Label names it on the status line. A plan action carries its item's PlanID.

type Config

type Config struct {
	Daemon Daemon
	Term   Terminal
	Now    func() time.Time
	// Tick redraws the ages and countdowns; zero means every second.
	Tick time.Duration
	// Refresh polls the rows while the daemon has no event stream; zero
	// means every 30 seconds. With a stream up, nothing polls.
	Refresh time.Duration
	// Reconnect is the wait before asking for the event stream again while
	// the daemon does not answer; zero means 2 seconds.
	Reconnect time.Duration
	// Color styles the screen; the caller decides it as termfmt does.
	Color bool
	// OpenURL opens a unit's link, as the open command does; nil cannot.
	OpenURL func(url string) error
}

type Daemon

type Daemon interface {
	RowsSince(ctx context.Context, since api.Since) (api.RowsPage, error)
	Health(ctx context.Context) (api.Health, error)
	Catalog(ctx context.Context) (api.CatalogResponse, error)
	Plugins(ctx context.Context) ([]api.Plugin, error)
	Actions(ctx context.Context) (api.ActionsResponse, error)
	Ask(ctx context.Context, u unit.Unit, action string, req api.ActionRequest) (api.ActionResult, error)
	Events(ctx context.Context, client string, since api.Since) (<-chan api.Change, error)
	Plan(ctx context.Context, q api.PlanQuery) (api.PlanResponse, error)
	ActOnPlan(ctx context.Context, req api.PlanActRequest) (api.PlanResponse, error)
	Views(ctx context.Context) (api.ViewsCatalog, error)
	TasksSince(ctx context.Context, q client.TaskQuery, since api.Since) (api.TasksPage, error)
	Counters(ctx context.Context, area, query string) (api.Counters, error)
	Task(ctx context.Context, id string) (api.TaskView, error)
	MatchTasks(ctx context.Context, text, except string) ([]api.TaskView, error)
	TaskDo(ctx context.Context, id, verb string, req api.TaskRequest) (api.TaskResult, error)
	TaskDrafts(ctx context.Context, task string) ([]api.Draft, error)
	ResolveGate(ctx context.Context, id int64, intent string, req api.TaskRequest) (api.GateView, error)
	Gates(ctx context.Context) ([]api.GateView, error)
	CreateTask(ctx context.Context, req api.TaskCreate) (api.TaskView, error)
	Keys(ctx context.Context, surface string) (api.KeysResponse, error)
	Review(ctx context.Context) (api.Review, error)
	ReviewStepDone(ctx context.Context, step string) (api.Review, error)
	Strings(ctx context.Context) (api.Strings, error)
}

type Decoder

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

Decoder turns what a raw terminal sends into keys, across reads: an escape sequence or a UTF-8 rune split between two reads is held for the next one, so its second half never arrives as typed text. Escape sequences it does not know are dropped whole.

func (*Decoder) Expire

func (d *Decoder) Expire()

Expire is called when a paste went idle: what came so far is dropped and so is the rest, up to the end marker. A discard that goes idle too ends.

func (*Decoder) Feed

func (d *Decoder) Feed(b []byte) []Key

Feed decodes b after the bytes held from the previous read.

func (*Decoder) Flush

func (d *Decoder) Flush() []Key

Flush is called when no more bytes came within a key's time: a lone ESC is the Esc key, and anything else held is dropped. A paste is not touched.

func (*Decoder) Holding

func (d *Decoder) Holding() bool

Holding reports whether bytes wait for the rest of an escape sequence or a rune: Flush ends the wait.

func (*Decoder) InPaste

func (d *Decoder) InPaste() bool

InPaste reports whether a paste has not ended: Expire ends the wait.

type EditRequest

type EditRequest struct {
	Label string
	Text  string
	// contains filtered or unexported fields
}

EditRequest is a prompt's text handed to the editor; Submit takes what the editor returns.

type Editor

type Editor interface {
	Edit(text string) (string, error)
}

An Editor can hand the terminal to the user's editor on a text and return the text it left.

type Key

type Key struct {
	Rune rune
	Name string
	Text string
	Read uint64
}

Key is one key press: a printable rune, or a named key with Rune 0. A bracketed paste arrives whole as KeyPaste with its Text. Read numbers the terminal read the key came in, so a key typed ahead in the same read as the one that opened a prompt can be told apart from a deliberate answer.

func Decode

func Decode(b []byte) []Key

Decode reads the keys in b as one whole input.

type Model

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

func NewModel

func NewModel() *Model

func (*Model) Done

func (m *Model) Done(c Command, lines []string, err error)

Done reports a finished action on the status line.

func (*Model) Edited

func (m *Model) Edited(e *EditRequest, text string, err error) (Command, bool)

Edited submits what the editor returned for e; an empty text cancels.

func (*Model) FilterQuery added in v0.4.0

func (m *Model) FilterQuery() string

FilterQuery is the filter as typed, trimmed: the lens query the daemon counts with.

func (*Model) Key

func (m *Model) Key(k Key) (c Command, ok bool)

Key applies one key press; ok means the command goes to the daemon.

func (*Model) Quit

func (m *Model) Quit() bool

func (*Model) Refetch

func (m *Model) Refetch() (Command, bool)

Refetch asks again for the open detail once a page changed its task.

func (*Model) Render

func (m *Model) Render(width, height int, now time.Time) []string

Render draws the screen as height lines of at most width cells: the views, the list of the current one, the selected pull request's detail, a status line and the help or prompt line.

func (*Model) SetCatalog

func (m *Model) SetCatalog(c api.CatalogResponse)

SetCatalog takes the terminal's row views and the kinds' labels from the served catalog, keeping the current view by id.

func (*Model) SetClosed added in v0.2.0

func (m *Model) SetClosed(closed []api.ClosedSession)

SetClosed replaces the sessions closed in the last day.

func (*Model) SetColor

func (m *Model) SetColor(on bool)

SetColor styles the screen with escapes; off, it is plain text.

func (*Model) SetCounters

func (m *Model) SetCounters(c api.Counters)

SetCounters replaces the counts the tabs show.

func (*Model) SetData

func (m *Model) SetData(rows []api.Row, h api.Health)

SetData replaces the rows and keeps the selected pull request while it is still in the view, else the same place in the list.

func (*Model) SetDetail

func (m *Model) SetDetail(id string, e api.TaskView, err error)

SetDetail shows the task the daemon answered for the open detail.

func (*Model) SetDrafts

func (m *Model) SetDrafts(id string, ds []api.Draft)

SetDrafts shows the drafts made for task id while its detail is open.

func (*Model) SetError

func (m *Model) SetError(err error)

SetError keeps the last rows on screen while the daemon does not answer.

func (*Model) SetFilteredCounters added in v0.2.0

func (m *Model) SetFilteredCounters(area string, c api.Counters)

SetFilteredCounters takes the counts of area narrowed to the tasks the filter keeps.

func (*Model) SetGates added in v0.3.0

func (m *Model) SetGates(gs []api.GateView)

SetGates takes the open gates: a plan gate with a deadline is an automatic round its unit's row counts down to.

func (*Model) SetKeys

func (m *Model) SetKeys(b []api.KeyView)

SetKeys replaces the bindings of the terminal the keys follow.

func (*Model) SetLoading added in v0.3.0

func (m *Model) SetLoading(ls []api.Loading)

SetLoading takes the plugins the last page of tasks said are still loading.

func (*Model) SetMatches added in v0.4.0

func (m *Model) SetMatches(text string, tasks []api.TaskView, err error)

SetMatches lists the open tasks the daemon answered for text, while the picker still holds that text.

func (*Model) SetPlan

func (m *Model) SetPlan(items []api.PlanItem, err error)

SetPlan replaces the plan items, pending ones whose window ends soonest first, and keeps the selected one while it is still pending or blocked, else the same place in the list.

func (*Model) SetPlanSpecs

func (m *Model) SetPlanSpecs(specs []api.ActionSpec)

SetPlanSpecs replaces the specs of the actions a plan item may offer.

func (*Model) SetPlugins

func (m *Model) SetPlugins(ps []api.Plugin)

SetPlugins keeps the plugins the daemon serves, whose views the catalog lists, keeping the current view by id.

func (*Model) SetReview

func (m *Model) SetReview(r api.Review)

SetReview takes the Review the daemon serves; with no step shown, or one it no longer has, the first open step is shown.

func (*Model) SetSpecs

func (m *Model) SetSpecs(specs []api.ActionSpec)

SetSpecs replaces the action specs the keys follow.

func (*Model) SetTasks added in v0.3.0

func (m *Model) SetTasks(view string, tasks []api.TaskView, c api.Counters)

SetTasks replaces the tasks of view, as its last page left them, and the counters that page carried.

func (*Model) SetViews added in v0.3.0

func (m *Model) SetViews(c api.ViewsCatalog)

SetViews takes the profile's views of GET /api/views. The first time, before the user moved to a view, it shows the first.

func (*Model) Stay

func (m *Model) Stay(why string)

Stay undoes a quit the caller cannot honor yet, and says why.

func (*Model) TakeEdit

func (m *Model) TakeEdit() *EditRequest

TakeEdit is the text a prompt handed to the editor, nil when none waits.

func (*Model) TaskQuery added in v0.3.0

func (m *Model) TaskQuery() (view, area string, ok bool)

TaskQuery is the task view on screen and the area the list follows; ok is false outside the task views.

type Suspender

type Suspender interface {
	Suspend() error
}

A Suspender can hand the terminal back to the shell on Ctrl-Z.

type TTY

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

TTY is the process's terminal in raw mode on the alternate screen.

func Open

func Open() (*TTY, error)

func (*TTY) Close

func (t *TTY) Close() error

Close leaves the alternate screen and restores the terminal's mode.

func (*TTY) Draw

func (t *TTY) Draw(lines []string) error

func (*TTY) Edit

func (t *TTY) Edit(initial string) (string, error)

Edit gives the terminal to $VISUAL, else $EDITOR, else vi, on a file holding initial, and returns the file as the editor left it.

func (*TTY) Err

func (t *TTY) Err() error

Err is why the keys ended early, nil when they did not.

func (*TTY) Keys

func (t *TTY) Keys() <-chan Key

func (*TTY) Size

func (t *TTY) Size() (int, int)

func (*TTY) Suspend

func (t *TTY) Suspend() error

Suspend gives the terminal back as it was, stops the process group like a shell's Ctrl-Z, and takes the terminal again once the job resumes.

type Terminal

type Terminal interface {
	Size() (width, height int)
	Draw(lines []string) error
	Keys() <-chan Key
}

type View

type View struct{ ID, Label, Provider string }

Jump to

Keyboard shortcuts

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