Documentation
¶
Index ¶
- Variables
- func Accent(s string) string
- func Ago(t time.Time) string
- func ChatFooter(cwd, name, right string) string
- func Colorless() bool
- func Danger(s string) string
- func DarkBackground() bool
- func DiffPreview(before, after string, limit int) (preview []string, added, removed int)
- func Dim(s string) string
- func Done(msg string) ui.Block
- func Duration(d time.Duration) string
- func Elapsed(d time.Duration) string
- func ErrorMsg(message string)
- func Failure(msg string) ui.Block
- func Header(version, newline string, files []string, banner string) ui.Block
- func Info(s string) string
- func InitTheme(mode string)
- func Markdown(md string) ui.Block
- func Muted(s string) string
- func Note(s string) ui.Block
- func PrintSources(sources []docsgpt.Source)
- func RenderHeader(version, keyName, baseURL, cwd string) string
- func Safe(s string) string
- func SetHyperlinks(mode string)
- func ShortPath(path string) string
- func Sources(sources []docsgpt.Source) ui.Block
- func StripControls(s string) string
- func Success(s string) string
- func Text(s string) ui.Block
- func TokenUsage(lastIn, lastOut, totalIn, totalOut int) string
- func Tokens(n int) string
- func ToolLines(lines []string)
- func ToolStatus(ok bool, msg string)
- func ToolTitle(title, note string)
- func UsePlainTheme()
- func User(text string) ui.Block
- func Warn(s string) string
- func WindowTitle(title, cwd string) string
- type Answer
- type StreamRenderer
- type TailView
- type Theme
- type ToolBlock
- func (b *ToolBlock) AddLines(lines []string)
- func (b *ToolBlock) Close(ok bool, status string)
- func (b *ToolBlock) Expand(on bool)
- func (b *ToolBlock) Expanded() bool
- func (b *ToolBlock) Folds() bool
- func (b *ToolBlock) Lines(width int) []string
- func (b *ToolBlock) Plain(width int) []ui.Plain
- func (b *ToolBlock) Start()
- func (b *ToolBlock) Write(p []byte) (int, error)
Constants ¶
This section is empty.
Variables ¶
var T = func() *Theme { lipgloss.SetHasDarkBackground(true) return newTheme() }()
T is the active theme. It starts dark without asking the terminal, so display helpers work before InitTheme runs.
Functions ¶
func Ago ¶ added in v1.7.0
Ago renders how long ago t was: "just now", "5m ago", "3h ago", "2d ago", or the date after a month.
func ChatFooter ¶ added in v1.7.0
ChatFooter is the left of the line under the chat input: the working directory, its git branch and the chat's name, fitted beside right.
func Colorless ¶ added in v1.7.0
func Colorless() bool
Colorless reports whether output must stay free of colors.
func DarkBackground ¶ added in v1.7.0
func DarkBackground() bool
DarkBackground reports the background the theme was set up for.
func DiffPreview ¶ added in v1.7.0
DiffPreview renders the first limit changed lines between before and after ("12 + text", "12 - text") and counts every added and removed line.
func Elapsed ¶ added in v1.8.0
Elapsed formats a running command's time in whole seconds: "3s", "1m 5s".
func ErrorMsg ¶
func ErrorMsg(message string)
ErrorMsg prints "✗ message" in the error color to stderr.
func Failure ¶ added in v1.7.0
Failure is "✗ message" in the error colour, without control sequences.
func Header ¶ added in v1.7.0
Header is what opens a chat: the banner (per setting, once by default), the name, the key hints and the instruction files the context sends.
func InitTheme ¶
func InitTheme(mode string)
InitTheme initializes the global theme. Mode can be "auto", "dark", or "light".
func PrintSources ¶ added in v1.7.0
PrintSources lists the sources an answer drew on, on a terminal only, after a blank line (see sourceLines).
func RenderHeader ¶
RenderHeader renders the one dim line that opens ask and chat: "docsgpt [version] · key · server · cwd". The cwd loses leading directories so the line never wraps.
func Safe ¶ added in v1.7.0
Safe makes text the model or a server controls (a command, a path, a source title) safe to print: control characters become visible symbols (␛ for ESC, ␍ for CR, ␊ for a newline), other invisible format runes (bidi overrides, zero-width) are shown as \uXXXX and invalid UTF-8 as �, so nothing can move the cursor, recolour or hide part of what the user is asked to approve. Tabs become spaces.
func SetHyperlinks ¶ added in v1.7.0
func SetHyperlinks(mode string)
SetHyperlinks sets the hyperlinks setting: "on", "off" or "auto" (or ""), which the DOCSGPT_HYPERLINKS environment variable overrides.
func ShortPath ¶ added in v1.7.0
ShortPath shows path relative to the working directory when it lies inside it, else with the home directory as ~.
func StripControls ¶ added in v1.7.0
StripControls removes terminal control sequences from text meant to be read as text (an answer, a saved chat): escape sequences whole, so no "[31m" is left behind, and every other control character but newline and tab. Unlike Safe it keeps the text as it reads, line breaks included.
func TokenUsage ¶ added in v1.7.0
TokenUsage is the footer's count of tokens sent (↑) and received (↓): the last exchange's, then the chat's when there were more ("↑2.1k ↓45 (Σ ↑12k ↓3.4k)"); "" before any.
func ToolLines ¶ added in v1.7.0
func ToolLines(lines []string)
ToolLines prints lines of a tool block (a preview). They are printed as they are, so must already be safe (DiffPreview's are).
func ToolStatus ¶ added in v1.7.0
ToolStatus closes a tool block: "✓ msg" or "✗ msg", the message dim and printed through Safe.
func ToolTitle ¶ added in v1.7.0
func ToolTitle(title, note string)
ToolTitle opens a tool block: a blank line, then title in bold. Further lines of a multi-line title are indented under the first. Title and note are printed through Safe.
func UsePlainTheme ¶
func UsePlainTheme()
UsePlainTheme swaps the active theme for the unstyled one regardless of terminal capabilities. Used when output goes to a log file instead of a terminal (host service mode).
func User ¶ added in v1.7.0
User is the block of a message the user sent: on a subtle background, or after a "❯" without colours.
func WindowTitle ¶ added in v1.7.0
WindowTitle is the terminal title of a chat: "docsgpt · <title> · <directory>", the chat's title (its name or first question) cut short.
Types ¶
type Answer ¶ added in v1.7.0
type Answer struct {
// contains filtered or unexported fields
}
Answer is a streamed answer: the model's reasoning (dim, when shown) and the markdown text. The finished markdown blocks are rendered once; only the one being written is rendered again as it grows.
func NewAnswer ¶ added in v1.7.0
NewAnswer returns an empty answer; showReasoning shows the reasoning.
func (*Answer) Content ¶ added in v1.7.0
Content returns the answer's text, without control sequences.
func (*Answer) Delta ¶ added in v1.7.0
Delta adds a streamed delta, cleaned of control sequences, and reports whether it shows anything.
type StreamRenderer ¶
type StreamRenderer struct {
ShowReasoning bool
// contains filtered or unexported fields
}
StreamRenderer prints a streamed markdown answer to stdout.
On a terminal, every finished block is rendered once and committed to scrollback. The block still being written is drawn below it and redrawn in place, but only while it fits on screen: lines that scrolled away cannot be erased, so a taller block waits until it is complete. Anywhere else the raw text is written as it arrives, and nothing more.
Either way the text loses its terminal control sequences first (see StripControls): the model must not be able to hide text, retitle or recolour the terminal, write the clipboard (OSC 52) or move the cursor under the redraws. Off a terminal too, since piped output often ends up on one (a pager, a file that is cat-ed); newlines and tabs stay.
func NewStreamRenderer ¶
func NewStreamRenderer() *StreamRenderer
NewStreamRenderer creates a StreamRenderer writing to stdout.
func (*StreamRenderer) Content ¶
func (r *StreamRenderer) Content() string
Content returns the answer so far, without control sequences.
func (*StreamRenderer) Delta ¶
func (r *StreamRenderer) Delta(delta docsgpt.Delta)
Delta processes one streamed delta. Reasoning is shown only on a terminal with ShowReasoning set, as a dim block of its own: the answer streamed so far is committed before it, and the answer resumes after a blank line.
func (*StreamRenderer) Flush ¶ added in v1.7.0
func (r *StreamRenderer) Flush()
Flush commits everything streamed so far, finished or not. Call it before anything else is printed (a tool call, an error) and at the end.
func (*StreamRenderer) Started ¶ added in v1.7.0
func (r *StreamRenderer) Started() bool
Started reports whether anything was streamed, shown or not yet.
func (*StreamRenderer) Status ¶ added in v1.7.0
func (r *StreamRenderer) Status(msg string)
Status swaps the spinner's message while it waits (a retry countdown).
func (*StreamRenderer) Wait ¶ added in v1.7.0
func (r *StreamRenderer) Wait()
Wait shows a "Thinking…" spinner on stderr until the next visible output or Flush.
type TailView ¶ added in v1.7.0
type TailView struct {
// contains filtered or unexported fields
}
TailView shows a command's output while it runs: on a terminal, only the last few lines, redrawn in place. Close leaves those lines in the scrollback below a "… N earlier lines" note.
func NewTailView ¶ added in v1.7.0
func NewTailView() *TailView
NewTailView returns a TailView drawing on stderr.
type Theme ¶
type Theme struct {
Text lipgloss.Style
Accent lipgloss.Style // prompts, headings, the selected item
Muted lipgloss.Style // secondary text, tool output
Dim lipgloss.Style // chrome, hints, metadata
Success lipgloss.Style
Warning lipgloss.Style
Error lipgloss.Style
Link lipgloss.Style
Thinking lipgloss.Style // reasoning tokens
ToolTitle lipgloss.Style // "$ command", "read path"
ToolOutput lipgloss.Style
ToolBg bool // tool blocks sit on colToolBg and friends (on a terminal)
}
Theme holds the semantic styles every UI element draws with.
type ToolBlock ¶ added in v1.7.0
type ToolBlock struct {
// contains filtered or unexported fields
}
ToolBlock shows a tool call in the transcript: its title, a preview (a diff), a command's output and a status line, on a background tinted by how it ended (as the stderr blocks of ask are). Collapsed (the default) it shows the output's last lines, expanded all it keeps: as much as the model gets (2000 lines, 50 KB).
func NewToolBlock ¶ added in v1.7.0
NewToolBlock opens a block for a tool call; title and note are shown through Safe.
func (*ToolBlock) AddLines ¶ added in v1.7.0
AddLines adds preview lines, which must be safe already (DiffPreview's are).
func (*ToolBlock) Close ¶ added in v1.7.0
Close ends the block with a status: "✓ status" or "✗ status". An empty status ends it as it is (a command the user edited before it ran).
func (*ToolBlock) Expanded ¶ added in v1.8.0
Expanded reports whether the block shows all the output kept.
func (*ToolBlock) Plain ¶ added in v1.7.0
Plain tells how the block's lines copy: without the background's padding or the indent of the lines under the title, the title unwrapped.