bunt

package module
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: MIT Imports: 19 Imported by: 20

README

bunt

License Go Report Card Tests Codecov PkgGoDev Release GitHub go.mod Go version

Golang package for creating true color output in terminals

Documentation

Index

Constants

View Source
const (
	AUTO = state(iota)
	ON
	OFF
)

Supported setting states

Variables

View Source
var (
	Pink            = hexColor("#FFC0CB")
	LightPink       = hexColor("#FFB6C1")
	HotPink         = hexColor("#FF69B4")
	DeepPink        = hexColor("#FF1493")
	PaleVioletRed   = hexColor("#DB7093")
	MediumVioletRed = hexColor("#C71585")

	LightSalmon = hexColor("#FFA07A")
	Salmon      = hexColor("#FA8072")
	DarkSalmon  = hexColor("#E9967A")
	LightCoral  = hexColor("#F08080")
	IndianRed   = hexColor("#CD5C5C")
	Crimson     = hexColor("#DC143C")
	FireBrick   = hexColor("#B22222")
	DarkRed     = hexColor("#8B0000")
	Red         = hexColor("#FF0000")

	OrangeRed  = hexColor("#FF4500")
	Tomato     = hexColor("#FF6347")
	Coral      = hexColor("#FF7F50")
	DarkOrange = hexColor("#FF8C00")
	Orange     = hexColor("#FFA500")

	Yellow               = hexColor("#FFFF00")
	LightYellow          = hexColor("#FFFFE0")
	LemonChiffon         = hexColor("#FFFACD")
	LightGoldenrodYellow = hexColor("#FAFAD2")
	PapayaWhip           = hexColor("#FFEFD5")
	Moccasin             = hexColor("#FFE4B5")
	PeachPuff            = hexColor("#FFDAB9")
	PaleGoldenrod        = hexColor("#EEE8AA")
	Khaki                = hexColor("#F0E68C")
	DarkKhaki            = hexColor("#BDB76B")
	Gold                 = hexColor("#FFD700")

	Cornsilk       = hexColor("#FFF8DC")
	BlanchedAlmond = hexColor("#FFEBCD")
	Bisque         = hexColor("#FFE4C4")
	NavajoWhite    = hexColor("#FFDEAD")
	Wheat          = hexColor("#F5DEB3")
	BurlyWood      = hexColor("#DEB887")
	Tan            = hexColor("#D2B48C")
	RosyBrown      = hexColor("#BC8F8F")
	SandyBrown     = hexColor("#F4A460")
	Goldenrod      = hexColor("#DAA520")
	DarkGoldenrod  = hexColor("#B8860B")
	Peru           = hexColor("#CD853F")
	Chocolate      = hexColor("#D2691E")
	SaddleBrown    = hexColor("#8B4513")
	Sienna         = hexColor("#A0522D")
	Brown          = hexColor("#A52A2A")
	Maroon         = hexColor("#800000")

	DarkOliveGreen    = hexColor("#556B2F")
	Olive             = hexColor("#808000")
	OliveDrab         = hexColor("#6B8E23")
	YellowGreen       = hexColor("#9ACD32")
	LimeGreen         = hexColor("#32CD32")
	Lime              = hexColor("#00FF00")
	LawnGreen         = hexColor("#7CFC00")
	Chartreuse        = hexColor("#7FFF00")
	GreenYellow       = hexColor("#ADFF2F")
	SpringGreen       = hexColor("#00FF7F")
	MediumSpringGreen = hexColor("#00FA9A")
	LightGreen        = hexColor("#90EE90")
	PaleGreen         = hexColor("#98FB98")
	DarkSeaGreen      = hexColor("#8FBC8F")
	MediumAquamarine  = hexColor("#66CDAA")
	MediumSeaGreen    = hexColor("#3CB371")
	SeaGreen          = hexColor("#2E8B57")
	ForestGreen       = hexColor("#228B22")
	Green             = hexColor("#008000")
	DarkGreen         = hexColor("#006400")

	Aqua            = hexColor("#00FFFF")
	Cyan            = hexColor("#00FFFF")
	LightCyan       = hexColor("#E0FFFF")
	PaleTurquoise   = hexColor("#AFEEEE")
	Aquamarine      = hexColor("#7FFFD4")
	Turquoise       = hexColor("#40E0D0")
	MediumTurquoise = hexColor("#48D1CC")
	DarkTurquoise   = hexColor("#00CED1")
	LightSeaGreen   = hexColor("#20B2AA")
	CadetBlue       = hexColor("#5F9EA0")
	DarkCyan        = hexColor("#008B8B")
	Teal            = hexColor("#008080")

	LightSteelBlue = hexColor("#B0C4DE")
	PowderBlue     = hexColor("#B0E0E6")
	LightBlue      = hexColor("#ADD8E6")
	SkyBlue        = hexColor("#87CEEB")
	LightSkyBlue   = hexColor("#87CEFA")
	DeepSkyBlue    = hexColor("#00BFFF")
	DodgerBlue     = hexColor("#1E90FF")
	CornflowerBlue = hexColor("#6495ED")
	SteelBlue      = hexColor("#4682B4")
	RoyalBlue      = hexColor("#4169E1")
	Blue           = hexColor("#0000FF")
	MediumBlue     = hexColor("#0000CD")
	DarkBlue       = hexColor("#00008B")
	Navy           = hexColor("#000080")
	MidnightBlue   = hexColor("#191970")

	Lavender        = hexColor("#E6E6FA")
	Thistle         = hexColor("#D8BFD8")
	Plum            = hexColor("#DDA0DD")
	Violet          = hexColor("#EE82EE")
	Orchid          = hexColor("#DA70D6")
	Fuchsia         = hexColor("#FF00FF")
	Magenta         = hexColor("#FF00FF")
	MediumOrchid    = hexColor("#BA55D3")
	MediumPurple    = hexColor("#9370DB")
	BlueViolet      = hexColor("#8A2BE2")
	DarkViolet      = hexColor("#9400D3")
	DarkOrchid      = hexColor("#9932CC")
	DarkMagenta     = hexColor("#8B008B")
	Purple          = hexColor("#800080")
	Indigo          = hexColor("#4B0082")
	DarkSlateBlue   = hexColor("#483D8B")
	SlateBlue       = hexColor("#6A5ACD")
	MediumSlateBlue = hexColor("#7B68EE")

	White         = hexColor("#FFFFFF")
	Snow          = hexColor("#FFFAFA")
	Honeydew      = hexColor("#F0FFF0")
	MintCream     = hexColor("#F5FFFA")
	Azure         = hexColor("#F0FFFF")
	AliceBlue     = hexColor("#F0F8FF")
	GhostWhite    = hexColor("#F8F8FF")
	WhiteSmoke    = hexColor("#F5F5F5")
	Seashell      = hexColor("#FFF5EE")
	Beige         = hexColor("#F5F5DC")
	OldLace       = hexColor("#FDF5E6")
	FloralWhite   = hexColor("#FFFAF0")
	Ivory         = hexColor("#FFFFF0")
	AntiqueWhite  = hexColor("#FAEBD7")
	Linen         = hexColor("#FAF0E6")
	LavenderBlush = hexColor("#FFF0F5")
	MistyRose     = hexColor("#FFE4E1")

	Gainsboro      = hexColor("#DCDCDC")
	LightGray      = hexColor("#D3D3D3")
	Silver         = hexColor("#C0C0C0")
	DarkGray       = hexColor("#A9A9A9")
	Gray           = hexColor("#808080")
	DimGray        = hexColor("#696969")
	LightSlateGray = hexColor("#778899")
	SlateGray      = hexColor("#708090")
	DarkSlateGray  = hexColor("#2F4F4F")
	Black          = hexColor("#000000")
)

