Documentation ¶
Overview ¶
Package reflow supports rewriting the whitespace in a stream of runes.
Index ¶
- Constants
- type Action
- type Rule
- type Writer
- func (w *Writer) Column() error
- func (w *Writer) Decrease() error
- func (w *Writer) DisableUntil(r rune) error
- func (w *Writer) EOL() error
- func (w *Writer) Flush() error
- func (w *Writer) Increase() error
- func (w *Writer) PushRune(r rune) error
- func (w *Writer) Reset()
- func (w *Writer) StrippedEOL() error
- func (w *Writer) Whitespace(r rune) error
- func (w *Writer) Write(data []byte) (n int, err error)
- func (w *Writer) WriteRune(r rune) error
Constants ¶
const ( EOL = '¶' // outputs a line break Space = '•' // outputs a space even where it would normally be stripped Column = '║' // a column marker used to line up text Toggle = '§' // switches the formatter on or off Disable = '⋖' // switches the formatter off Enable = '⋗' // switches the formatter back on again Indent = '»' // increases the current indent level by 1 Unindent = '«' // decreases the current indent level by 1 Flush = 'ø' // flushes text, resets column detection )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
Action is the function type invoked for runes being processed by the writer. It is handed the writer and the rune that triggered it.
type Rule ¶
type Rule struct { // Rune is the rune to activate the binding for. Rune rune // Aciton is the funciton to invoke for the matching rune. Action }
Rule is an entry in the rule set that maps a rune to an action.
func AppendDefaultRules ¶
AppendDefaultRules adds the default set of rune bindings to a rule set.
The default rules are:
Whitespace at the start and end of input lines, along with the newline characters themselves will be stripped. ¶ Will be replaced by a newline. • Will be converted to a space. It will attempt to line up columns indicated by ║ in adjacent lines using a tabwriter. The indent level can be increased by » and decreased by «. § can be used to disable the reflow behaviours, and reenable them again. ø will flush the writers, reseting all column alignment behaviour.
type Writer ¶
type Writer struct { Rules []Rule // The set of rune actions to apply. Depth int // The current indentation depth. Indent string // The string to repeat as the indentation. Disabled rune // The current disabled state of the writer. Out io.Writer Tabs *tabwriter.Writer To io.Writer // contains filtered or unexported fields }
Writer is an io.Writer that uses unicode markup to reflow the text passing through it.
func New ¶
New constructs a new reflow Writer with the default indent of 2 spaces. A copy of the default rules are pre-installed in the bindings, and can be modifed at any time. See AppendDefaultRules for the set of rules installed.
func (*Writer) DisableUntil ¶
DisableUntil makes the reflow push all runes through verbatim until the next occurcence of r.
func (*Writer) Flush ¶
Flush causes any cached bytes to be flushed to the underlying stream. This has the side effect of forcing a reset of column detection.
func (*Writer) Reset ¶
func (w *Writer) Reset()
Reset reverts the stream back to the initial state, dropping column, indentation or any other state.
func (*Writer) StrippedEOL ¶
StrippedEOL indicates that an end of line character was suppressed.
func (*Writer) Whitespace ¶
Whitespace indicates that the rune should be considered whitespace.