wrap

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package wrap provides facilities to wrap text

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func String

func String(length int, s string) string

String is a convenience method that creates a new Wrapper, writes s to it, and then returns the written data. When s has a trailing newline, also adds a trailing newline to the return value.

Example
fmt.Println(String(20, "this text is longer than 20 characters and is wrapped accordingly"))
fmt.Println(String(20, "	(wrapping also takes leading spaces into account)"))
Output:

this text is longer
than 20 characters
and is wrapped
accordingly
	(wrapping also
	takes leading
	spaces into
	account)

func Write

func Write(writer io.Writer, length int, s string) (int, error)

Write is a convenience method that creates a new wrapper and calls the write method on it.

Types

type Wrapper

type Wrapper struct {
	Writer io.Writer
	Length int
}

Wrapper provides methods to write hard-wrapped lines to Writer.

func (Wrapper) WriteIndent

func (w Wrapper) WriteIndent(line string) (int, error)

WriteIndent determines the largest space-only prefix of line, and uses it to call WriteLinePrefix().

func (Wrapper) WriteLine

func (w Wrapper) WriteLine(line string) (int, error)

WriteLine writes a wrapped line to the output

func (Wrapper) WritePrefix

func (w Wrapper) WritePrefix(prefix, line string) (int, error)

WritePrefix writes a line with a prefix

func (Wrapper) WriteString

func (w Wrapper) WriteString(s string) (n int, err error)

WriteString splits s into lines, and then passes each line into WriteIndent. It also inserts newlines in between each line passed to WriteIndent.

Jump to

Keyboard shortcuts

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