Documentation
¶
Overview ¶
Package console provides the terminal rendering engine.
Index ¶
- type Console
- func (c *Console) ColorSystem() style.ColorSystem
- func (c *Console) Height() int
- func (c *Console) IsTerminal() bool
- func (c *Console) Log(args ...any)
- func (c *Console) Options() Options
- func (c *Console) PopRenderHook() RenderHook
- func (c *Console) Print(args ...any)
- func (c *Console) PrintMarkup(text markup.Text)
- func (c *Console) PrintSegments(segments []segment.Segment)
- func (c *Console) Printf(format string, args ...any)
- func (c *Console) Println(args ...any)
- func (c *Console) PushRenderHook(hook RenderHook)
- func (c *Console) Render(r Renderable)
- func (c *Console) RenderLines(r Renderable, opts Options) [][]segment.Segment
- func (c *Console) Rule(title string, opts ...RuleOption)
- func (c *Console) Size() Dimensions
- func (c *Console) Sprint(args ...any) string
- func (c *Console) Sprintf(format string, args ...any) string
- func (c *Console) Width() int
- func (c *Console) Write(p []byte) (n int, err error)
- func (c *Console) WriteControl(ctrl segment.Control)
- func (c *Console) WriteString(s string) (n int, err error)
- type ControlRenderable
- type Dimensions
- type Justify
- type Measurable
- type Measurement
- type Option
- type Options
- type Overflow
- type RenderHook
- type Renderable
- type RuleOption
- type Segments
- type Text
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Console ¶
type Console struct {
// contains filtered or unexported fields
}
Console handles terminal output with colors and styles.
func (*Console) ColorSystem ¶
func (c *Console) ColorSystem() style.ColorSystem
ColorSystem returns the detected color system.
func (*Console) IsTerminal ¶
IsTerminal returns true if output is a terminal.
func (*Console) PopRenderHook ¶
func (c *Console) PopRenderHook() RenderHook
PopRenderHook removes the most recently added render hook.
func (*Console) Print ¶
Print prints Rich-style markup to the console without a trailing newline.
Example:
console.Print("[bold]Hello[/] [red]World[/]")
func (*Console) PrintMarkup ¶
PrintMarkup prints pre-parsed markup segments.
func (*Console) PrintSegments ¶
PrintSegments writes segments directly to the console.
func (*Console) Printf ¶
Printf prints formatted Rich-style markup to the console without a trailing newline.
Example:
console.Printf("[bold]Count:[/] %d\n", count)
func (*Console) Println ¶ added in v1.1.0
Println prints Rich-style markup to the console with a trailing newline.
Example:
console.Println("[bold]Hello[/] [red]World[/]")
console.Println("[italic green]Success![/]")
func (*Console) PushRenderHook ¶
func (c *Console) PushRenderHook(hook RenderHook)
PushRenderHook adds a render hook.
func (*Console) Render ¶
func (c *Console) Render(r Renderable)
Render renders a Renderable to the console.
func (*Console) RenderLines ¶ added in v1.0.2
func (c *Console) RenderLines(r Renderable, opts Options) [][]segment.Segment
RenderLines renders a Renderable into lines of segments. This is used internally by table rendering to get cell content as lines.
func (*Console) Rule ¶
func (c *Console) Rule(title string, opts ...RuleOption)
Rule prints a horizontal rule with optional title.
func (*Console) Sprint ¶ added in v1.0.10
Sprint renders Rich-style markup args and returns the resulting ANSI string. Args are joined with spaces, like fmt.Sprint's space rules for non-strings.
Example:
s := console.Sprint("[bold]Hello[/] [red]World[/]")
func (*Console) Sprintf ¶ added in v1.0.10
Sprintf renders formatted Rich-style markup and returns the resulting ANSI string.
Example:
s := console.Sprintf("[bold]Count:[/] %d", count)
func (*Console) WriteControl ¶
WriteControl writes a control sequence to the console.
type ControlRenderable ¶
ControlRenderable wraps a Control as a Renderable.
type Dimensions ¶
Dimensions represents terminal dimensions in cells.
type Measurable ¶
type Measurable interface {
Measure(c *Console, opts Options) Measurement
}
Measurable is implemented by renderables that can report their width.
type Measurement ¶
Measurement represents the min and max width of a renderable.
func NewMeasurement ¶
func NewMeasurement(min, max int) Measurement
NewMeasurement creates a measurement with the given min and max.
func (Measurement) Clamp ¶
func (m Measurement) Clamp(width int) int
Clamp clamps a width to this measurement's bounds.
type Option ¶
type Option func(*Console)
Option configures a Console.
func WithColorSystem ¶
func WithColorSystem(cs style.ColorSystem) Option
WithColorSystem sets the color system.
func WithEnviron ¶
WithEnviron sets a custom environment mapping for testing. This allows overriding environment variables without modifying the actual environment. Matches Python Rich's _environ parameter pattern.
func WithForceTerminal ¶
WithForceTerminal forces terminal mode on or off.
type Options ¶
type Options struct {
Size Dimensions
MinWidth int
MaxWidth int
MaxHeight int
IsTerminal bool
ASCIIOnly bool
ColorSystem style.ColorSystem
NoWrap bool
Overflow Overflow
Justify Justify
}
Options carries rendering constraints passed to every Renderable.
func (Options) WithMaxWidth ¶
WithMaxWidth returns a copy with the given max width.
func (Options) WithNoWrap ¶
WithNoWrap returns a copy with no-wrap set.
type RenderHook ¶
type RenderHook interface {
ProcessRenderables(renderables []Renderable) []Renderable
}
RenderHook allows interception of the console's print pipeline. Used by Live to inject cursor-repositioning codes.
type Renderable ¶
Renderable is the core protocol for anything that can be rendered.
type RuleOption ¶ added in v1.0.1
type RuleOption func(*ruleConfig)
RuleOption configures Rule rendering.
func WithRuleStyle ¶ added in v1.0.1
func WithRuleStyle(s string) RuleOption
WithRuleStyle sets the style for the rule line characters.
func WithTitleStyle ¶ added in v1.0.1
func WithTitleStyle(s string) RuleOption
WithTitleStyle sets the style for the title text.