当前位置: 首页 > 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

相关文章:

  • sql:定时执行存储过程(嵌套存储过程、使用游标)
  • 算法训练营第三十天|332.重新安排行程 51. N皇后 37. 解数独
  • 202402读书笔记|《当你老了》——灰蒙曙光比爱情温柔,清晨露珠比希望更可爱
  • 如何实现服务器主动向客户端推送实时数据
  • CSS尺寸单位详解(rpx、px、pt、em、rem、%、vh、vw的区别)
  • pod 基础 2
  • 惠普83752A合成扫频器/信号源0.01-20GHz
  • imgaug库指南(四):从入门到精通的【图像增强】之旅
  • flutter学习-day22-使用GestureDetector识别手势事件
  • 使用react+vite开发项目时候,部署上线后刷新页面无法访问解决办法
  • 【响应式编程-03】Lambda表达式底层实现原理
  • 【INTEL(ALTERA)】Intel Agilex7 设备的外设图像比特流大小是多少?
  • Kafka集群详解
  • 电缆厂 3D 可视化管控系统 | 图扑数字孪生
  • 【React系列】受控非受控组件
  • 【402天】跃迁之路——程序员高效学习方法论探索系列(实验阶段159-2018.03.14)...
  • 【翻译】Mashape是如何管理15000个API和微服务的(三)
  • 【每日笔记】【Go学习笔记】2019-01-10 codis proxy处理流程
  • Cookie 在前端中的实践
  • HTTP中的ETag在移动客户端的应用
  • IE报vuex requires a Promise polyfill in this browser问题解决
  • isset在php5.6-和php7.0+的一些差异
  • Mac 鼠须管 Rime 输入法 安装五笔输入法 教程
  • PyCharm搭建GO开发环境(GO语言学习第1课)
  • Python 使用 Tornado 框架实现 WebHook 自动部署 Git 项目
  • SQLServer之索引简介
  • 使用阿里云发布分布式网站,开发时候应该注意什么?
  • 交换综合实验一
  • 浅谈sql中的in与not in,exists与not exists的区别
  • 组复制官方翻译九、Group Replication Technical Details
  • ​马来语翻译中文去哪比较好?
  • ​用户画像从0到100的构建思路
  • #vue3 实现前端下载excel文件模板功能
  • (delphi11最新学习资料) Object Pascal 学习笔记---第5章第5节(delphi中的指针)
  • (Redis使用系列) Springboot 实现Redis 同数据源动态切换db 八
  • (Redis使用系列) Springboot 使用redis的List数据结构实现简单的排队功能场景 九
  • (附源码)springboot教学评价 毕业设计 641310
  • (附源码)ssm高校运动会管理系统 毕业设计 020419
  • (免费领源码)python#django#mysql校园校园宿舍管理系统84831-计算机毕业设计项目选题推荐
  • (十八)devops持续集成开发——使用docker安装部署jenkins流水线服务
  • (新)网络工程师考点串讲与真题详解
  • (转)拼包函数及网络封包的异常处理(含代码)
  • .NET Core SkiaSharp 替代 System.Drawing.Common 的一些用法
  • .NET Standard、.NET Framework 、.NET Core三者的关系与区别?
  • .net 使用ajax控件后如何调用前端脚本
  • .Net 中的反射(动态创建类型实例) - Part.4(转自http://www.tracefact.net/CLR-and-Framework/Reflection-Part4.aspx)...
  • .net快速开发框架源码分享
  • .vollhavhelp-V-XXXXXXXX勒索病毒的最新威胁:如何恢复您的数据?
  • @DateTimeFormat 和 @JsonFormat 注解详解
  • @Documented注解的作用
  • [ 网络基础篇 ] MAP 迈普交换机常用命令详解
  • []FET-430SIM508 研究日志 11.3.31
  • [20170705]lsnrctl status LISTENER_SCAN1
  • [2019.3.20]BZOJ4573 [Zjoi2016]大森林
  • [BUG] Authentication Error