printer

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 5, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Newline = &newlineType{}

Newline is a text Component that inserts a new line.

Functions

This section is empty.

Types

type BasicComponent

type BasicComponent interface {
	Component

	// Render renders the component to string buffer.
	Render(*Renderer)
	// contains filtered or unexported methods
}

BasicComponent is either a [newlineType] or a Text.

type Component

type Component interface {

	// Simplify returns a flattened and and simplified the component in an inside-out order.
	// This is similar to how a AST optimizer would do it.
	Simplify(*Renderer) []BasicComponent
}

Component is an abstract representation of some unit of printable text.

type LinePrefix

type LinePrefix struct {
	Prefix Component
	Child  Component
}

LinePrefix adds a prefix to each line.

func (*LinePrefix) Simplify

func (c *LinePrefix) Simplify(r *Renderer) []BasicComponent

Simplify implements Component

type Renderer

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

Renderer is responsible for rendering Component into strings. To prevent unnecessary computation, this is caches simplification steps.

func NewRenderer

func NewRenderer() *Renderer

func (*Renderer) Render

func (r *Renderer) Render(c Component)

func (*Renderer) Simplify

func (r *Renderer) Simplify(c Component) []BasicComponent

Simplify should be used by [Component]s to render their contents.

func (*Renderer) String

func (r *Renderer) String() string

func (*Renderer) WriteString

func (r *Renderer) WriteString(s string)

WriteString should be used by [Component]s to render their contents.

type Sequence

type Sequence struct {
	Children []Component
}

Sequence contains zero or more child [Component]s in an ordered sequence.

func (*Sequence) Append

func (c *Sequence) Append(children ...Component)

Append adds a new child Component to the end of the sequence.

func (*Sequence) Simplify

func (c *Sequence) Simplify(r *Renderer) []BasicComponent

Simplify implements Component

type Text

type Text struct {
	Color string
	Text  string
}

Text is for a regular string of text. This may or may not have color.

func (*Text) Render

func (c *Text) Render(r *Renderer)

Render implements Component

func (*Text) Simplify

func (c *Text) Simplify(r *Renderer) []BasicComponent

Simplify implements Component

When Text is simplified, it is split up into individual lines.

type Trim

type Trim struct {
	Leading  bool
	Trailing bool
	Child    Component
}

Trim is a text Component that can trim leading or trailing newlines.

func (*Trim) Simplify

func (c *Trim) Simplify(r *Renderer) []BasicComponent

Jump to

Keyboard shortcuts

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