Documentation
¶
Overview ¶
Package segment provides the atomic rendering unit for terminal output.
Index ¶
- func Divide(segments []Segment, cuts []int) [][]Segment
- func LastStyle(segments []Segment) *style.Style
- func SplitLines(segments []Segment) [][]Segment
- func TotalCellLength(segments []Segment) int
- type Control
- func BeginSyncUpdate() Control
- func CarriageReturn() Control
- func CursorBackward(n int) Control
- func CursorDown(n int) Control
- func CursorForward(n int) Control
- func CursorMoveTo(x, y int) Control
- func CursorUp(n int) Control
- func EndSyncUpdate() Control
- func EraseInDisplay(mode int) Control
- func EraseInLine(mode int) Control
- func HideCursor() Control
- func NewControl(codes ...ControlCode) Control
- func SetTitle(title string) Control
- func ShowCursor() Control
- type ControlCode
- type ControlType
- type Segment
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Divide ¶
Divide divides segments at the given cell positions. Returns len(cuts)+1 slices of segments.
func LastStyle ¶ added in v1.1.2
LastStyle returns the Style of the last non-control segment, or nil.
func SplitLines ¶
SplitLines splits segments by newlines, returning lines of segments.
func TotalCellLength ¶
TotalCellLength returns the total cell length of a slice of segments.
Types ¶
type Control ¶
type Control struct {
Codes []ControlCode
}
Control is a renderable that produces terminal control sequences.
func BeginSyncUpdate ¶ added in v1.0.8
func BeginSyncUpdate() Control
BeginSyncUpdate creates a control that opens a synchronized output frame (DEC private mode 2026). Terminals that support it buffer everything until EndSyncUpdate and paint it atomically, eliminating flicker. Unsupported terminals ignore the unknown mode.
func CarriageReturn ¶
func CarriageReturn() Control
CarriageReturn creates a control for carriage return.
func CursorBackward ¶
CursorBackward creates a control to move the cursor backward n columns.
func CursorDown ¶
CursorDown creates a control to move the cursor down n lines.
func CursorForward ¶
CursorForward creates a control to move the cursor forward n columns.
func CursorMoveTo ¶
CursorMoveTo creates a control to move the cursor to (x, y).
func EndSyncUpdate ¶ added in v1.0.8
func EndSyncUpdate() Control
EndSyncUpdate creates a control that closes a synchronized output frame.
func EraseInDisplay ¶
EraseInDisplay creates a control to erase in the display. mode: 0 = cursor to end, 1 = start to cursor, 2 = entire display, 3 = entire display + scrollback
func EraseInLine ¶
EraseInLine creates a control to erase in the current line. mode: 0 = cursor to end, 1 = start to cursor, 2 = entire line
func NewControl ¶
func NewControl(codes ...ControlCode) Control
NewControl creates a new Control with the given codes.
type ControlCode ¶
type ControlCode struct {
Type ControlType
Params []int
Text string // For SetTitle/SetWindowTitle
}
ControlCode represents a control operation with optional parameters.
func (ControlCode) Render ¶
func (cc ControlCode) Render() string
Render produces the ANSI escape sequence for this control code.
type ControlType ¶
type ControlType int
ControlType represents a terminal control operation.
const ( ControlCarriageReturn ControlType = iota ControlShowCursor ControlHideCursor ControlCursorUp ControlCursorDown ControlCursorForward ControlCursorBackward ControlCursorMoveTo ControlEraseInLine ControlEraseInDisplay ControlSetTitle ControlBeginSyncUpdate ControlEndSyncUpdate )
type Segment ¶
type Segment struct {
Text string
Style *style.Style
Control []ControlCode // Non-nil means this is a control segment
}
Segment is the atomic unit of terminal rendering. A segment is either styled text or a control sequence.
func AdjustLineLength ¶
AdjustLineLength adjusts a line of segments to the given cell width. If pad is true, shorter lines are padded with spaces. Longer lines are truncated.
func ApplyStyle ¶
ApplyStyle applies a style to all segments.
func NewControlSegment ¶
func NewControlSegment(codes ...ControlCode) Segment
NewControl creates a control segment.
func (Segment) CellLength ¶
CellLength returns the number of terminal cells this segment occupies. Control segments have zero cell length.