display

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 39 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

Index

Constants

This section is empty.

Variables

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

func Accent(s string) string

Accent renders text in the accent color (prompts, headings).

func Ago added in v1.7.0

func Ago(t time.Time) string

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

func ChatFooter(cwd, name, right string) string

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 Danger

func Danger(s string) string

Danger renders text in the error color.

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

func DiffPreview(before, after string, limit int) (preview []string, added, removed int)

DiffPreview renders the first limit changed lines between before and after ("12 + text", "12 - text") and counts every added and removed line.

func Dim added in v1.7.0

func Dim(s string) string

Dim renders text in the dim color (chrome, hints, metadata).

func Done added in v1.7.0

func Done(msg string) ui.Block

Done is a "✓" and a dim notice.

func Duration added in v1.7.0

func Duration(d time.Duration) string

Duration formats d like "0.3s", "1m 5s".

func Elapsed added in v1.8.0

func Elapsed(d time.Duration) string

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

func Failure(msg string) ui.Block

Failure is "✗ message" in the error colour, without control sequences.

func Header(version, newline string, files []string, banner string) ui.Block

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 Info

func Info(s string) string

Info renders text in the link color.

func InitTheme

func InitTheme(mode string)

InitTheme initializes the global theme. Mode can be "auto", "dark", or "light".

func Markdown added in v1.7.0

func Markdown(md string) ui.Block

Markdown is a block of rendered markdown (an answer shown again).

func Muted

func Muted(s string) string

Muted renders text in the muted/secondary color.

func Note added in v1.7.0

func Note(s string) ui.Block

Note is a dim notice, wrapped to the width.

func PrintSources added in v1.7.0

func PrintSources(sources []docsgpt.Source)

PrintSources lists the sources an answer drew on, on a terminal only, after a blank line (see sourceLines).

func RenderHeader

func RenderHeader(version, keyName, baseURL, cwd string) string

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

func Safe(s string) string

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(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

func ShortPath(path string) string

ShortPath shows path relative to the working directory when it lies inside it, else with the home directory as ~.

func Sources added in v1.7.0

func Sources(sources []docsgpt.Source) ui.Block

Sources is the "Sources" block of an answer, empty without any.

func StripControls added in v1.7.0

func StripControls(s string) string

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 Success

func Success(s string) string

Success renders text in the success color.

func Text added in v1.7.0

func Text(s string) ui.Block

Text is a block of lines that are styled already.

func TokenUsage added in v1.7.0

func TokenUsage(lastIn, lastOut, totalIn, totalOut int) string

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 Tokens added in v1.7.0

func Tokens(n int) string

Tokens renders a count compactly: 950, 1.2k, 12k, 1.5M.

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

func ToolStatus(ok bool, msg string)

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

func User(text string) ui.Block

User is the block of a message the user sent: on a subtle background, or after a "❯" without colours.

func Warn

func Warn(s string) string

Warn renders text in the warning color.

func WindowTitle added in v1.7.0

func WindowTitle(title, cwd string) string

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

func NewAnswer(showReasoning bool) *Answer

NewAnswer returns an empty answer; showReasoning shows the reasoning.

func (*Answer) Content added in v1.7.0

func (a *Answer) Content() string

Content returns the answer's text, without control sequences.

func (*Answer) Delta added in v1.7.0

func (a *Answer) Delta(d docsgpt.Delta) bool

Delta adds a streamed delta, cleaned of control sequences, and reports whether it shows anything.

func (*Answer) Finish added in v1.7.0

func (a *Answer) Finish()

Finish marks the answer complete: its last block is final.

func (*Answer) Lines added in v1.7.0

func (a *Answer) Lines(width int) []string

func (*Answer) Plain added in v1.7.0

func (a *Answer) Plain(width int) []ui.Plain

Plain tells how the answer's lines copy: the reasoning and the markdown, unwrapped.

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.

func (*TailView) Close added in v1.7.0

func (v *TailView) Close()

Close stops the live region and prints the final tail.

func (*TailView) Write added in v1.7.0

func (v *TailView) Write(p []byte) (int, error)

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

func NewToolBlock(title, note string) *ToolBlock

NewToolBlock opens a block for a tool call; title and note are shown through Safe.

func (*ToolBlock) AddLines added in v1.7.0

func (b *ToolBlock) AddLines(lines []string)

AddLines adds preview lines, which must be safe already (DiffPreview's are).

func (*ToolBlock) Close added in v1.7.0

func (b *ToolBlock) Close(ok bool, status string)

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) Expand added in v1.7.0

func (b *ToolBlock) Expand(on bool)

Expand shows all the output kept (on) or its last lines.

func (*ToolBlock) Expanded added in v1.8.0

func (b *ToolBlock) Expanded() bool

Expanded reports whether the block shows all the output kept.

func (*ToolBlock) Folds added in v1.7.0

func (b *ToolBlock) Folds() bool

Folds reports whether collapsing hides output lines.

func (*ToolBlock) Lines added in v1.7.0

func (b *ToolBlock) Lines(width int) []string

func (*ToolBlock) Plain added in v1.7.0

func (b *ToolBlock) Plain(width int) []ui.Plain

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.

func (*ToolBlock) Start added in v1.8.0

func (b *ToolBlock) Start()

Start marks the command as running: until Close the block shows for how long ("running · 3s"), from its first second, each time it is drawn.

func (*ToolBlock) Write added in v1.7.0

func (b *ToolBlock) Write(p []byte) (int, error)

Write adds a command's output.

Jump to

Keyboard shortcuts

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