wrap

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package wrap implements line wrapping at character or word boundaries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cells

func Cells(cells []*buffer.Cell, width int, m Mode) ([][]*buffer.Cell, error)

Cells returns the cells wrapped into individual lines according to the specified width and wrapping mode.

This function consumes any cells that contain newline characters and uses them to start new lines.

If the mode is AtWords, this function also drops cells with leading space character before a word at which the wrap occurs.

func ValidCells

func ValidCells(cells []*buffer.Cell) error

ValidCells validates the provided cells for wrapping. The text in the cells must follow the same rules as described for ValidText.

func ValidText

func ValidText(text string) error

ValidText validates the provided text for wrapping. The text must not be empty, contain any control or space characters other than '\n' and ' '.

Types

type Mode

type Mode int

Mode sets the wrapping mode.

const (
	// Never is the default wrapping mode, which disables line wrapping.
	Never Mode = iota

	// AtRunes is a wrapping mode where if the width of the text crosses the
	// width of the canvas, wrapping is performed at rune boundaries.
	AtRunes

	// AtWords is a wrapping mode where if the width of the text crosses the
	// width of the canvas, wrapping is performed at word boundaries. The
	// wrapping still switches back to the AtRunes mode for any words that are
	// longer than the width.
	AtWords
)

func (Mode) String

func (m Mode) String() string

String implements fmt.Stringer()

Jump to

Keyboard shortcuts

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