color

package
v1.24.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package color is a modification of https://github.com/fatih/color/blob/master/color.go

Index

Constants

View Source
const (
	ButtonBackgroundColor = tcell.ColorGray

	FieldBackgroundColor = tcell.ColorGray

	TitleColor = tcell.Color87

	ModalBackgroundColor = tcell.ColorOrangeRed
)

Variables

View Source
var (
	// NoColor defines if the output is colorized or not. It's dynamically set to
	// false or true based on the stdout's file descriptor referring to a terminal
	// or not. This is a global option and affects all colors. For more control
	// over each color block use the methods DisableColor() individually.
	NoColor = os.Getenv("TERM") == "dumb" ||
		(!isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd()))

	// Output defines the standard output of the print functions. By default
	// os.Stdout is used.
	Output = colorable.NewColorableStdout()

	// Error defines a color supporting writer for os.Stderr.
	Error = colorable.NewColorableStderr()
)
View Source
var (
	// Section is used for sections
	Section = New(FgHiYellow, Underline).Sprintf

	// Primary is used for primary texts
	Primary = SHiCyan

	// Secondary is used for secondary texts
	Secondary = SHiGreen

	// Flag is used for global and local flags
	Flag = SGreen

	// Separator is used for separators
	Separator = SRed

	// R resets the color
	R = New(Reset).Sprintf("")
)

Functions

func Blackf added in v1.19.0

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

Blackf is a convenient helper function to print with black foreground. A newline is appended to format by default.

func Bluef added in v1.19.0

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

Bluef is a convenient helper function to print with blue foreground. A newline is appended to format by default.

func Cyanf added in v1.19.0

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

Cyanf is a convenient helper function to print with cyan foreground. A newline is appended to format by default.

func Greenf added in v1.19.0

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

Greenf is a convenient helper function to print with green foreground. A newline is appended to format by default.

func HiBlackf added in v1.19.0

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

HiBlackf is a convenient helper function to print with hi-intensity black foreground. A newline is appended to format by default.

func HiBluef added in v1.19.0

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

HiBluef is a convenient helper function to print with hi-intensity blue foreground. A newline is appended to format by default.

func HiCyanf added in v1.19.0

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

HiCyanf is a convenient helper function to print with hi-intensity cyan foreground. A newline is appended to format by default.

func HiGreenf added in v1.19.0

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

HiGreenf is a convenient helper function to print with hi-intensity green foreground. A newline is appended to format by default.

func HiMagentaf added in v1.19.0

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

HiMagentaf is a convenient helper function to print with hi-intensity magenta foreground. A newline is appended to format by default.

func HiRedf added in v1.19.0

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

HiRedf is a convenient helper function to print with hi-intensity red foreground. A newline is appended to format by default.

func HiWhitef added in v1.19.0

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

HiWhitef is a convenient helper function to print with hi-intensity white foreground. A newline is appended to format by default.

func HiYellowf added in v1.19.0

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

HiYellowf is a convenient helper function to print with hi-intensity yellow foreground. A newline is appended to format by default.

func Magentaf added in v1.19.0

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

Magentaf is a convenient helper function to print with magenta foreground. A newline is appended to format by default.

func Redf added in v1.19.0

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

Redf is a convenient helper function to print with red foreground. A newline is appended to format by default.

func SBlack added in v1.19.0

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

SBlack is a convenient helper function to return a string with black foreground.

func SBlue added in v1.19.0

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

SBlue is a convenient helper function to return a string with blue foreground.

func SCyan added in v1.19.0

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

SCyan is a convenient helper function to return a string with cyan foreground.

func SGreen added in v1.19.0

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

SGreen is a convenient helper function to return a string with green foreground.

func SHiBlack added in v1.19.0

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

SHiBlack is a convenient helper function to return a string with hi-intensity black foreground.

func SHiBlue added in v1.19.0

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

SHiBlue is a convenient helper function to return a string with hi-intensity blue foreground.

func SHiCyan added in v1.19.0

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

SHiCyan is a convenient helper function to return a string with hi-intensity cyan foreground.

func SHiGreen added in v1.19.0

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

SHiGreen is a convenient helper function to return a string with hi-intensity green foreground.

func SHiMagenta added in v1.19.0

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

SHiMagenta is a convenient helper function to return a string with hi-intensity magenta foreground.

func SHiRed added in v1.19.0

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

SHiRed is a convenient helper function to return a string with hi-intensity red foreground.

func SHiWhite added in v1.19.0

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

SHiWhite is a convenient helper function to return a string with hi-intensity white foreground.

func SHiYellow added in v1.19.0

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

SHiYellow is a convenient helper function to return a string with hi-intensity yellow foreground.

func SMagenta added in v1.19.0

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

SMagenta is a convenient helper function to return a string with magenta foreground.

func SRed added in v1.19.0

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

SRed is a convenient helper function to return a string with red foreground.

func SWhite added in v1.19.0

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

SWhite is a convenient helper function to return a string with white foreground.

func SYellow added in v1.19.0

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

SYellow is a convenient helper function to return a string with yellow foreground.

func Unset

func Unset()

Unset resets all escape attributes and clears the output. Usually should be called after Set().

func Whitef added in v1.19.0

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

Whitef is a convenient helper function to print with white foreground. A newline is appended to format by default.

func Yellowf added in v1.19.0

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

Yellowf is a convenient helper function to print with yellow foreground. A newline is appended to format by default.

Types

type Attribute

type Attribute int

Attribute defines a single SGR Code

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

Base attributes

