color

package
v0.0.0-...-466e094 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2025 License: MIT Imports: 3 Imported by: 2

Documentation

Overview

Package color makes it easy to output formatted text (via tput or output codes depending on the operating system). tput is preferred when possible as that doesn't modify the text passed to downstream commands See the tput documentation for more info: https://linuxcommand.org/lc3_adv_tput.php This package is specifically implemented to work well with the base `command` package, both in terms of usage and testing.

Index

Constants

This section is empty.

Variables

View Source
var (
	Black   = &ColorCode{0, true}
	Red     = &ColorCode{1, true}
	Green   = &ColorCode{2, true}
	Yellow  = &ColorCode{3, true}
	Blue    = &ColorCode{4, true}
	Magenta = &ColorCode{5, true}
	Cyan    = &ColorCode{6, true}
	White   = &ColorCode{7, true}

	Reset        = newEffect(0, "init")
	Bold         = newEffect(1, "bold")
	Underline    = newEffect(4, "smul")
	EndUnderline = newEffect(24, "rmul")
)

Functions

func Apply

func Apply(s string, fs ...Format) string

Apply applies the provided format to the string and then resets the format.

func OutputCode

func OutputCode(fs ...Format) string

OutputCode gets the output codes for the provided `Formats`. Note: the callers of this package are responsible for applying the `Reset` format.

Types

type ColorCode

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

ColorCode is the color code for tput and for the output format `\033[0;(30+X)m`.

func (*ColorCode) Background

func (c *ColorCode) Background() *ColorCode

type Effect

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

Effect is an effect that defines separate code and tput args.

type Format

type Format interface {
	// contains filtered or unexported methods
}

Format is a format (bold, color, etc.) that can be applied to output. This package defines a handful of these for the typical use cases.

func MultiFormat

func MultiFormat(fs ...Format) Format

Directories

Path Synopsis
Package colorreset provides a CLI that clears all color formatting done by the github.com/leep-frog/command/color package.
Package colorreset provides a CLI that clears all color formatting done by the github.com/leep-frog/command/color package.

Jump to

Keyboard shortcuts

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