Documentation
¶
Overview ¶
Package exampleui provides terminal UI utilities for llama-go examples.
This package contains formatting, colour, and display utilities used by example programs. It is intentionally kept internal to avoid polluting the main library API whilst providing shared functionality across examples.
Package exampleui provides terminal UI utilities for llama-go examples.
This package contains formatting, colour, and display utilities used by example programs. It is intentionally kept internal to avoid polluting the main library API whilst providing shared functionality across examples.
Package exampleui provides terminal UI utilities for llama-go examples.
This package contains formatting, colour, and display utilities used by example programs. It is intentionally kept internal to avoid polluting the main library API whilst providing shared functionality across examples.
Package exampleui provides terminal UI utilities for llama-go examples.
This package contains formatting, colour, and display utilities used by example programs. It is intentionally kept internal to avoid polluting the main library API whilst providing shared functionality across examples.
Index ¶
- Constants
- func ColouriseField(name string, index, total int) string
- func DisplayDebugInfo(messages []llama.ChatMessage, formattedPrompt string, formatErr error)
- func DisplayModelStats(stats llama.ModelStats, maxTokens, timeout int, temp, topP float64, topK int)
- func DisplaySystemPrompt(prompt string)
- func FormatNumber(n int) string
- func GetTerminalWidth() int
- func PrintFields(fields []string)
- func PromptUser(scanner *bufio.Scanner) (string, error)
- func PromptUserSimple(scanner *bufio.Scanner) (string, error)
- func VisibleWidth(s string) int
- type StreamRenderer
- type WordWrapper
Constants ¶
const ( ColorReset = "\033[0m" ColorDim = "\033[38;5;244m" // Gray (compatible alternative to dim attribute) ColorNormal = "\033[22m" // Normal intensity ColorOrange = "\033[38;5;214m" // Bright pastel orange ColorPurple = "\033[38;5;177m" // Bright pastel purple )
ANSI colour codes for visual distinction.
Variables ¶
This section is empty.
Functions ¶
func ColouriseField ¶
ColouriseField wraps a field name with a rainbow gradient colour. Colours flow smoothly from red (hue 0°) to purple (hue 270°) based on position.
func DisplayDebugInfo ¶
func DisplayDebugInfo(messages []llama.ChatMessage, formattedPrompt string, formatErr error)
DisplayDebugInfo shows conversation history and formatted prompt for debugging.
func DisplayModelStats ¶
func DisplayModelStats(stats llama.ModelStats, maxTokens, timeout int, temp, topP float64, topK int)
DisplayModelStats renders model statistics with rainbow gradient colours and smart wrapping. It handles GPU info, metadata, runtime config, and generation parameters.
func DisplaySystemPrompt ¶
func DisplaySystemPrompt(prompt string)
DisplaySystemPrompt shows the system prompt in dimmed style.
func FormatNumber ¶
FormatNumber formats an integer with thousand separators for readability.
func GetTerminalWidth ¶
func GetTerminalWidth() int
GetTerminalWidth returns the terminal width, or 80 as fallback.
func PrintFields ¶
func PrintFields(fields []string)
PrintFields prints fields intelligently wrapped to terminal width. Each field is kept complete; multiple fields are separated by " | ".
func PromptUser ¶
PromptUser displays a coloured prompt and reads a line of input. Returns the trimmed input string and any scanner error. Returns empty string with nil error to indicate clean EOF.
func PromptUserSimple ¶
PromptUserSimple displays a simple prompt without colours (for non-streaming examples). Returns the trimmed input string and any scanner error. Returns empty string with nil error to indicate clean EOF.
func VisibleWidth ¶
VisibleWidth calculates display width excluding ANSI escape codes.
Types ¶
type StreamRenderer ¶
type StreamRenderer struct {
// contains filtered or unexported fields
}
StreamRenderer handles visual rendering of streaming chat responses. It manages reasoning vs content output, colour transitions, wrapping, and prefixes.
func NewStreamRenderer ¶
func NewStreamRenderer() *StreamRenderer
NewStreamRenderer creates a renderer with terminal-width wrapping.
func (*StreamRenderer) Finish ¶
func (r *StreamRenderer) Finish() string
Finish completes the stream rendering and returns accumulated content.
func (*StreamRenderer) GetContent ¶
func (r *StreamRenderer) GetContent() string
GetContent returns the accumulated content without finishing rendering.
func (*StreamRenderer) HandleError ¶
func (r *StreamRenderer) HandleError(err error) string
HandleError renders an error message and returns accumulated content.
func (*StreamRenderer) HandleTimeout ¶
func (r *StreamRenderer) HandleTimeout(ctxErr error) string
HandleTimeout renders a timeout message and returns accumulated content.
func (*StreamRenderer) ProcessDelta ¶
func (r *StreamRenderer) ProcessDelta(delta llama.ChatDelta)
ProcessDelta renders a single chat delta with appropriate formatting.
type WordWrapper ¶
type WordWrapper struct {
// contains filtered or unexported fields
}
WordWrapper handles word-boundary text wrapping for streaming output.
func NewWordWrapper ¶
func NewWordWrapper(maxWidth int) *WordWrapper
NewWordWrapper creates a wrapper with the given maximum line width.
func (*WordWrapper) Flush ¶
func (w *WordWrapper) Flush()
Flush outputs any remaining buffered text.
func (*WordWrapper) SetLinePos ¶
func (w *WordWrapper) SetLinePos(pos int)
SetLinePos updates the current line position (for handling prefixes).
func (*WordWrapper) Write ¶
func (w *WordWrapper) Write(text string)
Write outputs text with word-boundary wrapping.