Documentation
¶
Overview ¶
Package chat is the terminal side of the interactive mode: the slash-command table and its menu, a small line editor with key decoding, and a console that keeps the input line intact while session events print above it. It knows nothing about the API.
Index ¶
- Constants
- Variables
- func Complete(c Command) string
- func Describe(ev api.Event) string
- func HelpLines() []string
- func Width(s string) int
- type Activity
- func (a *Activity) Active() bool
- func (a *Activity) Block(st style.Style, frame int, sp *mark.Spinner) string
- func (a *Activity) Elapsed() time.Duration
- func (a *Activity) Line(st style.Style, frame int, spinner bool) string
- func (a *Activity) Observe(ev api.Event)
- func (a *Activity) Start()
- func (a *Activity) Stop()
- func (a *Activity) Text() string
- type Command
- type Console
- type Editor
- type Key
- type KeyKind
- type PickItem
- type PickStyle
- type PickTab
- type Picker
- type Result
Constants ¶
const MaxMenu = 6
MaxMenu is how many commands the menu shows at once.
const PickRows = 8
PickRows is how many items a Picker shows at once.
Variables ¶
var Commands = []Command{ {Name: "new", Args: "[prompt]", Desc: "Start a new session from this repo"}, {Name: "sessions", Desc: "List recent sessions and pick one by number"}, {Name: "switch", Args: "<id>", Desc: "Follow another session"}, {Name: "status", Desc: "Run, queue, last outcome, pull request"}, {Name: "stop", Desc: "Stop the running work (changes are kept)"}, {Name: "steer", Args: "<text>", Desc: "Redirect the run that is going"}, {Name: "queue", Desc: "Show the prompts waiting behind the run"}, {Name: "logs", Args: "[N]", Desc: "Show the last N events (default 30)"}, {Name: "diff", Desc: "What the session changed, per repo"}, {Name: "pr", Desc: "Show and open the pull request"}, {Name: "preview", Desc: "Print preview links (one-time, 60 seconds)"}, {Name: "open", Desc: "Open the session in the browser"}, {Name: "share", Args: "[viewer|collaborator]", Desc: "Turn on a share link and print it"}, {Name: "export", Args: "[csv|xlsx]", Desc: "Save this session's summary row to a file"}, {Name: "mode", Args: "auto|build|plan|ask", Desc: "How the next prompts run"}, {Name: "model", Args: "[name]", Desc: "Pick the model for the next prompts", Aliases: []string{"models"}}, {Name: "attach", Args: "<file>", Desc: "Attach a file to the next prompt"}, {Name: "whoami", Desc: "Who you are and where"}, {Name: "workspace", Args: "[name]", Desc: "List workspaces, or switch for this chat"}, {Name: "login", Desc: "Sign in"}, {Name: "logout", Desc: "Sign out and leave"}, {Name: "clear", Desc: "Clear the screen (the session keeps going)"}, {Name: "help", Aliases: []string{"?"}, Desc: "List every command"}, {Name: "quit", Aliases: []string{"exit"}, Desc: "Leave; the session keeps running"}, }
Commands are all the slash commands, in the order the menu shows them.
var SpinnerFrames = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
SpinnerFrames are the braille frames of the spinner, drawn about ten times a second.
var Words = []string{
"Thinking",
"Looking closer",
"Connecting the dots",
"Weighing options",
"Checking twice",
"Turning it over",
"Following the thread",
"Sorting it out",
"Gathering my thoughts",
"Piecing it together",
"Reading between the lines",
"Taking a careful look",
}
Words are what the status line says between real updates: Waniis's own gentle words.
Functions ¶
func Complete ¶
Complete is the text Tab puts in the input for a command: "/name", plus a space when it takes arguments.
func Describe ¶ added in v0.1.1
Describe says what a real event means for what Waniis is doing, "" when it says nothing new.
Types ¶
type Activity ¶ added in v0.1.1
type Activity struct {
// contains filtered or unexported fields
}
Activity is the live status of a working session: what Waniis is doing now, from the events, and for how long. It is pure and driven by an injected clock, so it can be tested.
func NewActivity ¶ added in v0.1.1
NewActivity returns an idle status.
func (*Activity) Block ¶ added in v0.1.3
Block is the status with the turning Waniis mark: two lines, the mark spanning both. The first says one of Waniis's words and for how long; the second, the latest real update (what it is reading, running or writing) or how to stop.
func (*Activity) Line ¶ added in v0.1.1
Line is the status line: a spinner frame (a static dot without a spinner) and the text.
func (*Activity) Observe ¶ added in v0.1.1
Observe takes one event: a real update replaces what the line says.
type Command ¶
Command is a slash command: its name, the argument hint and a one-line description.
type Console ¶
type Console struct {
Out io.Writer
Raw bool
Width func() int
Prompt func() string // the prompt text, plain
// Footer is a line under the input (the mode), shown when no menu is open; nil or "": none.
// It is called with the console's lock held.
Ed *Editor
Bold func(string) string // styling for the selected menu item; nil: none
Dim func(string) string
// Pick, when set, is drawn under the input line instead of the command menu and takes the
// keys. Set and clear it with OpenPicker and inside Edit.
Pick *Picker
PickStyle PickStyle
// contains filtered or unexported fields
}
Console is the chat's output. In Raw mode (a terminal in raw input mode) it keeps a footer at the bottom: the half-written line of a streaming answer, the live status line, the input line and the command menu. Text written to it scrolls above the footer, which is drawn again after, so the input line stays usable while Waniis streams. Otherwise it is a plain writer.
func (*Console) Edit ¶ added in v0.1.1
func (c *Console) Edit(fn func())
Edit runs fn while holding the console's lock: the input line (Ed) is read when the footer is drawn, which can happen from the stream's goroutine at any time, so every change to it from the key-reading goroutine goes through here.
func (*Console) Hide ¶
func (c *Console) Hide()
Hide removes the footer, finishing any half-written line, and leaves the cursor at the start of an empty line.
func (*Console) OpenPicker ¶ added in v0.1.2
OpenPicker shows p under the input line; it takes the keys until it is done.
func (*Console) Redraw ¶
func (c *Console) Redraw()
Redraw draws the footer again (after a key press).
func (*Console) SetStatus ¶ added in v0.1.1
SetStatus sets the live status line (already styled, no newline); "" removes it.
type Editor ¶
type Editor struct {
Buf []rune
Pos int
Sel int // selected menu item
Dismissed bool // Esc closed the menu until the text changes
Line string
// contains filtered or unexported fields
}
Editor is a one-line editor with history and the slash-command menu. It is pure: it takes keys and changes its state; the Console draws it.
type PickItem ¶ added in v0.1.2
type PickItem struct {
ID string
Label string
Detail string // shown dim after the label
Note string // why it can't be chosen; shown dim at the end
Disabled bool // shown, but Enter explains instead of choosing
Current bool // marked as the one in use
}
PickItem is one row of a Picker.
type PickTab ¶ added in v0.1.2
PickTab is one tab: its name and which items it shows. A Search tab filters by what is typed.
type Picker ¶ added in v0.1.2
type Picker struct {
Title string
Tabs []PickTab
Items []PickItem
Match func(item PickItem, query string) bool
// Done is called once, outside the console's lock, with the chosen item or nil when closed.
Done func(*PickItem)
Tab int
Sel int
Query []rune
}
Picker is a list with tabs that opens under the input line ("/model"): ←/→ or Tab change the tab, ↑/↓ move, typing searches, Enter chooses and Esc closes. Match says whether an item fits the search words.
func (*Picker) Handle ¶ added in v0.1.2
Handle applies one key. It reports whether the picker is finished, and the chosen item (nil when it was closed). Choosing a disabled item finishes it too, so the caller can say why.