terminal

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BoxTopLeft     = "┌"
	BoxTopRight    = "┐"
	BoxBottomLeft  = "└"
	BoxBottomRight = "┘"
	BoxHorizontal  = "─"
	BoxVertical    = "│"
	BoxTeeLeft     = "├"
	BoxTeeRight    = "┤"
	BoxTeeTop      = "┬"
	BoxTeeBottom   = "┴"
	BoxCross       = "┼"
)

Box characters for drawing

Variables

View Source
var (
	// DefaultTableStyle is the default table style
	DefaultTableStyle = TableStyle{
		HeaderColor: ColorCyan,
		BorderColor: ColorBrightBlack,
		ShowBorder:  true,
		Compact:     false,
	}

	// CompactTableStyle is a compact table style
	CompactTableStyle = TableStyle{
		HeaderColor: ColorCyan,
		BorderColor: ColorBrightBlack,
		ShowBorder:  false,
		Compact:     true,
	}
)
View Source
var (
	// DefaultListStyle is the default list style
	DefaultListStyle = ListStyle{
		BulletColor: ColorCyan,
		Indent:      2,
		Bullets:     []string{"•", "◦", "▸", "‣"},
	}

	// NumberedListStyle uses numbers
	NumberedListStyle = ListStyle{
		BulletColor: ColorCyan,
		Indent:      2,
		Bullets:     []string{"%d.", "%d)", "%d."},
	}
)
View Source
var (
	// DefaultProgressStyle is the default progress bar style
	DefaultProgressStyle = ProgressStyle{
		FilledChar:   "█",
		EmptyChar:    "░",
		LeftBracket:  "[",
		RightBracket: "]",
		Color:        ColorCyan,
	}

	// GradientProgressStyle uses gradient colors
	GradientProgressStyle = ProgressStyle{
		FilledChar:   "█",
		EmptyChar:    "░",
		LeftBracket:  "[",
		RightBracket: "]",
		Color:        ColorSuccess,
	}

	// ArrowProgressStyle uses arrows
	ArrowProgressStyle = ProgressStyle{
		FilledChar:   "▶",
		EmptyChar:    "▷",
		LeftBracket:  "⟨",
		RightBracket: "⟩",
		Color:        ColorBlue,
	}
)
View Source
var (
	// SpinnerDots is a simple dots spinner
	SpinnerDots = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}

	// SpinnerLineFrames is a line spinner
	SpinnerLineFrames = []string{"-", "\\", "|", "/"}

	// SpinnerArrow is an arrow spinner
	SpinnerArrow = []string{"←", "↖", "↑", "↗", "→", "↘", "↓", "↙"}

	// SpinnerCircle is a circle spinner
	SpinnerCircle = []string{"◐", "◓", "◑", "◒"}

	// SpinnerGrowth is a growing spinner
	SpinnerGrowth = []string{"▁", "▂", "▃", "▄", "▅", "▆", "▇", "█", "▇", "▆", "▅", "▄", "▃", "▂"}

	// SpinnerBounce is a bouncing spinner
	SpinnerBounce = []string{"⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈"}
)
View Source
var (
	// Standard ANSI colors
	ColorBlack   = Color{Code: 30}
	ColorRed     = Color{Code: 31}
	ColorGreen   = Color{Code: 32}
	ColorYellow  = Color{Code: 33}
	ColorBlue    = Color{Code: 34}
	ColorMagenta = Color{Code: 35}
	ColorCyan    = Color{Code: 36}
	ColorWhite   = Color{Code: 37}

	// Bright colors
	ColorBrightBlack   = Color{Code: 90}
	ColorBrightRed     = Color{Code: 91}
	ColorBrightGreen   = Color{Code: 92}
	ColorBrightYellow  = Color{Code: 93}
	ColorBrightBlue    = Color{Code: 94}
	ColorBrightMagenta = Color{Code: 95}
	ColorBrightCyan    = Color{Code: 96}
	ColorBrightWhite   = Color{Code: 97}

	// Presets for common use cases
	ColorCritical = Color{R: 220, G: 38, B: 38, IsRGB: true}  // Bright red
	ColorHigh     = Color{R: 251, G: 191, B: 36, IsRGB: true} // Orange/Yellow
	ColorMedium   = Color{R: 251, G: 146, B: 60, IsRGB: true} // Orange
	ColorLow      = Color{R: 59, G: 130, B: 246, IsRGB: true} // Blue
	ColorInfo     = Color{R: 99, G: 102, B: 241, IsRGB: true} // Indigo
	ColorSuccess  = Color{R: 34, G: 197, B: 94, IsRGB: true}  // Green
	ColorWarning  = Color{R: 234, G: 179, B: 8, IsRGB: true}  // Amber
	ColorError    = Color{R: 239, G: 68, B: 68, IsRGB: true}  // Red
)

Functions

This section is empty.

Types

type Color

type Color struct {
	R, G, B uint8
	IsRGB   bool
	Code    int // ANSI color code for non-RGB colors
}

Color represents a terminal color

func RGB

func RGB(r, g, b uint8) Color

RGB creates a color from RGB values

