当前位置: 首页 > news >正文

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

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

  • 1.安装
  • 2.基础颜色(16-color)
  • 3.256色彩/RGB风格

1.安装

go get github.com/gookit/color

2.基础颜色(16-color)

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

1、例如:

color.Yellow.Println("bold message")
color.Blue.Println("bold message")
color.White.Println("bold message")

在这里插入图片描述

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

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

在这里插入图片描述

3、构建风格

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

在这里插入图片描述

4、直接设置控制台属性

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

在这里插入图片描述

5、扩展风格方法

color.Info.Println("Info message")
color.Note.Println("Note message")
color.Notice.Println("Notice message")

在这里插入图片描述

全部扩展风格:

// 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、简约提示风格

color.Info.Tips("Info tips message")
color.Notice.Tips("Notice tips message")
color.Error.Tips("Error tips message")

在这里插入图片描述

7、着重提示风格

color.Info.Prompt("Info prompt message")
color.Error.Prompt("Error prompt message")
color.Danger.Prompt("Danger prompt message")

在这里插入图片描述

8、强调提示风格

color.Warn.Block("Warn block message")
color.Debug.Block("Debug block message")
color.Question.Block("Question block message")

在这里插入图片描述


3.256色彩/RGB风格

参考官方文档:

gookit/color

http://www.lryc.cn/news/272451.html

相关文章:

  • python弹奏《起风了》
  • Linux---all
  • 前端中级算法题
  • Ant Design Vue 编译后的网页特点是什么,怎么确认他是用的前端 Ant Design Vue 技术栈的呢?
  • python | PYTHON正则表达式
  • 为什么大学c语言课不顺便教一下Linux,Makefile
  • Go后端开发 -- main函数 变量 常量 函数
  • 2023/12/30 c++ work
  • ctfshow——文件上传
  • 【RocketMQ每日一问】RocketMQ SQL92过滤用法以及原理?
  • Go语言中的包管理工具之Go Path的使用
  • cocos creator(2.4.7版本) webview 可以在上层添加UI控件
  • 2023 年四川省职业院校技能大赛“信息安全管理与评估”样题
  • ubuntu2204,mysql8.x安装
  • CG Magic分享云渲染和本地渲染之间的区别有什么?
  • 【算法与数据结构】763、LeetCode划分字母区间
  • 新火种AI|人形机器人敲响上市罗,首日市值高达390亿港元
  • SpringMVC框架
  • FreeRTOS——计数型信号量知识总结及实战
  • Linux下Docker Engine安装后的一些配置步骤
  • 【并发设计模式】聊聊Balking是如何实现以及具体原理
  • dubbo的一些问题思考
  • 盛最多水的容器(力扣11题)
  • .babky勒索病毒解密方法|勒索病毒解决|勒索病毒恢复|数据库修复
  • 20240103-通过布局让自己的生活有有意义人生有价值
  • JDK17 - 开发者视角,从 JDK8 ~ JDK17 都增加了哪些新特性
  • 八股文打卡day11——计算机网络(11)
  • 在Android设备上设置和使用隧道代理HTTP
  • Paddle3D 2 雷达点云CenterPoint模型训练
  • RabbitMQ集群的简单说明