The named colors are based upon https://en.wikipedia.org/wiki/Web_colors

Functions

func Errorf added in v1.1.1

func Errorf(format string, a ...interface{}) error

Errorf wraps fmt.Errorf(err error, format string, a ...interface{}) and evaluates any text markers into its respective format

func Fprint

func Fprint(w io.Writer, a ...interface{}) (n int, err error)

Fprint wraps fmt.Fprint(w io.Writer, a ...interface{}) and evaluates any text markers into its respective format

func Fprintf

func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)

Fprintf wraps fmt.Fprintf(w io.Writer, format string, a ...interface{}) and evaluates any text markers into its respective format

func Fprintln

func Fprintln(w io.Writer, a ...interface{}) (n int, err error)

Fprintln wraps fmt.Fprintln(w io.Writer, a ...interface{}) and evaluates any text markers into its respective format

func PlainTextLength

func PlainTextLength(text string) int

PlainTextLength returns the length of the input text without any escape sequences.

func Print

func Print(a ...interface{}) (n int, err error)

Print wraps fmt.Print(a ...interface{}) and evaluates any text markers into its respective format

func Printf

func Printf(format string, a ...interface{}) (n int, err error)

Printf wraps fmt.Printf(format string, a ...interface{}) and evaluates any text markers into its respective format

func Println

func Println(a ...interface{}) (n int, err error)

Println wraps fmt.Println(a ...interface{}) and evaluates any text markers into its respective format

func RandomTerminalFriendlyColors added in v1.1.0

func RandomTerminalFriendlyColors(n int) []colorful.Color

RandomTerminalFriendlyColors creates a list of random 24 bit colors based on the 4 bit colors that most terminals support.

func RemoveAllEscapeSequences added in v1.0.1

func RemoveAllEscapeSequences(input string) string

RemoveAllEscapeSequences return the input string with all escape sequences removed.

func SetColorSettings added in v1.3.2

func SetColorSettings(color state, trueColor state)