type ColorLevel

type ColorLevel int

ColorLevel represents the terminal's color capability

const (
	// ColorLevelNone represents no color support
	ColorLevelNone ColorLevel = iota
	// ColorLevelBasic represents 16-color support
	ColorLevelBasic
	// ColorLevel256 represents 256-color support
	ColorLevel256
	// ColorLevelTrueColor represents 24-bit true color support
	ColorLevelTrueColor
)

type List

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

List represents a formatted list

func (*List) Add

func (l *List) Add(text string) *List

Add adds an item to the list

func (*List) AddColored

func (l *List) AddColored(text string, color Color) *List

AddColored adds a colored item to the list

func (*List) AddWithLevel

func (l *List) AddWithLevel(text string, level int) *List

AddWithLevel adds an item with a specific indentation level

func (*List) Render

func (l *List) Render()

Render renders the list

func (*List) SetStyle

func (l *List) SetStyle(style ListStyle) *List

SetStyle sets the list style

type ListItem

type ListItem struct {
	Text   string
	Level  int
	Bullet string
	Color  Color
}

ListItem represents a single item in a list

type ListStyle

type ListStyle struct {
	BulletColor Color
	Indent      int
	Bullets     []string // Bullets for different levels
}

ListStyle defines the visual style of the list

type MultiSpinner

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

MultiSpinner manages multiple concurrent spinners

func (*MultiSpinner) Add

func (ms *MultiSpinner) Add(key, message string)

Add adds a new spinner line

func (*MultiSpinner) Fail

func (ms *MultiSpinner) Fail(key, message string)

Fail marks a spinner as failed

func (*MultiSpinner) Stop

func (ms *MultiSpinner) Stop()

Stop stops all spinners

func (*MultiSpinner) Success

func (ms *MultiSpinner) Success(key, message string)

Success marks a spinner as successful

func (*MultiSpinner) Update

func (ms *MultiSpinner) Update(key, message string)

Update updates a spinner line's message

type ProgressBar

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

ProgressBar represents a progress indicator

func (*ProgressBar) Add

func (pb *ProgressBar) Add(n int)

Add adds to the current progress

func (*ProgressBar) Finish

func (pb *ProgressBar) Finish()

Finish completes the progress bar

func (*ProgressBar) Increment

func (pb *ProgressBar) Increment()

Increment increments the progress by one

func (*ProgressBar) Set

func (pb *ProgressBar) Set(current int)

Set sets the current progress

func (*ProgressBar) SetPrefix

func (pb *ProgressBar) SetPrefix(prefix string) *ProgressBar

SetPrefix sets the prefix text

func (*ProgressBar) SetStyle

func (pb *ProgressBar) SetStyle(style ProgressStyle) *ProgressBar

SetStyle sets the progress bar style

func (*ProgressBar) SetSuffix

func (pb *ProgressBar) SetSuffix(suffix string) *ProgressBar

SetSuffix sets the suffix text

type ProgressStyle

type ProgressStyle struct {
	FilledChar   string
	EmptyChar    string
	LeftBracket  string
	RightBracket string
	Color        Color
}

ProgressStyle defines the visual style of the progress bar

type Spinner

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

Spinner represents an animated spinner

func (*Spinner) Fail

func (s *Spinner) Fail(message string)

Fail stops the spinner and shows a failure message

func (*Spinner) SetInterval

func (s *Spinner) SetInterval(interval time.Duration) *Spinner

SetInterval sets the animation interval

func (*Spinner) SetMessage

func (s *Spinner) SetMessage(message string) *Spinner

SetMessage sets the spinner message

func (*Spinner) SetStyle

func (s *Spinner) SetStyle(style Style) *Spinner

SetStyle sets the spinner style

func (*Spinner) Start

func (s *Spinner) Start() *Spinner

Start starts the spinner animation

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop stops the spinner animation

func (*Spinner) Success

func (s *Spinner) Success(message string)

Success stops the spinner and shows a success message

func (*Spinner) Warning

func (s *Spinner) Warning(message string)

Warning stops the spinner and shows a warning message

type SpinnerLine

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

SpinnerLine represents a single line in a multi-spinner

type Style

type Style struct {
	Foreground Color
	Background Color
	Bold       bool
	Italic     bool
	Underline  bool
	Dim        bool
	Blink      bool
	Reverse    bool
	Hidden     bool
	Strike     bool
}

Style represents text styling options

func NewStyle

func NewStyle() Style

NewStyle creates a new style

func (Style) WithBackground

func (s Style) WithBackground(c Color) Style

WithBackground sets the background color

func (Style) WithBold

func (s Style) WithBold() Style

WithBold enables bold text

func (Style) WithDim

func (s Style) WithDim() Style

WithDim enables dim text

func (Style) WithForeground

func (s Style) WithForeground(c Color) Style

WithForeground sets the foreground color

func (Style) WithItalic

func (s Style) WithItalic() Style

WithItalic enables italic text

func (Style) WithUnderline

func (s Style) WithUnderline() Style

WithUnderline enables underlined text

type Table

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

Table represents a formatted table

func (*Table) AddRow

