Documentation
¶
Index ¶
- Variables
- func ApplyBackgroundToANSI(text string, color lipgloss.Color) string
- func BlocksHeight(blocks []MessageContentBlock) int
- func FinalizeBlock(b *MessageContentBlock, rc RenderContext)
- func FormatDuration(d time.Duration) string
- func FormatToolCall(chroma *ChromaHighlighter, tc api.ToolCall) string
- func FormatToolCallBlock(chroma *ChromaHighlighter, tc api.ToolCall, tr *api.ToolResult, ...) string
- func FormatToolResultInline(tr *api.ToolResult, showDetails bool, toolName string) string
- func HeadingRole(role api.MessageRole) string
- func ImageErrorPlaceholder(err error) string
- func MessageDetails(msg *conversation.Message) []string
- func RenderImageToANSI(data []byte, width int) (string, error)
- func RoleStyle(role api.MessageRole) lipgloss.Style
- func ToolCallExtraArgs(tc api.ToolCall) string
- func WriteBlocks(sb *strings.Builder, blocks []MessageContentBlock) int
- type BlockKind
- type ChromaHighlighter
- func (s *ChromaHighlighter) Highlight(w io.Writer, text string) error
- func (s *ChromaHighlighter) HighlightLang(w io.Writer, text string, lang string) error
- func (s *ChromaHighlighter) HighlightLangS(text string, lang string) (string, error)
- func (s *ChromaHighlighter) HighlightS(text string) (string, error)
- type MessageContentBlock
- type RenderContext
Constants ¶
This section is empty.
Variables ¶
var ( UserRoleStyle = BoldFaint.Foreground(BrightGreen) AssistantRoleStyle = BoldFaint.Foreground(BrightBlue) SystemRoleStyle = Bold.Foreground(BrightBlack) )
var ( Black = lipgloss.Color("0") Red = lipgloss.Color("1") Green = lipgloss.Color("2") Yellow = lipgloss.Color("3") Cyan = lipgloss.Color("6") White = lipgloss.Color("7") BrightBlack = lipgloss.Color("8") BrightRed = lipgloss.Color("9") BrightGreen = lipgloss.Color("10") BrightBlue = lipgloss.Color("12") BrightWhite = lipgloss.Color("15") )
ANSI color palette used across the TUI.
var ( Faint = lipgloss.NewStyle().Faint(true) Bold = lipgloss.NewStyle().Bold(true) BoldFaint = lipgloss.NewStyle().Bold(true).Faint(true) )
Shared style primitives.
var ( // Header is the top bar background style. Header = lipgloss.NewStyle(). Padding(0, 1). Background(Black) Footer = lipgloss.NewStyle().Padding(0, 1) // Selected is the accent style for highlighted items. Selected = Faint.Foreground(Cyan) // HelpPanel is the border+padding style for the help overlay. HelpPanel = lipgloss.NewStyle(). Padding(0, 2). Border(lipgloss.NormalBorder(), true, false, false, false). BorderForeground(BrightBlack) )
Semantic styles shared across views.
var ( ToolCallNameStyle = Bold.Foreground(Yellow) ToolCallArgStyle = Faint )
var ToolCallLang = map[string]string{
"Bash": "bash",
"Python": "python",
}
ToolCallLang maps tool names to their syntax-highlight language.
Functions ¶
func ApplyBackgroundToANSI ¶ added in v0.6.0
ApplyBackgroundToANSI re-applies a background colour after every ANSI reset in the given text, and ensures a final reset. This allows Chroma-highlighted output (which resets formatting between tokens) to retain a background.
func BlocksHeight ¶
func BlocksHeight(blocks []MessageContentBlock) int
BlocksHeight returns the number of visual lines in the joined block content without building a string.
func FinalizeBlock ¶
func FinalizeBlock(b *MessageContentBlock, rc RenderContext)
FinalizeBlock applies word-wrapping and block styling to a block based on the render context. Image blocks are not wrapped (they are pre-sized) but still receive the block style (padding).
func FormatDuration ¶
FormatDuration formats a duration for display (tenths of seconds minimum).
func FormatToolCall ¶
func FormatToolCall(chroma *ChromaHighlighter, tc api.ToolCall) string
FormatToolCall renders a tool call in function-call notation with styling. Known tools are syntax-highlighted by language; all other tools' primary arguments are rendered in faint gray. Multi-line arguments are indented:
Bash(
cd somewhere && long_command \
--flag value
)
func FormatToolCallBlock ¶
func FormatToolCallBlock(chroma *ChromaHighlighter, tc api.ToolCall, tr *api.ToolResult, rc RenderContext) string
FormatToolCallBlock renders a tool call block for message content display. In non-detailed mode, renders just the function-call line (e.g. Grep(pattern)). In detailed mode, adds extra key=value arguments below; for Edit and Write, shows a unified diff inside the parentheses instead of the file path. When a toolResult is provided, it is used to determine whether to render the actual file diff (success) or the proposed diff (before execution / failure).
func FormatToolResultInline ¶
func FormatToolResultInline(tr *api.ToolResult, showDetails bool, toolName string) string
FormatToolResultInline renders a tool result directly underneath its tool call block. In detailed mode, multi-line results are shown indented. In non-detailed mode, single-line results are shown inline and multi-line results are collapsed to "(N lines)". For Edit and Write tools with a successful result (>1 line), "success" is shown.
func HeadingRole ¶
func HeadingRole(role api.MessageRole) string
HeadingRole returns the display name for a message role in a heading context. ToolCall messages display as "Assistant".
func ImageErrorPlaceholder ¶
ImageErrorPlaceholder returns a placeholder string for a failed image render.
func MessageDetails ¶
func MessageDetails(msg *conversation.Message) []string
MessageDetails returns metadata detail strings for a message heading (model, timing). The caller can prepend additional details (e.g. a timestamp) and format the joined result.
func RenderImageToANSI ¶
RenderImageToANSI renders image data to an ANSI symbol-art string in-process via chafa-go. width is the desired terminal column width; height is calculated automatically from the image aspect ratio.
func RoleStyle ¶
func RoleStyle(role api.MessageRole) lipgloss.Style
RoleStyle returns the heading style for a message role.
func ToolCallExtraArgs ¶
ToolCallExtraArgs returns space-separated key=value pairs for non-primary, non-trivial parameters of a tool call (sorted alphabetically).
func WriteBlocks ¶
func WriteBlocks(sb *strings.Builder, blocks []MessageContentBlock) int
WriteBlocks appends the contents of blocks to sb, separated by blank lines. It returns the number of visual lines written. Blocks should be finalized (no trailing newlines) before calling WriteBlocks.
Types ¶
type BlockKind ¶
type BlockKind int
BlockKind identifies the kind of a rendered content block within a message.
type ChromaHighlighter ¶
type ChromaHighlighter struct {
// contains filtered or unexported fields
}
func NewChromaHighlighter ¶
func NewChromaHighlighter(lang, format, style string) *ChromaHighlighter
func (*ChromaHighlighter) Highlight ¶
func (s *ChromaHighlighter) Highlight(w io.Writer, text string) error
func (*ChromaHighlighter) HighlightLang ¶
func (*ChromaHighlighter) HighlightLangS ¶
func (s *ChromaHighlighter) HighlightLangS(text string, lang string) (string, error)
func (*ChromaHighlighter) HighlightS ¶
func (s *ChromaHighlighter) HighlightS(text string) (string, error)
type MessageContentBlock ¶
MessageContentBlock represents a single rendered content block within a message. Messages are composed of one or more blocks — thinking, text, image, tool calls with inline results, and retry hints — each independently cacheable.
func BuildMessageBlocks ¶
func BuildMessageBlocks( chroma *ChromaHighlighter, msg *conversation.Message, rc RenderContext, ) []MessageContentBlock
BuildMessageBlocks produces the ordered content blocks for a message by iterating its content parts directly. Each thinking, text, or image part becomes its own block. Image parts are rendered synchronously via chafa when rc.ImageWidth > 0; otherwise they are skipped.
When rc.Raw is true, markdown syntax highlighting is skipped for text blocks (used by the streaming fast-path tail rendering).
type RenderContext ¶
type RenderContext struct {
ShowDetails bool // show full tool parameters, results, message metadata
Cursor string // streaming cursor; appears before closing </thinking> for reasoning-only, or after text
ToolResults []api.ToolResult // results from the next ToolResult message for inline rendering under tool calls
ResultHint bool // render "(press ctrl+r to retry)" hint for selected ToolResult messages
ConfirmedCount int // how many tool calls to render: -1 = all, 0 = hide (awaiting confirmation), N = first N
Raw bool // skip markdown syntax highlighting (fast-path tail rendering)
WrapWidth int // content width for word-wrapping blocks (0 = no wrapping)
ImageWidth int // terminal column width for image rendering (0 = skip images)
BlockStyle *lipgloss.Style // per-block padding/style baked into cached block content (nil = skip lipgloss)
SandboxCfg *sandbox.ToolSandboxConfig // sandbox config for translating paths when computing diffs
}
RenderContext holds the per-message rendering parameters that depend on current UI state (streaming cursor, confirmation progress, etc.).