gookit/color - Go语言命令行色彩使用库教程

gookit/color - Go语言命令行色彩使用库教程

1.安装

go 复制代码
go get github.com/gookit/color

2.基础颜色(16-color)

提供通用的API方法:Print Printf Println Sprint Sprintf

1、例如:

go 复制代码
color.Yellow.Println("bold message")
color.Blue.Println("bold message")
color.White.Println("bold message")

2、特例,仅仅设置前景和背景颜色:

go 复制代码
// 仅使用前景色
color.FgCyan.Printf("Simple to use %s\n", "color")
// 仅使用背景色
color.BgRed.Printf("Simple to use %s\n", "color")

3、构建风格

go 复制代码
// 完全自定义: 前景色 背景色 选项(字体)
style := color.New(color.FgRed, color.BgBlack, color.OpBold)
style.Println("custom color style")

4、直接设置控制台属性

go 复制代码
// 设置console颜色
_, err := color.Set(color.FgCyan)
if err != nil {
	return
}
// 输出信息
fmt.Print("message")

5、扩展风格方法

go 复制代码
color.Info.Println("Info message")
color.Note.Println("Note message")
color.Notice.Println("Notice message")

全部扩展风格:

go 复制代码
// Info color style
Info = &Theme{"info", Style{OpReset, FgGreen}}
// Note color style
Note = &Theme{"note", Style{OpBold, FgLightCyan}}
// Warn color style
Warn = &Theme{"warning", Style{OpBold, FgYellow}}
// Light color style
Light = &Theme{"light", Style{FgLightWhite, BgBlack}}
// Error color style
Error = &Theme{"error", Style{FgLightWhite, BgRed}}
// Danger color style
Danger = &Theme{"danger", Style{OpBold, FgRed}}
// Debug color style
Debug = &Theme{"debug", Style{OpReset, FgCyan}}
// Notice color style
Notice = &Theme{"notice", Style{OpBold, FgCyan}}
// Comment color style
Comment = &Theme{"comment", Style{OpReset, FgYellow}}
// Success color style
Success = &Theme{"success", Style{OpBold, FgGreen}}
// Primary color style
Primary = &Theme{"primary", Style{OpReset, FgBlue}}
// Question color style
Question = &Theme{"question", Style{OpReset, FgMagenta}}
// Secondary color style
Secondary = &Theme{"secondary", Style{FgDarkGray}}

6、简约提示风格

go 复制代码
color.Info.Tips("Info tips message")
color.Notice.Tips("Notice tips message")
color.Error.Tips("Error tips message")

7、着重提示风格

go 复制代码
color.Info.Prompt("Info prompt message")
color.Error.Prompt("Error prompt message")
color.Danger.Prompt("Danger prompt message")

8、强调提示风格

go 复制代码
color.Warn.Block("Warn block message")
color.Debug.Block("Debug block message")
color.Question.Block("Question block message")

3.256色彩/RGB风格

参考官方文档:

gookit/color

相关推荐
coderWangbuer3 分钟前
基于springboot的高校招生系统(含源码+sql+视频导入教程+文档+PPT)
spring boot·后端·sql
无限大.7 分钟前
c语言200例 067
java·c语言·开发语言
余炜yw9 分钟前
【Java序列化器】Java 中常用序列化器的探索与实践
java·开发语言
攸攸太上9 分钟前
JMeter学习
java·后端·学习·jmeter·微服务
篝火悟者10 分钟前
问题-python-运行报错-SyntaxError: Non-UTF-8 code starting with ‘\xd5‘ in file 汉字编码问题
开发语言·python
Kenny.志12 分钟前
2、Spring Boot 3.x 集成 Feign
java·spring boot·后端
Death20012 分钟前
Qt 中的 QListWidget、QTreeWidget 和 QTableWidget:简化的数据展示控件
c语言·开发语言·c++·qt·c#
六点半88814 分钟前
【C++】速通涉及 “vector” 的经典OJ编程题
开发语言·c++·算法·青少年编程·推荐算法
惜.己14 分钟前
javaScript基础(8个案例+代码+效果图)
开发语言·前端·javascript·vscode·css3·html5
niu_sama17 分钟前
基于muduo库函数实现protobuf协议的通信
开发语言·qt