Documentation
¶
Index ¶
- Variables
- func DisplayCells(text string, cellWidth CellWidthFunc) int
- func EscapeText(text string) string
- func GraphemeCellWidth(text string) int
- type Canvas
- type Capabilities
- type CapabilityProvider
- type CapabilityProviderFunc
- type CellWidthFunc
- type Clock
- type Config
- type Environment
- type Line
- type RawTerminal
- type Span
- type Style
- type SystemClock
Constants ¶
This section is empty.
Variables ¶
ErrWriterUnavailable is latched when a canvas is constructed without its mandatory serialized output writer.
Functions ¶
func DisplayCells ¶
func DisplayCells(text string, cellWidth CellWidthFunc) int
DisplayCells escapes text before measuring it, matching Canvas output.
func EscapeText ¶
EscapeText makes arbitrary display text inert before styling and measurement. Visible ASCII escapes preserve diagnostic meaning without letting user values move the cursor, split records, or change bidi ordering.
func GraphemeCellWidth ¶
GraphemeCellWidth follows terminal grapheme and East Asian/emoji width rules.
Types ¶
type Canvas ¶
type Canvas struct {
// contains filtered or unexported fields
}
Canvas serializes complete lines around at most one dynamic progress line. Writer failures are observable through Err but deliberately never returned from rendering calls, so diagnostics cannot become transfer authority.
func New ¶
New constructs a Canvas. Native callers should pass the serialized stderr writer here and the raw stderr handle only to NewNativeEnvironment.
func (*Canvas) Close ¶
func (canvas *Canvas) Close()
Close finishes any active progress row once and disables later output.
func (*Canvas) FinishProgress ¶
func (canvas *Canvas) FinishProgress()
FinishProgress removes the transient line and terminates its terminal row exactly once. It does not close the Canvas; later progress may start again.
func (*Canvas) Insert ¶
Insert preserves complete records, letting the terminal wrap long lines so help and diagnostics never lose content. Only the transient progress row is clipped to the current width when it is redrawn after the insertion.
func (*Canvas) ReplaceProgress ¶
ReplaceProgress replaces the active dynamic line. When cursor ANSI is not available it writes an ordinary complete line instead of using carriage-return animation.
type Capabilities ¶
Capabilities deliberately keeps terminal properties orthogonal. In particular, interactivity does not imply ANSI, and ANSI does not imply color.
type CapabilityProvider ¶
type CapabilityProvider interface {
Snapshot() Capabilities
}
CapabilityProvider is sampled at each render so resize events are observed.
type CapabilityProviderFunc ¶
type CapabilityProviderFunc func() Capabilities
CapabilityProviderFunc is a deterministic injection seam for renderers/tests.
func (CapabilityProviderFunc) Snapshot ¶
func (provider CapabilityProviderFunc) Snapshot() Capabilities
type CellWidthFunc ¶
CellWidthFunc reports terminal display cells, not bytes or runes.
type Clock ¶
Clock remains separate from terminal detection because progress sampling and ANSI policy have unrelated authorities.
type Config ¶
type Config struct {
Writer io.Writer
Capabilities CapabilityProvider
CellWidth CellWidthFunc
}
Config keeps the serialized writer independent from the raw descriptor used by native capability detection.
type Environment ¶
type Environment struct {
RawOutput RawTerminal
Capabilities CapabilityProvider
Clock Clock
}
Environment groups independently injectable native dependencies without coupling the raw terminal handle to serialized output.
func NewNativeEnvironment ¶
func NewNativeEnvironment(rawOutput RawTerminal) Environment
NewNativeEnvironment detects capabilities from the raw output while leaving actual writes to a separately supplied Canvas writer.
type Line ¶
type Line struct {
// contains filtered or unexported fields
}
Line is a complete semantic line without a trailing newline.
Its spans are private so a caller cannot mutate an active progress line while another goroutine is redrawing it.
func (Line) DisplayCells ¶
func (line Line) DisplayCells(cellWidth CellWidthFunc) int
DisplayCells reports the width of the line exactly as Canvas will display it.
type RawTerminal ¶
type RawTerminal interface {
Fd() uintptr
}
RawTerminal exposes only the native identity used for capability detection. It must remain distinct from the serialized io.Writer owned by Canvas.
type Span ¶
Span is semantic terminal text. Text may be untrusted; Canvas escapes it before measuring or writing it.
type Style ¶
type Style uint8
Style describes presentation intent without admitting terminal control bytes. The canvas remains the only component that translates intent into ANSI.
type SystemClock ¶
type SystemClock struct{}
SystemClock supplies monotonic-capable time.Time values to production callers.
func (SystemClock) Now ¶
func (SystemClock) Now() time.Time