sgr

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2025 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package sgr is a minimalist package for setting ANSI color terminal escape sequences. It implements 8 colors and several styles of the Select Graphic Rendition SGR.

Index

Constants

View Source
const Escape = "\x1b["

Escape is the leading control sequence for SGR commands.

Variables

This section is empty.

Functions

This section is empty.

Types

type Color

type Color int

Color is base terminal color.

const (
	Black Color = iota
	Red
	Green
	Yellow
	Blue
	Magenta
	Cyan
	White
	Default
)

Base values for ANSI terminal colors. Use the `FG` and `BG` methods to obtain a valid Param.

func (Color) BG

func (c Color) BG() Param

BG returns the background color SGR parameter for c.

func (Color) FG

func (c Color) FG() Param

FG returns the foreground color SGR parameter for c.

type Param

type Param int

Param is a formatted SGR parameter.

const (
	Reset Param = iota
	Bold
	Faint
	Italic
	Underline
	BlinkSlow
	BlinkRapid
	ReverseVideo
	Concealed
	CrossedOut
)

Style SGR parameters.

type Wrapped

type Wrapped struct {
	Text string // Text is the original text, not the colored value.
	// contains filtered or unexported fields
}

Wrapped represents SGR wrapped text.

func Wrap

func Wrap(p []Param, a ...any) Wrapped

Wrap applies the SGR parameters to wrap the formatted text.

func Wrapf

func Wrapf(p []Param, format string, a ...any) Wrapped

Wrapf applies the SGR parameters to wrap the formatted text.

func (Wrapped) String

func (w Wrapped) String() string

String implements the Stringer interface for w. This will be the colored text, to access the uncolored value use the `Text` field.

Directories

Path Synopsis
Package color provides default foreground and background color convenience variables.
Package color provides default foreground and background color convenience variables.

Jump to

Keyboard shortcuts

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