代码拉取完成,页面将自动刷新
同步操作将从 gookit/color 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
Golang下的命令行色彩使用库, 拥有丰富的色彩渲染输出,通用的API方法,兼容Windows系统
基本颜色预览:
cmd.exe
linux
mac
和 Windows下的 ConEmu
git-bash
mintty
等部分终端Print
Printf
Println
Sprint
Sprintf
<green>message</>
Bold
Black
White
Gray
Red
Green
Yellow
Blue
Magenta
Cyan
Info
Note
Light
Error
Danger
Notice
Success
Comment
Primary
Warning
Question
Secondary
如下,引入当前包就可以快速的使用
import "gopkg.in/gookit/color.v1" // 推荐
// or
import "github.com/gookit/color"
package main
import (
"fmt"
"github.com/gookit/color"
)
func main() {
// simple usage
color.Cyan.Printf("Simple to use %s\n", "color")
// use like func
red := color.FgRed.Render
green := color.FgGreen.Render
fmt.Printf("%s line %s library\n", red("Command"), green("color"))
// 自定义颜色
color.New(color.FgWhite, color.BgBlack).Println("custom color style")
// 也可以:
color.Style{color.FgCyan, color.OpBold}.Println("custom color style")
// internal style:
color.Info.Println("message")
color.Warn.Println("message")
color.Error.Println("message")
// 使用颜色标签
color.Print("<suc>he</><comment>llo</>, <cyan>wel</><red>come</>\n")
// apply a style tag
color.Tag("info").Println("info style text")
// prompt message
color.Info.Prompt("prompt style message")
color.Warn.Prompt("prompt style message")
// tips message
color.Info.Tips("tips style message")
color.Warn.Tips("tips style message")
}
运行 demo:
go run ./_examples/app.go
// 仅设置前景色
color.FgCyan.Printf("Simple to use %s\n", "color")
// 仅设置背景色
color.BgRed.Printf("Simple to use %s\n", "color")
// 完全自定义 前景色 背景色 选项
style := color.New(color.FgWhite, color.BgBlack, color.OpBold)
style.Println("custom color style")
// 也可以:
color.Style{color.FgCyan, color.OpBold}.Println("custom color style")
// 设置console颜色
color.Set(color.FgCyan)
// 输出信息
fmt.Print("message")
// 重置console颜色
color.Reset()
支持在windows
cmd.exe
使用
color.Bold
color.Black
color.White
color.Gray
color.Red
color.Green
color.Yellow
color.Blue
color.Magenta
color.Cyan
color.Bold.Println("bold message")
color.Yellow.Println("yellow message")
运行 demo:
go run ./_examples/basiccolor.go
支持在windows
cmd.exe
使用
color.Info
color.Note
color.Light
color.Error
color.Danger
color.Notice
color.Success
color.Comment
color.Primary
color.Warning
color.Question
color.Secondary
color.Info.Println("Info message")
color.Success.Println("Success message")
运行 demo:
go run ./_examples/theme_style.go
不 支持在windows
cmd.exe
使用,但不影响使用,会自动去除颜色标签
使用内置的颜色标签,可以非常方便简单的构建自己需要的任何格式
// 使用内置的 color tag
color.Print("<suc>he</><comment>llo</>, <cyan>wel</><red>come</>")
color.Println("<suc>hello</>")
color.Println("<error>hello</>")
color.Println("<warning>hello</>")
// 自定义颜色属性
color.Print("<fg=yellow;bg=black;op=underscore;>hello, welcome</>\n")
color.Tag
给后面输出的文本信息加上给定的颜色风格标签
// set a style tag
color.Tag("info").Print("info style text")
color.Tag("info").Printf("%s style text", "info")
color.Tag("info").Println("info style text")
运行 demo:
go run ./_examples/colortag.go
color.C256(val uint8, isBg ...bool) Color256
c := color.C256(132) // fg color
c.Println("message")
c.Printf("format %s", "message")
c := color.C256(132, true) // bg color
c.Println("message")
c.Printf("format %s", "message")
可同时设置前景和背景色
color.S256(fgAndBg ...uint8) *Style256
s := color.S256(32, 203)
s.Println("message")
s.Printf("format %s", "message")
运行 demo:
go run ./_examples/color256.go
color.RGB(r, g, b uint8, isBg ...bool) RGBColor
c := color.RGB(30,144,255) // fg color
c.Println("message")
c.Printf("format %s", "message")
c := color.RGB(30,144,255, true) // bg color
c.Println("message")
c.Printf("format %s", "message")
color.HEX(hex string, isBg ...bool) RGBColor
从16进制颜色创建c := HEX("ccc") // 也可以写为: "cccccc" "#cccccc"
c.Println("message")
c.Printf("format %s", "message")
c = HEX("aabbcc", true) // as bg color
c.Println("message")
c.Printf("format %s", "message")
可同时设置前景和背景色
color.NewRGBStyle(fg RGBColor, bg ...RGBColor) *RGBStyle
s := NewRGBStyle(RGB(20, 144, 234), RGB(234, 78, 23))
s.Println("message")
s.Printf("format %s", "message")
color.HEXStyle(fg string, bg ...string) *RGBStyle
从16进制颜色创建s := HEXStyle("11aa23", "eee")
s.Println("message")
s.Printf("format %s", "message")
gookit/gcli 快速的构建CLI命令应用
issue9/term
https://github.com/issue9/term
beego/bee
https://github.com/beego/bee
inhere/console
https://github/inhere/php-console
MIT
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。