visual

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cut

func Cut(s string, sz int) (chunks []string)

Cut cuts a string at end-of-line if the line "visual" length is shorter than the given limit or at word boundary (space) to stay as close as possible under the given limit. Should a word exists that is longer than the limit, the word is split in pieces. If provided limit is zero or less than zero, Cut only acts at end-of-line.

func LazyCut added in v0.6.1

func LazyCut(s string, sz int) (chunks []string)

LazyCut cuts a string at end-of-line if the line "visual" length is shorter than the given limit or at word boundary (space) to stay as close as possible under the given limit. Should a word exists that is longer than the limit, the word is not split to fit into the given limit ans is kept as is. If provided limit is zero or less than zero, Cut only acts at end-of-line.

func PadCenter

func PadCenter(s []byte, sz int) []byte

PadCenter equally prefixes and complete a slice of bytes with spaces until its "visual" size reaches the provided limit.

func PadLeft

func PadLeft(s []byte, sz int) []byte

PadLeft prefixes a slice of bytes with spaces until its "visual" size reaches the provided limit.

func PadRight

func PadRight(s []byte, sz int) []byte

PadRight completes a slice of bytes with spaces until its "visual" size reaches the provided limit.

func Repeat

func Repeat(s string, sz int) string

Repeat repeats s until given "visual" size is reached.

func Runewidth

func Runewidth(c rune) int

Runewidth returns the visual width of a rune.

func Stringwidth added in v0.7.0

func Stringwidth(s string) int

Stringwidth returns the "visual" width of string.

func TrimLeadingSpace added in v0.7.0

func TrimLeadingSpace(s []byte) []byte

TrimLeadingSpace trims any leading space (as defined by Unicode) from a slice of bytes.

func TrimSpace

func TrimSpace(s []byte) []byte

TrimSpace trims any leading and trailing space (as defined by Unicode) from a slice of bytes.

func TrimSuffix

func TrimSuffix(s []byte, r rune) []byte

TrimSuffix trims trailing rune r.

func TrimTrailingSpace added in v0.7.0

func TrimTrailingSpace(s []byte) []byte

TrimTrailingSpace trims any trailing space (as defined by Unicode) from a slice of bytes.

func Truncate

func Truncate(s string, limit int) string

Truncate truncates the string so that its "visible" length is lower or equal to the provided limit. When needed, Truncate terminates the string by an ansi.Reset sequence to inhibit any visual effects coming from the truncation step.

func Width added in v0.7.0

func Width(p []byte) (w int)

Width returns the "visual" width of a slice of bytes.

Types

type Cutter added in v0.7.0

type Cutter struct {
	// Maxwidth is the maximum line's "visual" length at which the Cutter
	// force a split.
	Maxwidth int
	// Lazycut flag governs the Cutter's behavior in case a word is
	// encountered whose "visual" length is longer than Cutter's MaxWidth.
	// When true, the word is kept as is, if false, the word is cut in
	// place.
	Lazycut bool
	// WordBoundaries list the byte considered as word boundaries where a
	// Cutter can split a line.
	WordBoundaries []byte
}

Cutter cuts a slice of bytes at end-of-line if the line's "visual" length is shorter than the maximum line limit or at word boundary to stay as close as possible under the maximum limit. Should a word exist that is longer than the limit, the word is either split in chunk or kept as is depending on Lazycut flag.

func NewCutter added in v0.7.0

func NewCutter(maxwidth int) *Cutter

NewCutter creates a new Cutter.

func NewLazyCutter added in v0.7.0

func NewLazyCutter(maxwidth int) *Cutter

NewLazyCutter creates a new Cutter that lazily manage word longer than maxwidth.

func (Cutter) Split added in v0.7.0

func (cutr Cutter) Split(s []byte) ([]byte, []byte)

Split cuts s at the first encountered end-of-line or at the word boundary at which the "visual" width is as close as possible (but lower than) Cutter max width. Split returns the two parts of the operation's result. Should no end-of-line nor the "visual" width be reached, result will be nil, s.

func (Cutter) SplitFunc added in v0.7.0

func (cutr Cutter) SplitFunc(data []byte, atEOF bool) (advance int, token []byte, err error)

SplitFunc implements bufio.SplitFunc for using Cutter with a bufio.Scanner.

Jump to

Keyboard shortcuts

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