color

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: MIT Imports: 9 Imported by: 1

README

GoDoc Build Status Coverage Status Report Card

This package is inspired by github.com/fatih/color.

Documentation

Overview

Package color provides color-based types and helpers.

Index

Constants

View Source
const Version = "v0.1.1"

Version is the current version of the package.

Variables

This section is empty.

Functions

func Copy

func Copy(s Style, dst io.Writer, src io.Reader) (int64, error)

Copy is a convenience function that calls s.Copy(dst, src).

func Enabled

func Enabled() bool

Enabled returns whether color is enabled based on terminal settings.

func Fprint

func Fprint(dst io.Writer, s Style, args ...any) (int, error)

Fprint is a convenience function that calls s.Fprint(dst, args...).

func Fprintf

func Fprintf(dst io.Writer, s Style, msg string, args ...any) (int, error)

Fprintf is a convenience function that calls s.Fprintf(dst, msg, args...).

func Fprintln

func Fprintln(dst io.Writer, s Style, args ...any) (int, error)

Fprintln is a convenience function that calls s.Fprintln(dst, args...).

func Print

func Print(s Style, args ...any)

Print is a convenience function that calls s.Print(args...).

func Printf

func Printf(s Style, msg string, args ...any)

Printf is a convenience function that calls s.Printf(msg, args...).

func Println

func Println(s Style, args ...any)

Println is a convenience function that calls s.Println(args...).

func Sprint

func Sprint(s Style, args ...any) string

Sprint is a convenience function that calls s.Sprint(args...).

func Sprintf

func Sprintf(s Style, msg string, args ...any) string

Sprintf is a convenience function that calls s.Sprintf(msg, args...).

func Sprintln

func Sprintln(s Style, args ...any) string

Sprintln is a convenience function that calls s.Sprintln(args...).

func Wrap

func Wrap(s Style, msg string) string

Wrap is a convenience function that calls s.Wrap(msg).

func WrapN

func WrapN(s Style, msgs ...string) string

WrapN is a convenience function that calls s.WrapN(msgs...).

Types

type Color

type Color uint8

A Color is a terminal color.

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

Style colors.

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

Foreground colors.

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

Foreground high-intensity colors.

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

Background colors.

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

Background high-intensity colors.

func (Color) Copy

func (c Color) Copy(dst io.Writer, src io.Reader) (int64, error)

Copy copies src to dest as in io.Copy, but wrapped in c.

func (Color) Escape

func (c Color) Escape() string

Escape returns c's escape code.

func (Color) Fprint

func (c Color) Fprint(w io.Writer, args ...any) (int, error)

Fprint prints args to w as in fmt.Fprint, but wrapped in c.

func (Color) Fprintf

func (c Color) Fprintf(w io.Writer, msg string, args ...any) (int, error)

Fprintf prints msg and args to w as in fmt.Fprintf, but wrapped in c.

func (Color) Fprintln

func (c Color) Fprintln(w io.Writer, args ...any) (int, error)

Fprintln prints args to w as in fmt.Fprintln, but wrapped in c.

func (Color) Print

func (c Color) Print(args ...any)

Print prints args as in fmt.Print, but wrapped in c.

func (Color) Printf

func (c Color) Printf(msg string, args ...any)

Printf prints msg and args as in fmt.Printf, but wrapped in c.

func (Color) Println

func (c Color) Println(args ...any)

Println prints args as in fmt.Println, but wrapped in c.

func (Color) Reset

func (c Color) Reset() string

Reset returns the escape code the reset output after c.

func (Color) Sprint

func (c Color) Sprint(args ...any) string

Sprint returns a string containing args as in fmt.Sprint, but wrapped in c.

func (Color) Sprintf

func (c Color) Sprintf(msg string, args ...any) string

Sprintf returns a string containing msg and args as in fmt.Sprintf, but wrapped in c.

func (Color) Sprintln

func (c Color) Sprintln(args ...any) string

Sprintln returns a string containing args as in fmt.Sprintln, but wrapped in c.

func (Color) String

func (c Color) String() string

String returns c's escape code, regardless of whether color is enabled.

func (Color) Wrap

func (c Color) Wrap(str string) string

Wrap wraps str with c.

func (Color) WrapN

func (c Color) WrapN(strs ...string) string

WrapN wraps strs, joined by spaces, with c.

type Style

type Style interface {
	Copy(io.Writer, io.Reader) (int64, error)
	Escape() string
	Fprint(io.Writer, ...any) (int, error)
	Fprintf(io.Writer, string, ...any) (int, error)
	Fprintln(io.Writer, ...any) (int, error)
	Print(...any)
	Printf(string, ...any)
	Println(...any)
	Reset() string
	Sprint(...any) string
	Sprintf(string, ...any) string
	Sprintln(...any) string
	String() string
	Wrap(string) string
	WrapN(...string) string
}

A Style styles text.

var Nop Style = nop{}

Nop is a passthrough Style that does not add color.

func Combine

func Combine(s ...Style) Style

Combine combines colors into [Colors].

Jump to

Keyboard shortcuts

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