chat

package
v0.1.0 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: 5 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.

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: "<id>", Desc: "Model for the next prompts"},
	{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.

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 HelpLines

func HelpLines() []string

HelpLines lists every command with its description, aligned.

Types

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
	Ed     *Editor
	Bold   func(string) string // styling for the selected menu item; nil: none
	Dim    func(string) string
	// contains filtered or unexported fields
}

Console is the chat's output. In Raw mode (a terminal in raw input mode) it keeps the input line and the command menu at the bottom: text written to it appears above them, and they are drawn again after. Otherwise it is a plain writer.

func (*Console) Clear

func (c *Console) Clear()

Clear wipes the screen.

func (*Console) Hide

func (c *Console) Hide()

Hide clears the input area, leaving the cursor at the start of an empty line.

func (*Console) Redraw

func (c *Console) Redraw()

Redraw draws the input line and menu again (after a key press).

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), and the input area is cleared before and redrawn after a finished line.

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
	KeyEsc
	KeyUp
	KeyDown
	KeyLeft
	KeyRight
	KeyHome
	KeyEnd
	KeyCtrlC
	KeyCtrlD
	KeyCtrlU
	KeyCtrlW
	KeyCtrlK
	KeyCtrlL
	KeyUnknown
)

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