colorString

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultColors map[string]string

DefaultColors are the default colors used when colorizing.

If the color is surrounded in underscores, such as "_blue_", then that color will be used for backfround color.

Functions

func Color

func Color(v string) string

Color colorizes your strings using the default settings.

Strings given to Color should use the syntax `[color]` to specify the color for text following. For example: `[red]Hello` will return "Hello" in red. See DefaultColors for all the supported colors and attributes.

If an unrecongnized color is given, it is ignored and assumed to be part of the string.For example: `[it]world` will result in "[it]world".

A color reset is appended to the end of every string. This will reset the color of following strings when you output this text to the same terminal session.

If you want to customize any of this behavior, use the Colorize struct.

func ColorPrefix

func ColorPrefix(v string) string

func Fprintf

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

Fprintf is a convenience wrapper for fmt.Fprintf with support for color codes.

Fprintf formats according to a format specifier and writes to w with support for color codes. It returns the number of bytes written and any write error encountered.

func Fprintln

func Fprintln(w io.Writer, a string) (n int, err error)

Fprintln is a convenience wrapper for fmt.Fprintln with support for color codes.

Fprintln formats using the default formatss for its operands and writes to standarg output with support for color codes. Spaces are added between operands when neither is a string. It returns the number of bytes written and ant write error encountered.

func Print

func Print(a string) (n int, err error)

Print is a convenience wrapper for fmt.Print with support for color codes.

Print formats using the default formatss for its operands and writes to standarg output with support for color codes. Spaces are added between operands when neither is a string. It returns the number of bytes written and ant write error encountered.

func Printf

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

Printf is a convenience wrapper for fmt.Printf with support for color codes.

Printf formats using the default formatss for its operands and writes to standarg output with support for color codes. Spaces are added between operands when neither is a string. It returns the number of bytes written and ant write error encountered.

func Println

func Println(a string) (n int, err error)

Println is a convenience wrapper for fmt.Println with support for color codes.

Println formats using the default formatss for its operands and writes to standarg output with support for color codes. Spaces are added between operands when neither is a string. It returns the number of bytes written and ant write error encountered.

func Sprintf

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

Sprintf is a convenience wrapper for fmt.Sprintf with support for color codes.

Sprintf formats according to a format specifier and writes to w with support for color codes. It returns the number of bytes written and any write error encountered.

Types

type Colorize

type Colorize struct {
	// Colors maps a color string to the code for that color.
	// The code is a string so that you can use more complex colors
	// to set foreground, background, attributes, etc.
	// For example, "boldblue" might be "1;34'
	Colors map[string]string

	// If true, color attributes will be ignored. This is useful
	// if you're outputting a location that doesn't support colors
	// and you just want the strings returned.
	Disable bool

	// Reset, if true, will reset the color after each colorization
	// by adding a reset code at the end.
	Reset bool
}

Colorize colorizes your strings, giveing you the ability to customize some of the colorization process.

The options in Colorize can be set to customize colorization. If you're only interested in the defaults, just use the top Color function derectly, which creates a default Colorize.

func (*Colorize) Color

func (c *Colorize) Color(v string) string

Color colorizes a string according to settings setup in the struct.

For more details on the syntax, see the top-level Color function

func (*Colorize) ColorPrefix

func (c *Colorize) ColorPrefix(v string) string

ColorPrefix returns the first color sequence that exists in this string.

For example: "[green]foo" would return "[green]". If no color sequence exists, then "" is returned. This is especially useful when wrapping colored texts to inherit the color of the wrapped text.

Jump to

Keyboard shortcuts

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