reflow

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2019 License: Apache-2.0 Imports: 4 Imported by: 8 modules, 32 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package reflow supports rewriting the whitespace in a stream of runes.

Index

Constants

View Source
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

type Action func(w *Writer, r rune) error

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

func AppendDefaultRules(rules []Rule) []Rule

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

func New(to io.Writer) *Writer

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) Column

func (w *Writer) Column() error

Column inidcates that a column marker should be inserted for alignement.

func (*Writer) Decrease

func (w *Writer) Decrease() error

Decrease the indent level of the reflow.

func (*Writer) DisableUntil

func (w *Writer) DisableUntil(r rune) error

DisableUntil makes the reflow push all runes through verbatim until the next occurcence of r.

func (*Writer) EOL

func (w *Writer) EOL() error

EOL makes the reflow add an end of line to the output.

func (*Writer) Flush

func (w *Writer) Flush() error

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) Increase

func (w *Writer) Increase() error

Increase the indent level of the reflow.

func (*Writer) PushRune

func (w *Writer) PushRune(r rune) error

PushRune pushes a rune through the reflow logic.

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

func (w *Writer) StrippedEOL() error

StrippedEOL indicates that an end of line character was suppressed.

func (*Writer) Whitespace

func (w *Writer) Whitespace(r rune) error

Whitespace indicates that the rune should be considered whitespace.

func (*Writer) Write

func (w *Writer) Write(data []byte) (n int, err error)

Write implements io.Writer with the reflow logic.

func (*Writer) WriteRune

func (w *Writer) WriteRune(r rune) error

WriteRune writes the UTF-8 encoding of Unicode code point r, returning an error if it cannot.

Jump to

Keyboard shortcuts

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