Documentation
¶
Overview ¶
Package attributes exposes an interface that knows how to deal with text presentation attributes (color, typeface, etc).
A Renderer is a unitary block of text, with an (optional) presentation context (StartSequence, EndSequence).
A sequence may typically be a terminal ANSI SGR escape sequence, but any tag language (e.g. HTML, LaTeX) works with a similar logic.
The State is a chained list of Renderers to track the context of Start/Stop sequences.
Index ¶
- type Attribute
- func (a Attribute) HasStart() bool
- func (a Attribute) HasStop() bool
- func (a Attribute) Level() int
- func (a Attribute) Render(w runesio.Writer)
- func (a Attribute) Runes() []rune
- func (a *Attribute) SetLevel(level int)
- func (a *Attribute) SetStop(stop []rune)
- func (a Attribute) Start(w runesio.Writer)
- func (a Attribute) Stop(w runesio.Writer)
- type Iterator
- type Renderer
- type Renderers
- type State
- type StateIterator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attribute ¶
Attribute implements a basic renderer.
The start and stop mode are rendered simply by writing their runes. This typically corresponds to a terminal use-case with ANSI escape sequences.
type Iterator ¶
type Iterator interface {
// Next indicates if there is a next item to be consumed.
Next() bool
// Item returns the currently iterated Renderer.
Item() Renderer
}
Iterator walks a chained list of Renderers.
type Renderer ¶
type Renderer interface {
// Start renders the start formatting sequence, if any.
Start(runesio.Writer)
// Start renders the stop formatting sequence, if any.
Stop(runesio.Writer)
// Runes renders the runes of the token, without formatting sequences.
Runes() []rune
// Level indicates the level of nested start/stop sequences.
Level() int
// SetLevel sets the level of nested start/stop sequences.
SetLevel(int)
// HasStart is true when the renderer contains a start sequence.
HasStart() bool
// HasStop is true when the renderer contains a stop sequence.
HasStop() bool
// Render knows how to render the token with the formatting sequences.
Render(runesio.Writer)
SetStop([]rune)
}
Renderer knows how to
type State ¶
type State struct {
// contains filtered or unexported fields
}
State maintains the state of attribute renderers.
The state is constructed from a flow of Renderers using Push().
func (*State) First ¶
func (s *State) First() *StateIterator
func (*State) Iterator ¶
func (s *State) Iterator() *StateIterator
Iterator yields an iterator to walk over the renderers in this State, from first to last.
type StateIterator ¶
type StateIterator struct {
// contains filtered or unexported fields
}
StateIterator iterates over the list of renderers.
A StateIterator knows how to close the current rendering context when reaching the end of line, and to resume the previous rendering context when starting a new line.
func (*StateIterator) EndOfLine ¶
func (i *StateIterator) EndOfLine(w runesio.Writer)
EndOfLine closes the state of attributes to end the line with an empty state.
func (*StateIterator) Item ¶
func (i *StateIterator) Item() Renderer
Item returns the currently iterated Renderer.
func (*StateIterator) Next ¶
func (i *StateIterator) Next() bool
Next yields true if there are more items to consume.
func (*StateIterator) StartOfLine ¶
func (i *StateIterator) StartOfLine(w runesio.Writer)
StartOfLine restores the state of attributes to start a new line.