SetColorSettings is a convenience function to set both color settings at the same time using the internal locks

func Sprint

func Sprint(a ...interface{}) string

Sprint wraps fmt.Sprint(a ...interface{}) and evaluates any text markers into its respective format

func Sprintf

func Sprintf(format string, a ...interface{}) string

Sprintf wraps fmt.Sprintf(format string, a ...interface{}) and evaluates any text markers into its respective format

func Sprintln

func Sprintln(a ...interface{}) string

Sprintln wraps fmt.Sprintln(a ...interface{}) and evaluates any text markers into its respective format

func Style

func Style(text string, styleOptions ...StyleOption) string

Style is a multi-purpose function to programmatically apply styles and other changes to an input text. The function will panic in the unlikely case of a parse issue.

func Substring

func Substring(text string, start int, end int) string

Substring returns a substring of a text that may contains escape sequences. The function will panic in the unlikely case of a parse issue.

func UseColors

func UseColors() bool

UseColors return whether colors are used or not based on the configured color setting, operating system, and terminal capabilities

func UseTrueColor

func UseTrueColor() bool

UseTrueColor returns whether true color colors should be used or not based on the configured true color usage setting or terminal capabilities

Types

type ColoredRune

type ColoredRune struct {
	Symbol   rune
	Settings uint64
}

ColoredRune is a rune with additional color information.

Bit details: - 1st bit, foreground color on/off - 2nd bit, background color on/off - 3rd bit, bold on/off - 4th bit, italic on/off - 5th bit, underline on/off - 6th-8th bit, unused/reserved - 9th-32nd bit, 24 bit RGB foreground color - 33rd-56th bit, 24 bit RGB background color - 57th-64th bit, unused/reserved

type ParseOption added in v1.0.3

type ParseOption func(*String) error

ParseOption defines parser options

func ProcessTextAnnotations added in v1.0.3

func ProcessTextAnnotations() ParseOption

ProcessTextAnnotations specifies whether during parsing bunt-specific text annotations like *bold*, or _italic_ should be processed.

type String

type String []ColoredRune

String is a string with color information

func ParseStream added in v1.2.0

func ParseStream(in io.Reader, opts ...ParseOption) (*String, error)

ParseStream reads from the input reader and parses all supported ANSI sequences that are relevant for colored strings.

Please notes: This function is still under development and should replace the `ParseString` function code eventually.

func ParseString

func ParseString(input string, opts ...ParseOption) (*String, error)

ParseString parses a string that can contain both ANSI escape code Select Graphic Rendition (SGR) codes and Markdown style text annotations, for example *bold* or _italic_. SGR details : https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters

func (String) String

func (s String) String() string

func (*String) Substring

func (s *String) Substring(from, to int)

Substring cuts the String to a sub-string using the provided absolute start and end indicies.

type StyleOption

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

StyleOption defines style option for colored strings

func Blend added in v1.0.6

func Blend() StyleOption

Blend enables that applying a color does not completely reset an existing existing color, but rather mixes/blends both colors together.

func Bold

func Bold() StyleOption

Bold applies the bold text parameter

func EachLine added in v1.0.4

func EachLine() StyleOption

EachLine enables that new line sequences will be ignored during coloring, which will lead to strings that are colored line by line and not as a block.

func EnableTextAnnotations added in v1.0.3

func EnableTextAnnotations() StyleOption

EnableTextAnnotations enables post-processing to evaluate text annotations

func Foreground

func Foreground(color colorful.Color) StyleOption

Foreground sets the given color as the foreground color of the text

func ForegroundFunc added in v1.2.1

func ForegroundFunc(f func(int, int, rune) *colorful.Color) StyleOption

ForegroundFunc uses the provided function to set an individual foreground color for each part of the text, which can be based on the position (x, y) or the content (rune) in the text.

func Italic

func Italic() StyleOption

Italic applies the italic text parameter

func Underline added in v1.0.5

func Underline() StyleOption

Underline applies the underline text parameter

type SwitchState

type SwitchState struct {
	sync.Mutex
	// contains filtered or unexported fields
}

SwitchState is the type to cover different preferences/settings like: on, off, or auto

var ColorSetting SwitchState = SwitchState{/* contains filtered or unexported fields */}

ColorSetting defines the coloring setting to be used

var TrueColorSetting SwitchState = SwitchState{/* contains filtered or unexported fields */}

TrueColorSetting defines the true color usage setting to be used

func (*SwitchState) Set added in v1.3.2

func (s *SwitchState) Set(setting string) error

Set updates the switch state based on the provided setting, or fails with an error in case the setting cannot be parsed

func (*SwitchState) String added in v1.3.2

func (s *SwitchState) String() string

func (*SwitchState) Type added in v1.3.2

func (s *SwitchState) Type() string

Type returns the type name of switch state, which is an empty string for now

Jump to

Keyboard shortcuts

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