text

package module
v0.0.0-...-5aad845 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: MIT Imports: 6 Imported by: 2

Documentation

Overview

Package text provides a few basic text alignment and utility functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlignBottom

func AlignBottom(str string, width, height int) string

AlignBottom aligns the text to the bottom.

func AlignCenter

func AlignCenter(str string, width int) string

AlignCenter centers str. It trims and then centers all the lines in the text with space.

func AlignLeft

func AlignLeft(str string) string

AlignLeft aligns string to the left.

func AlignMiddle

func AlignMiddle(str string, width, height int) string

AlignMiddle aligns the text to the middle.

func AlignRight

func AlignRight(str string, width int) string

AlignRight aligns string to the right.

func AlignTop

func AlignTop(str string, width, height int) string

AlignTop aligns the text to the top.

func CenterText

func CenterText(str string, width int) string

CenterText centers the text by adding spaces to the left and right. It assumes the text is one line. For multiple lines use AlignCenter.

func Chunks

func Chunks(s string, length int) (res []string)

Chunks splits the string into chunks of the given length.

func ClearCode

func ClearCode(str string) string

ClearCode returns the input string without any ANSI escapes.

func JoinLines

func JoinLines(lines []*Line) string

func LineCount

func LineCount(s ...interface{}) int

LineCount returns the number of lines in the string.

func Lines

func Lines(s string) iter.Seq2[int, *Line]

func OddLength

func OddLength(s ...interface{}) bool

OddLength returns true if the length of the string is odd.

func OddVisibleLength

func OddVisibleLength(s ...interface{}) bool

OddVisibleLength returns true if the visible length of the string is odd.

func SplitLines

func SplitLines(s ...interface{}) []string

SplitLines splits the string by new line character ("\n")

func VisibleLength

func VisibleLength(s ...interface{}) int

VisibleLength returns the length of the string as seen by a human. It removes all ANSI sequences from the string.

Types

type Line

type Line struct {
	// contains filtered or unexported fields
}

Line is a single line of text.

func MapLines

func MapLines(s string, fn func(*Line) *Line) (lines []*Line)

MapLines runs the function fn on every line of the string.

func (*Line) Bytes

func (l *Line) Bytes() []byte

Bytes returns the line as a byte slice.

func (*Line) Runes

func (l *Line) Runes() []rune

Runes returns the line as a slice of runes.

func (*Line) Set

func (l *Line) Set(s string)

Set sets the line to the given string.

func (*Line) Value

func (l *Line) Value() string

Value returns the inner value of the line as a string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