console

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColorReset     = "\033[0m"
	ColorBold      = "\033[1m"
	ColorDim       = "\033[2m"
	ColorItalic    = "\033[3m"
	ColorUnderline = "\033[4m"

	// Colors
	ColorRed     = "\033[31m"
	ColorGreen   = "\033[32m"
	ColorYellow  = "\033[33m"
	ColorBlue    = "\033[34m"
	ColorMagenta = "\033[35m"
	ColorCyan    = "\033[36m"
	ColorWhite   = "\033[37m"
	ColorGray    = "\033[90m"

	// Bright colors
	ColorBrightRed     = "\033[91m"
	ColorBrightGreen   = "\033[92m"
	ColorBrightYellow  = "\033[93m"
	ColorBrightBlue    = "\033[94m"
	ColorBrightMagenta = "\033[95m"
	ColorBrightCyan    = "\033[96m"
	ColorBrightWhite   = "\033[97m"

	// Background colors
	BgRed     = "\033[41m"
	BgGreen   = "\033[42m"
	BgYellow  = "\033[43m"
	BgBlue    = "\033[44m"
	BgMagenta = "\033[45m"
	BgCyan    = "\033[46m"
	BgGray    = "\033[100m"
)

ANSI color codes

Variables

This section is empty.

Functions

func ClearLineSeq added in v0.7.0

func ClearLineSeq() string

ClearLineSeq returns the escape sequence to clear the entire current line.

func ClearScreenSeq added in v0.9.0

func ClearScreenSeq() string

ClearScreenSeq returns the escape sequence to clear the entire screen.

func ClearToEndOfLineSeq added in v0.7.0

func ClearToEndOfLineSeq() string

ClearToEndOfLineSeq returns the escape sequence to clear from cursor to end of line.

func ClearToEndOfScreenSeq added in v0.9.0

func ClearToEndOfScreenSeq() string

ClearToEndOfScreenSeq returns the escape sequence to clear from cursor to end of screen.

func ClearToStartOfLineSeq added in v0.9.0

func ClearToStartOfLineSeq() string

ClearToStartOfLineSeq returns the escape sequence to clear from start of line to cursor.

func HideCursorSeq added in v0.9.0

func HideCursorSeq() string

HideCursorSeq returns the escape sequence to hide the cursor.

func HomeCursorSeq added in v0.9.0

func HomeCursorSeq() string

HomeCursorSeq returns the escape sequence to move cursor to home position (1,1).

func IsLikelyMarkdown added in v0.9.0

func IsLikelyMarkdown(text string) bool

IsLikelyMarkdown checks if text contains markdown patterns

func MoveCursorSeq added in v0.7.0

func MoveCursorSeq(x, y int) string

MoveCursorSeq returns the escape sequence to move the cursor to (x,y) Note: ANSI uses row (y) first, then column (x).

func MoveCursorToColumnSeq added in v0.9.0

func MoveCursorToColumnSeq(n int) string

MoveCursorToColumnSeq returns the escape sequence to move cursor to column n (1-based).

func MoveCursorUpSeq added in v0.9.0

func MoveCursorUpSeq(n int) string

MoveCursorUpSeq returns the escape sequence to move cursor up by n lines.

func ResetScrollRegionSeq added in v0.7.0

func ResetScrollRegionSeq() string

ResetScrollRegionSeq resets the scrolling region to the full screen.

func SetScrollRegionSeq added in v0.7.0

func SetScrollRegionSeq(top, bottom int) string

SetScrollRegionSeq returns the escape sequence to set the scrolling region (1-based, inclusive).

func ShowCursorSeq added in v0.9.0

func ShowCursorSeq() string

ShowCursorSeq returns the escape sequence to show the cursor.

Types

type CIOutputHandler added in v0.7.0

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

CIOutputHandler manages output formatting for CI/non-interactive environments

func NewCIOutputHandler added in v0.7.0

func NewCIOutputHandler(writer io.Writer) *CIOutputHandler

NewCIOutputHandler creates a new CI output handler

func (*CIOutputHandler) IsCI added in v0.7.0

func (h *CIOutputHandler) IsCI() bool

IsCI returns true if running in CI environment

func (*CIOutputHandler) IsInteractive added in v0.7.0

func (h *CIOutputHandler) IsInteractive() bool

IsInteractive returns true if running in an interactive terminal

func (*CIOutputHandler) PrintProgress added in v0.7.0

func (h *CIOutputHandler) PrintProgress()

PrintProgress prints a progress update in CI-friendly format

func (*CIOutputHandler) PrintSummary added in v0.7.0

func (h *CIOutputHandler) PrintSummary()

PrintSummary prints a final summary

func (*CIOutputHandler) Printf added in v0.7.0

func (h *CIOutputHandler) Printf(format string, args ...interface{})

Printf writes formatted output

