代码拉取完成,页面将自动刷新
golang下的命令行色彩使用库
dep ensure -add gopkg.in/gookit/color.v1 // 推荐
// OR
dep ensure -add github.com/gookit/color
go get gopkg.in/gookit/color.v1 // 推荐
// OR
go get -u github.com/gookit/color
git clone https://github.com/gookit/color
如下,引入当前包就可以快速的使用
import "gopkg.in/gookit/color.v1" // 推荐
// or
import "github.com/gookit/color"
package main
import (
"github.com/gookit/color"
)
func main() {
// simple usage
color.FgCyan.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"))
// custom color
color.New(color.FgWhite, color.BgBlack).Println("custom color style")
// can also:
color.Style{color.FgCyan, color.OpBold}.Println("custom color style")
// use style tag
color.Print("<suc>he</><comment>llo</>, <cyan>wel</><red>come</>\n")
// set a style tag
color.Tag("info").Println("info style text")
// use info style tips
color.Tips("info").Print("tips style text")
// use info style blocked tips
color.LiteTips("info").Print("blocked tips style text")
}
运行 demo: go run ./demo/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")
// can also:
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(args ...interface{})
color.Black(args ...interface{})
color.White(args ...interface{})
color.Gray(args ...interface{})
color.Red(args ...interface{})
color.Green(args ...interface{})
color.Yellow(args ...interface{})
color.Blue(args ...interface{})
color.Magenta(args ...interface{})
color.Cyan(args ...interface{})
color.Bold("bold message")
color.Yellow("yellow message")
支持在windows
cmd.exe
使用
color.Info(args ...interface{})
color.Note(args ...interface{})
color.Light(args ...interface{})
color.Error(args ...interface{})
color.Danger(args ...interface{})
color.Notice(args ...interface{})
color.Success(args ...interface{})
color.Comment(args ...interface{})
color.Primary(args ...interface{})
color.Warning(args ...interface{})
color.Question(args ...interface{})
color.Secondary(args ...interface{})
color.Info("Info message")
color.Success("Success message")
不 支持在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")
这里列出了内置的标签,基本上涵盖了各种风格和颜色搭配。它们都可用作颜色html标签,或者作为 color.Tag
color.Tips
等的参数
// Some internal defined style tags
// usage: <tag>content text</>
// basic tags
- red
- blue
- cyan
- black
- green
- brown
- white
- default // no color
- normal// no color
- yellow
- magenta
// alert tags like bootstrap's alert
- suc // same "green" and "bold"
- success
- info // same "green"
- comment // same "brown"
- note
- notice
- warn
- warning
- primary
- danger // same "red"
- err
- error
// more tags
- lightRed
- light_red
- lightGreen
- light_green
- lightBlue
- light_blue
- lightCyan
- light_cyan
- lightDray
- light_gray
- gray
- darkGray
- dark_gray
- lightYellow
- light_yellow
- lightMagenta
- light_magenta
// extra
- lightRedEx
- light_red_ex
- lightGreenEx
- light_green_ex
- lightBlueEx
- light_blue_ex
- lightCyanEx
- light_cyan_ex
- whiteEx
- white_ex
// option
- bold
- underscore
- reverse
issue9/term
https://github.com/issue9/termbeego/bee
https://github.com/beego/beeinhere/console
https://github/inhere/php-consoleMIT
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。