colors

package
v0.0.0-...-205ef5e Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2020 License: MIT, MIT Imports: 5 Imported by: 0

Documentation

Overview

colors 带色彩的控制台文本输出包,兼容 windows 平台。

// 输出段蓝底红字:foreground:Red;background:Blue
colors.Printf(colors.Red, colors.Blue, "foreground:%v;background:%v", colors.Red, colors.Blue)

// 功能同上,但是可以重复调用 Print* 系列函数输出内容。
c := colors.Init(colors.Red, colors.Yellow)
c.Print("foreground:%v;background:%v")
c.Print(colors.Red, colors.Blue)

为了兼容 windows 平台,只使用了最基本的几种颜色值, 而不是 ansi 控制台的 256 色。若不需要考虑 windows 平台, 可以直接使用 term/ansi 包,那里有对 ansi 包更好的支持。

兼容 mingw 等软件。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fprint

func Fprint(w io.Writer, foreground, background Color, v ...interface{}) (int, error)

Fprint 带色彩输出的 fmt.Fprint。 颜色值只在 w 不为 os.Stderr、os.Stdin、os.Stdout 中的一个时才启作用,否则只向 w 输出普通字符串。

func Fprintf

func Fprintf(w io.Writer, foreground, background Color, format string, v ...interface{}) (int, error)

Fprintf 带色彩输出的 fmt.Fprintf。 颜色值只在 w 不为 os.Stderr、os.Stdin、os.Stdout 中的一个时才启作用,否则只向 w 输出普通字符串。

func Fprintln

func Fprintln(w io.Writer, foreground, background Color, v ...interface{}) (int, error)

Fprintln 带色彩输出的 fmt.Fprintln。 颜色值只在 w 不为 os.Stderr、os.Stdin、os.Stdout 中的一个时才启作用,否则只向 w 输出普通字符串。

func Print

func Print(foreground, background Color, v ...interface{}) (int, error)

Print 带色彩输出的 fmt.Print,输出到 os.Stdout。

func Printf

func Printf(foreground, background Color, format string, v ...interface{}) (int, error)

Printf 带色彩输出的 fmt.Printf,输出到 os.Stdout。

func Println

func Println(foreground, background Color, v ...interface{}) (int, error)

Println 带色彩输出的 fmt.Println,输出到 os.Stdout。

Types

type Color

type Color int8

Color 定义了控制台能接受的所有颜色值。 具体颜色值在不同的平台上可能有一定的差异。

const (
	Default Color = iota // 默认色,由控制台决定具体颜色值
	Black                // 黑色
	Red                  // 红色
	Green                // 绿色
	Yellow               // 黄色
	Blue                 // 蓝色
	Magenta              // 洋红色
	Cyan                 // 青色
	White                // 白色

)

颜色值定义

func (Color) IsValid

func (c Color) IsValid() bool

IsValid 检测是否为一个有效的 Color 值。

func (Color) String

func (c Color) String() string

fmt.Stringer.String()

type Colorize

type Colorize struct {
	Foreground Color
	Background Color
}

func New

func New(foreground, background Color) Colorize

Init 新建一个 Colorize

func (Colorize) Fprint

func (c Colorize) Fprint(w io.Writer, v ...interface{}) (int, error)

Fprint 等同于 Fprint(),颜色由 Colorize 指定, 若 w 不指向控制台,则颜色值被忽略。

func (Colorize) Fprintf

func (c Colorize) Fprintf(w io.Writer, format string, v ...interface{}) (int, error)

Fprintf 等同于 Fprintf(),颜色由 Colorize 指定, 若 w 不指向控制台,则颜色值被忽略。

func (Colorize) Fprintln

func (c Colorize) Fprintln(w io.Writer, v ...interface{}) (int, error)

Fprintln 等同于 Fprintln(),颜色由 Colorize 指定, 若 w 不指向控制台,则颜色值被忽略。

func (Colorize) Print

func (c Colorize) Print(v ...interface{}) (int, error)

Print 等同于 Print(),颜色由 Colorize 指定

func (Colorize) Printf

func (c Colorize) Printf(format string, v ...interface{}) (int, error)

Printf 等同于 Printf(),颜色由 Colorize 指定

func (Colorize) Println

func (c Colorize) Println(v ...interface{}) (int, error)

Println 等同于 Println(),颜色由 Colorize 指定

Jump to

Keyboard shortcuts

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