styled

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package styled builds text made of styled runs, printed either plain or with ANSI escape codes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Style

type Style uint8

Style is a set of text attributes: at most one color, optionally bold.

const (
	Plain Style = 0
	Bold  Style = 1 << iota
	Red
	Green
	Blue
	Gray
)

Styles.

type Text

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

Text is a sequence of styled runs; adjacent runs of the same style are merged, so a single escape sequence covers them.

func (*Text) Append

func (t *Text) Append(o Text)

Append appends the runs of o.

func (Text) HasSuffix

func (t Text) HasSuffix(s string) bool

HasSuffix reports whether the unstyled text ends with s.

func (*Text) Push

func (t *Text) Push(s string, st Style)

Push appends s with style st; an empty s is ignored.

func (Text) Split

func (t Text) Split(sep string) []Text

Split cuts t around each sep, keeping the styles; like strings.Split, n separators give n+1 parts.

func (Text) String

func (t Text) String(color bool) string

String returns the text, with ANSI escape codes when color is true.

Jump to

Keyboard shortcuts

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