const (
	FgBlack Attribute = iota + 30
	FgRed
	FgGreen
	FgYellow
	FgBlue
	FgMagenta
	FgCyan
	FgWhite
)

Foreground text colors

const (
	FgHiBlack Attribute = iota + 90
	FgHiRed
	FgHiGreen
	FgHiYellow
	FgHiBlue
	FgHiMagenta
	FgHiCyan
	FgHiWhite
)

Foreground Hi-Intensity text colors

const (
	BgBlack Attribute = iota + 40
	BgRed
	BgGreen
	BgYellow
	BgBlue
	BgMagenta
	BgCyan
	BgWhite
)

Background text colors

const (
	BgHiBlack Attribute = iota + 100
	BgHiRed
	BgHiGreen
	BgHiYellow
	BgHiBlue
	BgHiMagenta
	BgHiCyan
	BgHiWhite
)

Background Hi-Intensity text colors

type Color

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

Color defines a custom color object which is defined by SGR parameters.

func New

func New(value ...Attribute) *Color

New returns a newly created color object.

func Set

func Set(p ...Attribute) *Color

Set sets the given parameters immediately. It will change the color of output with the given SGR parameters until color.Unset() is called.

func (*Color) Add

func (c *Color) Add(value ...Attribute) *Color

Add is used to chain SGR parameters. Use as many as parameters to combine and create custom color objects. Example: Add(color.FgRed, color.Underline).

func (*Color) DisableColor

func (c *Color) DisableColor()

DisableColor disables the color output. Useful to not change any existing code and still being able to output. Can be used for flags like "--no-color". To enable back use EnableColor() method.

func (*Color) EnableColor

func (c *Color) EnableColor()

EnableColor enables the color output. Use it in conjunction with DisableColor(). Otherwise this method has no side effects.

func (*Color) Equals

func (c *Color) Equals(c2 *Color) bool

Equals returns a boolean value indicating whether two colors are equal.

func (*Color) Fprint

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

Fprint formats using the default formats for its operands and writes to w. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered. On Windows, users should wrap w with colorable.NewColorable() if w is of type *os.File.

func (*Color) FprintFunc

func (c *Color) FprintFunc() func(w io.Writer, a ...interface{})

FprintFunc returns a new function that prints the passed arguments as colorized with color.Fprint().

func (*Color) Fprintf

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

Fprintf formats according to a format specifier and writes to w. It returns the number of bytes written and any write error encountered. On Windows, users should wrap w with colorable.NewColorable() if w is of type *os.File.

func (*Color) FprintfFunc

func (c *Color) FprintfFunc() func(w io.Writer, format string, a ...interface{})

FprintfFunc returns a new function that prints the passed arguments as colorized with color.Fprintf().

func (*Color) Fprintln

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

Fprintln formats using the default formats for its operands and writes to w. Spaces are always added between operands and a newline is appended. On Windows, users should wrap w with colorable.NewColorable() if w is of type *os.File.

func (*Color) FprintlnFunc

func (c *Color) FprintlnFunc() func(w io.Writer, a ...interface{})

FprintlnFunc returns a new function that prints the passed arguments as colorized with color.Fprintln().

func (*Color) Print

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

Print formats using the default formats for its operands and writes to standard output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered. This is the standard fmt.Print() method wrapped with the given color.

func (*Color) PrintFunc

func (c *Color) PrintFunc() func(a ...interface{})

PrintFunc returns a new function that prints the passed arguments as colorized with color.Print().

func (*Color) Printf

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

Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered. This is the standard fmt.Printf() method wrapped with the given color.

func (*Color) PrintfFunc

func (c *Color) PrintfFunc() func(format string, a ...interface{})

PrintfFunc returns a new function that prints the passed arguments as colorized with color.Printf().

func (*Color) Println

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

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered. This is the standard fmt.Print() method wrapped with the given color.

func (*Color) PrintlnFunc

func (c *Color) PrintlnFunc() func(a ...interface{})

PrintlnFunc returns a new function that prints the passed arguments as colorized with color.Println().

func (*Color) Set

func (c *Color) Set() *Color

Set sets the SGR sequence.

func (*Color) Sprint

func (c *Color) Sprint(a ...interface{}) string

Sprint is just like Print, but returns a string instead of printing it.

func (*Color) SprintFunc

func (c *Color) SprintFunc() func(a ...interface{}) string

SprintFunc returns a new function that returns colorized strings for the given arguments with fmt.Sprint(). Useful to put into or mix into other string. Windows users should use this in conjunction with color.Output, example:

put := New(FgYellow).SprintFunc()
fmt.Fprintf(color.Output, "This is a %s", put("warning"))

func (*Color) Sprintf

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

Sprintf is just like Printf, but returns a string instead of printing it.

func (*Color) SprintfFunc

func (c *Color) SprintfFunc() func(format string, a ...interface{}) string

SprintfFunc returns a new function that returns colorized strings for the given arguments with fmt.Sprintf(). Useful to put into or mix into other string. Windows users should use this in conjunction with color.Output.

func (*Color) Sprintln

func (c *Color) Sprintln(a ...interface{}) string

Sprintln is just like Println, but returns a string instead of printing it.

func (*Color) SprintlnFunc

func (c *Color) SprintlnFunc() func(a ...interface{}) string

SprintlnFunc returns a new function that returns colorized strings for the given arguments with fmt.Sprintln(). Useful to put into or mix into other string. Windows users should use this in conjunction with color.Output.

Jump to

Keyboard shortcuts

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