func (*CIOutputHandler) ShouldShowProgress added in v0.7.0

func (h *CIOutputHandler) ShouldShowProgress() bool

ShouldShowProgress returns true if progress should be shown

func (*CIOutputHandler) UpdateMetrics added in v0.7.0

func (h *CIOutputHandler) UpdateMetrics(totalTokens, contextTokens, maxContextTokens, iteration int, totalCost float64)

UpdateMetrics updates the tracked metrics

func (*CIOutputHandler) Write added in v0.7.0

func (h *CIOutputHandler) Write(p []byte) (n int, err error)

Write implements io.Writer interface

func (*CIOutputHandler) WriteString added in v0.7.0

func (h *CIOutputHandler) WriteString(s string) error

WriteString writes a string with appropriate formatting

type EscapeParser added in v0.9.0

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

EscapeParser handles escape sequences using a simple state machine

func NewEscapeParser added in v0.9.0

func NewEscapeParser() *EscapeParser

NewEscapeParser creates a new escape sequence parser

func (*EscapeParser) Parse added in v0.9.0

func (ep *EscapeParser) Parse(b byte) *InputEvent

Parse processes a byte and returns an event if complete

func (*EscapeParser) Reset added in v0.9.0

func (ep *EscapeParser) Reset()

Reset the parser state

type InputEvent added in v0.7.0

type InputEvent struct {
	Type InputEventType
	Data string
}

InputEvent represents a key press or input event

type InputEventType added in v0.7.0

type InputEventType int
const (
	EventChar InputEventType = iota
	EventUp
	EventDown
	EventLeft
	EventRight
	EventHome
	EventEnd
	EventBackspace
	EventDelete
	EventEnter
	EventTab
	EventInterrupt
	EventSuspend
	EventEscape
)

type InputReader added in v0.9.0

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

InputReader handles interactive input with proper escape sequence handling

func NewInputReader added in v0.9.0

func NewInputReader(prompt string) *InputReader

NewInputReader creates a new input reader

func (*InputReader) AddToHistory added in v0.9.0

func (ir *InputReader) AddToHistory(command string)

AddToHistory adds a command to history

func (*InputReader) Backspace added in v0.9.0

func (ir *InputReader) Backspace()

Backspace deletes the character before the cursor

func (*InputReader) Delete added in v0.9.0

func (ir *InputReader) Delete()

Delete deletes the character at the cursor position

func (*InputReader) GetHistory added in v0.9.0

func (ir *InputReader) GetHistory() []string

GetHistory returns the command history

func (*InputReader) HandleEvent added in v0.9.0

func (ir *InputReader) HandleEvent(event *InputEvent)

HandleEvent processes an input event

func (*InputReader) InsertChar added in v0.9.0

func (ir *InputReader) InsertChar(char string)

InsertChar inserts a character at the cursor position

func (*InputReader) MoveCursor added in v0.9.0

func (ir *InputReader) MoveCursor(delta int)

MoveCursor moves the cursor left or right

func (*InputReader) NavigateHistory added in v0.9.0

func (ir *InputReader) NavigateHistory(direction int)

NavigateHistory navigates through command history

func (*InputReader) ReadLine added in v0.9.0

func (ir *InputReader) ReadLine() (string, error)

ReadLine reads a line of input with proper escape sequence handling

func (*InputReader) Refresh added in v0.9.0

func (ir *InputReader) Refresh()

Refresh redraws the current input line

func (*InputReader) SetCursor added in v0.9.0

func (ir *InputReader) SetCursor(pos int)

SetCursor sets the cursor to an absolute position

func (*InputReader) SetHistory added in v0.9.0

func (ir *InputReader) SetHistory(history []string)

SetHistory sets the command history

type MarkdownFormatter added in v0.9.0

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

MarkdownFormatter converts markdown to ANSI-colored terminal output

func NewMarkdownFormatter added in v0.9.0

func NewMarkdownFormatter(enableColors, enableInline bool) *MarkdownFormatter

NewMarkdownFormatter creates a new markdown formatter

func (*MarkdownFormatter) Format added in v0.9.0

func (f *MarkdownFormatter) Format(text string) string

Format formats markdown text to colored terminal output

type TerminalManager

type TerminalManager interface {
	// SaveCursor saves the current cursor position
	SaveCursor() error

	// RestoreCursor restores the cursor to the previously saved position
	RestoreCursor() error

	// MoveCursor moves the cursor to the specified position (x, y)
	MoveCursor(x, y int) error

	// WriteText writes text at the current cursor position
	WriteText(text string) error

	// Flush ensures all output is written to the terminal
	Flush() error

	// GetSize returns the terminal dimensions
	GetSize() (width, height int, err error)
}

TerminalManager defines the interface for terminal operations used by the UI rendering system.

Jump to

Keyboard shortcuts

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