wordwrap

package
v0.1.1-0...-7170e74 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes

func Bytes(b []byte, limit int) []byte

Bytes is shorthand for declaring a new default WordWrap instance, used to immediately word-wrap a byte slice.

func HardWrap

func HardWrap(s string, limit int, tabReplace string) string

HardWrap is a shorthand for declaring a new hardwrapping WordWrap instance, since variable length characters can not be hard wrapped to a fixed length, tabs will be replaced by TabReplace, use according amount of spaces.

func String

func String(s string, limit int) string

String is shorthand for declaring a new default WordWrap instance, used to immediately word-wrap a string.

Types

type WordWrap

type WordWrap struct {
	Limit          int
	Breakpoints    []rune
	Newline        []rune
	KeepNewlines   bool
	HardWrap       bool
	TabReplace     string // since tabs can have different lengths, replace them with this when hardwrap is enabled
	PreserveSpaces bool
	// contains filtered or unexported fields
}

WordWrap contains settings and state for customisable text reflowing with support for ANSI escape sequences. This means you can style your terminal output without affecting the word wrapping algorithm.

func NewWriter

func NewWriter(limit int) *WordWrap

NewWriter returns a new instance of a word-wrapping writer, initialized with default settings.

func (*WordWrap) Bytes

func (w *WordWrap) Bytes() []byte

Bytes returns the word-wrapped result as a byte slice. Make sure to have closed the WordWrapper, before calling it.

func (*WordWrap) Close

func (w *WordWrap) Close() error

Close will finish the word-wrap operation. Always call it before trying to retrieve the final result.

func (*WordWrap) String

func (w *WordWrap) String() string

String returns the word-wrapped result as a string. Make sure to have closed the WordWrapper, before calling it.

func (*WordWrap) Write

func (w *WordWrap) Write(b []byte) (int, error)

Write is used to write more content to the word-wrap buffer.

Jump to

Keyboard shortcuts

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