chat

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 13 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 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

View Source
const MaxMenu = 6

MaxMenu is how many commands the menu shows at once.

View Source
const PickRows = 8

PickRows is how many items a Picker shows at once.

Variables

View Source
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.

View Source
var SpinnerFrames = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}

SpinnerFrames are the braille frames of the spinner, drawn about ten times a second.

View Source
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

func Complete(c Command) string

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

func Describe(ev api.Event) string

Describe says what a real event means for what Waniis is doing, "" when it says nothing new.

func HelpLines

func HelpLines() []string

HelpLines lists every command with its description, aligned.

func Width added in v0.1.1

func Width(s string) int

Width is the printed width of s in columns, ignoring ANSI sequences.

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

func NewActivity(now func() time.Time) *Activity

NewActivity returns an idle status.

func (*Activity) Active added in v0.1.1

func (a *Activity) Active() bool

Active reports whether the status is going.

func (*Activity) Block added in v0.1.3

func (a *Activity) Block(st style.Style, frame int, sp *mark.Spinner) string

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) Elapsed added in v0.1.1

func (a *Activity) Elapsed() time.Duration

Elapsed is how long the status has been going.

func (*Activity) Line added in v0.1.1

func (a *Activity) Line(st style.Style, frame int, spinner bool) string

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

func (a *Activity) Observe(ev api.Event)

Observe takes one event: a real update replaces what the line says.

func (*Activity) Start added in v0.1.1

func (a *Activity) Start()

Start begins the status (no-op while one is going).

func (*Activity) Stop added in v0.1.1

func (a *Activity) Stop()

Stop ends the status.

func (*Activity) Text added in v0.1.1

func (a *Activity) Text() string

Text is what the status says now, without the spinner: the latest real update while it is fresh, otherwise one of Waniis's words, changing every few seconds, then the elapsed time.

type Command

type Command struct {
	Name    string
	Args    string
	Desc    string
	Aliases []string
}

Command is a slash command: its name, the argument hint and a one-line description.

func Filter

func Filter(input string) []Command

Filter returns the commands that match what has been typed after the slash: names that start with it first, then names or descriptions that contain it. "/" alone returns everything. It returns nothing once the input has a space (the name is done) or doesn't start with "/".

func Lookup

func Lookup(name string) (Command, bool)

Lookup finds a command by name or alias (without the slash, case-insensitive).

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.
	Footer func() string
	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) Clear

func (c *Console) Clear()

Clear wipes the screen.

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

func (c *Console) OpenPicker(p *Picker)

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

func (c *Console) SetStatus(line string)

SetStatus sets the live status line (already styled, no newline); "" removes it.

func (*Console) Write

func (c *Console) Write(p []byte) (int, error)

Write prints p. In raw mode "\n" becomes "\r\n" (raw mode turns output translation off), long lines are cut into rows at spaces, finished rows scroll up and the footer is drawn again below; the unfinished line stays in the footer until it ends.

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.

func NewEditor

func NewEditor() *Editor

NewEditor returns an empty editor.

func (*Editor) Handle

func (e *Editor) Handle(k Key) Result

Handle applies one key.

func (*Editor) Menu

func (e *Editor) Menu() []Command

Menu returns the commands to offer under the input line: only while the text starts with "/", has no space yet, and the menu wasn't dismissed.

func (*Editor) Reset

func (e *Editor) Reset()

Reset clears the input (after a submit).

func (*Editor) Text

func (e *Editor) Text() string

Text is what is typed.

type Key

type Key struct {
	Kind KeyKind
	Rune rune
}

Key is one decoded key press.

func Decode

func Decode(b []byte) []Key

Decode turns the bytes one terminal read returned into key presses. A read that is only ESC is the Esc key; ESC followed by more is an escape sequence (arrows, Home, End, Delete).

type KeyKind

type KeyKind int

KeyKind is what a key press means to the editor.

const (
	KeyRune KeyKind = iota
	KeyEnter
	KeyBackspace
	KeyDelete
	KeyTab
	KeyBackTab
	KeyEsc
	KeyUp
	KeyDown
	KeyLeft
	KeyRight
	KeyHome
	KeyEnd
	KeyCtrlC
	KeyCtrlD
	KeyCtrlU
	KeyCtrlW
	KeyCtrlK
	KeyCtrlL
	KeyUnknown
)

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 PickStyle added in v0.1.2

type PickStyle struct {
	Bold, Dim, Accent, Reverse func(string) string
}

PickStyle styles a Picker's lines; nil functions leave text plain.

type PickTab added in v0.1.2

type PickTab struct {
	Name   string
	Show   func(PickItem) bool // nil: every item
	Search bool
}

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

func (p *Picker) Handle(k Key) (bool, *PickItem)

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.

func (*Picker) Lines added in v0.1.2

func (p *Picker) Lines(w int, st PickStyle) []string

Lines draws the picker: a tab bar, the search field on the search tab, the rows and a hint.

func (*Picker) Visible added in v0.1.2

func (p *Picker) Visible() []PickItem

Visible is what the current tab shows.

type Result

type Result int

Result is what handling a key produced.

const (
	None      Result = iota // nothing to act on; redraw
	Submit                  // a line is ready: Editor.Line
	Interrupt               // Ctrl-C on an empty line
	EOF                     // Ctrl-D on an empty line
	ClearScr                // Ctrl-L
)

Jump to

Keyboard shortcuts

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