Documentation ¶
Overview ¶
Package colors 带色彩的控制台文本输出包
兼容 windows 平台。
// 输出段蓝底红字:foreground:Red;background:Blue colors.Printf(colors.Red, colors.Blue, "foreground:%v;background:%v", colors.Red, colors.Blue) // 功能同上,但是可以重复调用 Print* 系列函数输出内容。 c := colors.New(). Color(colors.Normal, colors.Red, colors.Yellow). Print("foreground:%v;background:%v"). Print(colors.Red, colors.Blue)
Index ¶
- func Fprint(w io.Writer, t Type, foreground, background Color, v ...any) (int, error)
- func Fprintf(w io.Writer, t Type, foreground, background Color, format string, v ...any) (int, error)
- func Fprintln(w io.Writer, t Type, foreground, background Color, v ...any) (int, error)
- func Print(t Type, foreground, background Color, v ...any) (int, error)
- func Printf(t Type, foreground, background Color, format string, v ...any) (int, error)
- func Println(t Type, foreground, background Color, v ...any) (int, error)
- func Sprint(t Type, foreground, background Color, v ...any) string
- func Sprintf(t Type, foreground, background Color, format string, v ...any) string
- func Sprintln(t Type, foreground, background Color, v ...any) string
- type Color
- type Colorize
- func (c *Colorize) Color(t Type, foreground, background Color) *Colorize
- func (c *Colorize) Err() error
- func (c *Colorize) Print(v ...any) *Colorize
- func (c *Colorize) Printf(format string, v ...any) *Colorize
- func (c *Colorize) Println(v ...any) *Colorize
- func (c *Colorize) Reset() *Colorize
- func (c *Colorize) WByte(b byte) *Colorize
- func (c *Colorize) WBytes(data []byte) *Colorize
- func (c *Colorize) WString(str string) *Colorize
- func (c *Colorize) Write(bs []byte) (int, error)
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fprint ¶
Fprint 带色彩输出的 fmt.Fprint
func Fprintf ¶
func Fprintf(w io.Writer, t Type, foreground, background Color, format string, v ...any) (int, error)
Fprintf 带色彩输出的 fmt.Fprintf
func Fprintln ¶
Fprintln 带色彩输出的 fmt.Fprintln
func Printf ¶
Printf 带色彩输出的 fmt.Printf
func Println ¶
Println 带色彩输出的 fmt.Println
Types ¶
type Color ¶
type Color int32
Color 定义了控制台能接受的所有颜色值
颜色定义分为以下几种:
- 默认色: math.MaxInt32 定义为 Default
- 基本色: 0-7 定义从 Black 至 White
- 增强色: 8-15 定义从 BrightBlack 至 BrightWhite
- 256 色: 0-256,数值,其中 0-15 的数据会被转换成以上的色彩;
- 真彩色: 负数,可由 RGB 函数生成;
默认色、增强色和 256 色基本上所有的终端都支持, 而 24 位真彩色则未必所有终端都支持,比如 macOS 自带的终端对该色彩支持并不好。
关于颜色的具体定义,可参考以下文章 ANSI_escape_code
NOTE: 具体颜色值在不同的平台上可能有一定的差异。
const ( Black Color = iota // 黑色 Red // 红色 Green // 绿色 Yellow // 黄色 Blue // 蓝色 Magenta // 洋红色 Cyan // 青色 White // 白色 BrightBlack // 亮黑 BrightRed // 亮红色 BrightGreen // 亮绿色 BrightYellow // 亮黄色 BrightBlue // 亮蓝色 BrightMagenta // 亮洋红色 BrightCyan // 亮青色 BrightWhite // 亮白色 Default Color = math.MaxInt32 )
颜色值定义
Click to show internal directories.
Click to hide internal directories.