Documentation
¶
Overview ¶
Package terminal provides Claude Code-style terminal output with rich markdown rendering, syntax highlighting, and styled output. No TUI framework - just print/stream/scroll.
Index ¶
- Variables
- func WithSpinner[T any](message string, fn func() (T, error)) (T, error)
- type MenuItem
- type Spinner
- func (s *Spinner) Elapsed() time.Duration
- func (s *Spinner) SetFrames(frames []string) *Spinner
- func (s *Spinner) SetMessage(message string)
- func (s *Spinner) Start()
- func (s *Spinner) Stop()
- func (s *Spinner) StopWithError(message string)
- func (s *Spinner) StopWithMessage(message string)
- func (s *Spinner) StopWithSuccess(message string)
- func (s *Spinner) WithoutTime() *Spinner
- type Writer
- func (w *Writer) Bold(format string, args ...interface{})
- func (w *Writer) Box(title, content string)
- func (w *Writer) Code(code string)
- func (w *Writer) CodeBlock(code, language string) error
- func (w *Writer) CommitMessage(message string)
- func (w *Writer) Confirm(prompt string, defaultYes bool) bool
- func (w *Writer) Dim(format string, args ...interface{})
- func (w *Writer) Divider()
- func (w *Writer) Error(format string, args ...interface{})
- func (w *Writer) Header(title string)
- func (w *Writer) Info(format string, args ...interface{})
- func (w *Writer) List(items []string)
- func (w *Writer) Markdown(md string) error
- func (w *Writer) Menu(title string, items []MenuItem) string
- func (w *Writer) Newline()
- func (w *Writer) NumberedList(items []string)
- func (w *Writer) Print(format string, args ...interface{})
- func (w *Writer) Println(format string, args ...interface{})
- func (w *Writer) Progress(current, total int, message string)
- func (w *Writer) ProgressDone()
- func (w *Writer) Prompt(prompt, defaultValue string) string
- func (w *Writer) Stream(chunk string)
- func (w *Writer) StreamEnd()
- func (w *Writer) Success(format string, args ...interface{})
- func (w *Writer) Warn(format string, args ...interface{})
Constants ¶
This section is empty.
Variables ¶
var DotsFrames = []string{"⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷"}
DotsFrames are simpler dots animation.
var SpinnerFrames = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
SpinnerFrames are the default spinner animation frames.
Functions ¶
Types ¶
type MenuItem ¶
type MenuItem struct {
Key string // Keyboard shortcut (e.g., "1", "a", "q")
Label string // Display label
Description string // Optional description
Disabled bool // Greyed out if true
}
MenuItem represents a menu option.
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
Spinner provides a simple terminal spinner for async operations.
func NewSpinner ¶
NewSpinner creates a new spinner with the given message.
func NewSpinnerWithOutput ¶
NewSpinnerWithOutput creates a spinner with custom output.
func (*Spinner) SetMessage ¶
SetMessage updates the spinner message.
func (*Spinner) StopWithError ¶
StopWithError stops and prints an error message.
func (*Spinner) StopWithMessage ¶
StopWithMessage stops and prints a final message.
func (*Spinner) StopWithSuccess ¶
StopWithSuccess stops and prints a success message.
func (*Spinner) WithoutTime ¶
WithoutTime disables elapsed time display.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer provides styled terminal output with markdown rendering.
func NewWithOutput ¶
NewWithOutput creates a terminal Writer with a custom output destination.
func (*Writer) CodeBlock ¶
CodeBlock prints a code block with optional language syntax highlighting.
func (*Writer) CommitMessage ¶
CommitMessage renders a git commit message with proper formatting.
func (*Writer) Confirm ¶
Confirm prompts for yes/no confirmation. Returns true if user confirms, false otherwise.
func (*Writer) Menu ¶
Menu displays an interactive menu and returns the selected key. Returns empty string if user cancels (Ctrl+C) or enters invalid input.
func (*Writer) NumberedList ¶
NumberedList prints a numbered list.
func (*Writer) ProgressDone ¶
func (w *Writer) ProgressDone()
ProgressDone finalizes progress output.
func (*Writer) Stream ¶
Stream writes a single character or string chunk for streaming output. Use for real-time model responses.
func (*Writer) StreamEnd ¶
func (w *Writer) StreamEnd()
StreamEnd finalizes streaming output with a newline.