func (tbl *Table) AddRow(cells ...string) *Table

AddRow adds a row to the table

func (*Table) Render

func (tbl *Table) Render()

Render renders the table

func (*Table) SetStyle

func (tbl *Table) SetStyle(style TableStyle) *Table

SetStyle sets the table style

type TableStyle

type TableStyle struct {
	HeaderColor Color
	BorderColor Color
	ShowBorder  bool
	Compact     bool
}

TableStyle defines the visual style of the table

type Terminal

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

Terminal provides intelligent terminal output capabilities

func Default

func Default() *Terminal

Default returns the default terminal instance

func New

func New(out, err io.Writer) *Terminal

New creates a new Terminal instance

func (*Terminal) Banner

func (t *Terminal) Banner(title string, width int)

Banner prints a styled banner

func (*Terminal) ClearLine

func (t *Terminal) ClearLine()

ClearLine clears the current line

func (*Terminal) ColorLevel

func (t *Terminal) ColorLevel() ColorLevel

ColorLevel returns the terminal's color capability

func (*Terminal) Divider

func (t *Terminal) Divider(char string, color Color)

Divider prints a horizontal divider

func (*Terminal) DrawBox

func (t *Terminal) DrawBox(width, height int, title string)

DrawBox draws a box with the given dimensions

func (*Terminal) Error

func (t *Terminal) Error(text string)

Error writes to stderr

func (*Terminal) ErrorMsg

func (t *Terminal) ErrorMsg(message string)

Error prints an error message (alias for Errorln)

func (*Terminal) Errorf

func (t *Terminal) Errorf(format string, args ...interface{})

Errorf writes formatted text to stderr

func (*Terminal) Errorln

func (t *Terminal) Errorln(text string)

Errorln writes to stderr with a newline

func (*Terminal) Height

func (t *Terminal) Height() int

Height returns the terminal height

func (*Terminal) HideCursor

func (t *Terminal) HideCursor()

HideCursor hides the cursor

func (t *Terminal) Hyperlink(text, url string) string

Hyperlink creates a clickable terminal hyperlink (if supported) Falls back to just showing the URL if hyperlinks aren't supported

func (*Terminal) Info

func (t *Terminal) Info(message string)

Info prints an info message

func (*Terminal) IsTTY

func (t *Terminal) IsTTY() bool

IsTTY returns true if the output is a terminal

func (*Terminal) KeyValue

func (t *Terminal) KeyValue(key, value string, keyWidth int)

KeyValue prints a key-value pair

func (*Terminal) MoveCursor

func (t *Terminal) MoveCursor(line, col int)

MoveCursor moves the cursor to the specified position

func (*Terminal) NewList

func (t *Terminal) NewList() *List

NewList creates a new list

func (*Terminal) NewMultiSpinner

func (t *Terminal) NewMultiSpinner() *MultiSpinner

NewMultiSpinner creates a new multi-spinner

func (*Terminal) NewProgressBar

func (t *Terminal) NewProgressBar(total int) *ProgressBar

NewProgressBar creates a new progress bar

func (*Terminal) NewSpinner

func (t *Terminal) NewSpinner(frames []string) *Spinner

NewSpinner creates a new spinner

func (*Terminal) NewTable

func (t *Terminal) NewTable(headers []string) *Table

NewTable creates a new table

func (*Terminal) Print

func (t *Terminal) Print(text string)

Print writes formatted text to the terminal

func (t *Terminal) PrintHyperlink(text, url string, style Style)

PrintHyperlink prints a clickable hyperlink

func (*Terminal) PrintStyled

func (t *Terminal) PrintStyled(text string, style Style)

PrintStyled writes styled text to the terminal

func (*Terminal) Printf

func (t *Terminal) Printf(format string, args ...interface{})

Printf writes formatted text to the terminal

func (*Terminal) Println

func (t *Terminal) Println(text string)

Println writes formatted text with a newline to the terminal

func (*Terminal) PrintlnStyled

func (t *Terminal) PrintlnStyled(text string, style Style)

PrintlnStyled writes styled text with a newline to the terminal

func (*Terminal) RestoreCursor

func (t *Terminal) RestoreCursor()

RestoreCursor restores the saved cursor position

func (*Terminal) SaveCursor

func (t *Terminal) SaveCursor()

SaveCursor saves the current cursor position

func (*Terminal) Section

func (t *Terminal) Section(title string)

Section prints a section header

func (*Terminal) ShowCursor

func (t *Terminal) ShowCursor()

ShowCursor shows the cursor

func (*Terminal) Success

func (t *Terminal) Success(message string)

Success prints a success message

func (*Terminal) Truncate

func (t *Terminal) Truncate(text string, maxWidth int) string

Truncate truncates text to fit the terminal width

func (*Terminal) Warning

func (t *Terminal) Warning(message string)

Warning prints a warning message

func (*Terminal) Width

func (t *Terminal) Width() int

Width returns the terminal width

func (*Terminal) Wrap

func (t *Terminal) Wrap(text string, width int) []string

Wrap wraps text to fit the terminal width

Jump to

Keyboard shortcuts

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