terminal

package
v0.0.0-...-cb3f5c8 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 10 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var DotsFrames = []string{"⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷"}

DotsFrames are simpler dots animation.

View Source
var SpinnerFrames = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}

SpinnerFrames are the default spinner animation frames.

Functions

func WithSpinner

func WithSpinner[T any](message string, fn func() (T, error)) (T, error)

WithSpinner runs a function with a spinner active. Returns the function result and stops the spinner appropriately.

Types

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

func NewSpinner(message string) *Spinner

NewSpinner creates a new spinner with the given message.

func NewSpinnerWithOutput

func NewSpinnerWithOutput(out io.Writer, message string) *Spinner

NewSpinnerWithOutput creates a spinner with custom output.

func (*Spinner) Elapsed

func (s *Spinner) Elapsed() time.Duration

Elapsed returns the time since the spinner started.

func (*Spinner) SetFrames

func (s *Spinner) SetFrames(frames []string) *Spinner

SetFrames sets custom animation frames.

func (*Spinner) SetMessage

func (s *Spinner) SetMessage(message string)

SetMessage updates the spinner message.

func (*Spinner) Start

func (s *Spinner) Start()

Start begins the spinner animation.

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop stops the spinner and clears the line.

func (*Spinner) StopWithError

func (s *Spinner) StopWithError(message string)

StopWithError stops and prints an error message.

func (*Spinner) StopWithMessage

func (s *Spinner) StopWithMessage(message string)

StopWithMessage stops and prints a final message.

func (*Spinner) StopWithSuccess

func (s *Spinner) StopWithSuccess(message string)

StopWithSuccess stops and prints a success message.

func (*Spinner) WithoutTime

func (s *Spinner) WithoutTime() *Spinner

WithoutTime disables elapsed time display.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer provides styled terminal output with markdown rendering.

func New

func New() *Writer

New creates a new terminal Writer with the default output (stdout).

func NewWithOutput

func NewWithOutput(out io.Writer) *Writer

NewWithOutput creates a terminal Writer with a custom output destination.

func (*Writer) Bold

func (w *Writer) Bold(format string, args ...interface{})

Bold prints bold text.

func (*Writer) Box

func (w *Writer) Box(title, content string)

Box renders content in a styled box.

func (*Writer) Code

func (w *Writer) Code(code string)

Code prints inline code.

func (*Writer) CodeBlock

func (w *Writer) CodeBlock(code, language string) error

CodeBlock prints a code block with optional language syntax highlighting.

func (*Writer) CommitMessage

func (w *Writer) CommitMessage(message string)

CommitMessage renders a git commit message with proper formatting.

func (*Writer) Confirm

func (w *Writer) Confirm(prompt string, defaultYes bool) bool

Confirm prompts for yes/no confirmation. Returns true if user confirms, false otherwise.

func (*Writer) Dim

func (w *Writer) Dim(format string, args ...interface{})

Dim prints dimmed/secondary text.

func (*Writer) Divider

func (w *Writer) Divider()

Divider prints a horizontal divider.

func (*Writer) Error

func (w *Writer) Error(format string, args ...interface{})

Error prints an error message in red.

func (*Writer) Header

func (w *Writer) Header(title string)

Header prints a section header.

func (*Writer) Info

func (w *Writer) Info(format string, args ...interface{})

Info prints an info message in blue.

func (*Writer) List

func (w *Writer) List(items []string)

List prints a bulleted list.

func (*Writer) Markdown

func (w *Writer) Markdown(md string) error

Markdown renders markdown to the terminal with syntax highlighting.

func (*Writer) Menu

func (w *Writer) Menu(title string, items []MenuItem) string

Menu displays an interactive menu and returns the selected key. Returns empty string if user cancels (Ctrl+C) or enters invalid input.

func (*Writer) Newline

func (w *Writer) Newline()

Newline prints a blank line.

func (*Writer) NumberedList

func (w *Writer) NumberedList(items []string)

NumberedList prints a numbered list.

func (*Writer) Print

func (w *Writer) Print(format string, args ...interface{})

Print writes text to the terminal.

func (*Writer) Println

func (w *Writer) Println(format string, args ...interface{})

Println writes text with a newline.

func (*Writer) Progress

func (w *Writer) Progress(current, total int, message string)

Progress prints a progress indicator.

func (*Writer) ProgressDone

func (w *Writer) ProgressDone()

ProgressDone finalizes progress output.

func (*Writer) Prompt

func (w *Writer) Prompt(prompt, defaultValue string) string

Prompt asks for text input.

func (*Writer) Stream

func (w *Writer) Stream(chunk string)

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.

func (*Writer) Success

func (w *Writer) Success(format string, args ...interface{})

Success prints a success message in green.

func (*Writer) Warn

func (w *Writer) Warn(format string, args ...interface{})

Warn prints a warning message in yellow.

Jump to

Keyboard shortcuts

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