From 79848087bccd5c87af1dbb44a39753aad1346f8b Mon Sep 17 00:00:00 2001 From: mjarkk Date: Tue, 27 Jul 2021 15:00:37 +0200 Subject: Switch to github.com/gookit/color for terminal colors --- vendor/github.com/gookit/color/.gitignore | 20 + vendor/github.com/gookit/color/LICENSE | 20 + vendor/github.com/gookit/color/README.md | 468 +++ vendor/github.com/gookit/color/README.zh-CN.md | 472 +++ vendor/github.com/gookit/color/color.go | 238 ++ vendor/github.com/gookit/color/color_16.go | 440 +++ vendor/github.com/gookit/color/color_256.go | 308 ++ vendor/github.com/gookit/color/color_rgb.go | 391 +++ vendor/github.com/gookit/color/color_tag.go | 427 +++ vendor/github.com/gookit/color/convert.go | 593 ++++ vendor/github.com/gookit/color/detect_env.go | 281 ++ vendor/github.com/gookit/color/detect_nonwin.go | 48 + vendor/github.com/gookit/color/detect_windows.go | 243 ++ vendor/github.com/gookit/color/go.mod | 9 + vendor/github.com/gookit/color/go.sum | 15 + vendor/github.com/gookit/color/printer.go | 122 + vendor/github.com/gookit/color/quickstart.go | 109 + vendor/github.com/gookit/color/style.go | 315 ++ vendor/github.com/gookit/color/utils.go | 206 ++ vendor/github.com/stretchr/testify/LICENSE | 2 +- .../stretchr/testify/assert/assertion_compare.go | 274 ++ .../stretchr/testify/assert/assertion_format.go | 118 +- .../stretchr/testify/assert/assertion_forward.go | 218 +- .../stretchr/testify/assert/assertion_order.go | 309 -- .../stretchr/testify/assert/assertions.go | 405 ++- .../stretchr/testify/assert/forward_assertions.go | 2 +- .../stretchr/testify/assert/http_assertions.go | 25 +- vendor/github.com/xo/terminfo/.gitignore | 9 + vendor/github.com/xo/terminfo/LICENSE | 21 + vendor/github.com/xo/terminfo/README.md | 139 + vendor/github.com/xo/terminfo/caps.go | 33 + vendor/github.com/xo/terminfo/capvals.go | 2023 +++++++++++++ vendor/github.com/xo/terminfo/color.go | 91 + vendor/github.com/xo/terminfo/go.mod | 3 + vendor/github.com/xo/terminfo/go.sum | 0 vendor/github.com/xo/terminfo/load.go | 72 + vendor/github.com/xo/terminfo/param.go | 490 ++++ vendor/github.com/xo/terminfo/stack.go | 48 + vendor/github.com/xo/terminfo/terminfo.go | 538 ++++ vendor/github.com/xo/terminfo/util.go | 266 ++ vendor/gopkg.in/yaml.v2/LICENSE | 201 -- vendor/gopkg.in/yaml.v2/LICENSE.libyaml | 31 - vendor/gopkg.in/yaml.v2/NOTICE | 13 - vendor/gopkg.in/yaml.v2/README.md | 133 - vendor/gopkg.in/yaml.v2/apic.go | 740 ----- vendor/gopkg.in/yaml.v2/decode.go | 815 ------ vendor/gopkg.in/yaml.v2/emitterc.go | 1685 ----------- vendor/gopkg.in/yaml.v2/encode.go | 390 --- vendor/gopkg.in/yaml.v2/go.mod | 5 - vendor/gopkg.in/yaml.v2/parserc.go | 1095 ------- vendor/gopkg.in/yaml.v2/readerc.go | 412 --- vendor/gopkg.in/yaml.v2/resolve.go | 258 -- vendor/gopkg.in/yaml.v2/scannerc.go | 2711 ------------------ vendor/gopkg.in/yaml.v2/sorter.go | 113 - vendor/gopkg.in/yaml.v2/writerc.go | 26 - vendor/gopkg.in/yaml.v2/yaml.go | 466 --- vendor/gopkg.in/yaml.v2/yamlh.go | 739 ----- vendor/gopkg.in/yaml.v2/yamlprivateh.go | 173 -- vendor/gopkg.in/yaml.v3/LICENSE | 50 + vendor/gopkg.in/yaml.v3/NOTICE | 13 + vendor/gopkg.in/yaml.v3/README.md | 150 + vendor/gopkg.in/yaml.v3/apic.go | 746 +++++ vendor/gopkg.in/yaml.v3/decode.go | 931 ++++++ vendor/gopkg.in/yaml.v3/emitterc.go | 1992 +++++++++++++ vendor/gopkg.in/yaml.v3/encode.go | 561 ++++ vendor/gopkg.in/yaml.v3/go.mod | 5 + vendor/gopkg.in/yaml.v3/parserc.go | 1229 ++++++++ vendor/gopkg.in/yaml.v3/readerc.go | 434 +++ vendor/gopkg.in/yaml.v3/resolve.go | 326 +++ vendor/gopkg.in/yaml.v3/scannerc.go | 3025 ++++++++++++++++++++ vendor/gopkg.in/yaml.v3/sorter.go | 134 + vendor/gopkg.in/yaml.v3/writerc.go | 48 + vendor/gopkg.in/yaml.v3/yaml.go | 662 +++++ vendor/gopkg.in/yaml.v3/yamlh.go | 805 ++++++ vendor/gopkg.in/yaml.v3/yamlprivateh.go | 198 ++ vendor/modules.txt | 11 +- 76 files changed, 20659 insertions(+), 10478 deletions(-) create mode 100644 vendor/github.com/gookit/color/.gitignore create mode 100644 vendor/github.com/gookit/color/LICENSE create mode 100644 vendor/github.com/gookit/color/README.md create mode 100644 vendor/github.com/gookit/color/README.zh-CN.md create mode 100644 vendor/github.com/gookit/color/color.go create mode 100644 vendor/github.com/gookit/color/color_16.go create mode 100644 vendor/github.com/gookit/color/color_256.go create mode 100644 vendor/github.com/gookit/color/color_rgb.go create mode 100644 vendor/github.com/gookit/color/color_tag.go create mode 100644 vendor/github.com/gookit/color/convert.go create mode 100644 vendor/github.com/gookit/color/detect_env.go create mode 100644 vendor/github.com/gookit/color/detect_nonwin.go create mode 100644 vendor/github.com/gookit/color/detect_windows.go create mode 100644 vendor/github.com/gookit/color/go.mod create mode 100644 vendor/github.com/gookit/color/go.sum create mode 100644 vendor/github.com/gookit/color/printer.go create mode 100644 vendor/github.com/gookit/color/quickstart.go create mode 100644 vendor/github.com/gookit/color/style.go create mode 100644 vendor/github.com/gookit/color/utils.go create mode 100644 vendor/github.com/stretchr/testify/assert/assertion_compare.go delete mode 100644 vendor/github.com/stretchr/testify/assert/assertion_order.go create mode 100644 vendor/github.com/xo/terminfo/.gitignore create mode 100644 vendor/github.com/xo/terminfo/LICENSE create mode 100644 vendor/github.com/xo/terminfo/README.md create mode 100644 vendor/github.com/xo/terminfo/caps.go create mode 100644 vendor/github.com/xo/terminfo/capvals.go create mode 100644 vendor/github.com/xo/terminfo/color.go create mode 100644 vendor/github.com/xo/terminfo/go.mod create mode 100644 vendor/github.com/xo/terminfo/go.sum create mode 100644 vendor/github.com/xo/terminfo/load.go create mode 100644 vendor/github.com/xo/terminfo/param.go create mode 100644 vendor/github.com/xo/terminfo/stack.go create mode 100644 vendor/github.com/xo/terminfo/terminfo.go create mode 100644 vendor/github.com/xo/terminfo/util.go delete mode 100644 vendor/gopkg.in/yaml.v2/LICENSE delete mode 100644 vendor/gopkg.in/yaml.v2/LICENSE.libyaml delete mode 100644 vendor/gopkg.in/yaml.v2/NOTICE delete mode 100644 vendor/gopkg.in/yaml.v2/README.md delete mode 100644 vendor/gopkg.in/yaml.v2/apic.go delete mode 100644 vendor/gopkg.in/yaml.v2/decode.go delete mode 100644 vendor/gopkg.in/yaml.v2/emitterc.go delete mode 100644 vendor/gopkg.in/yaml.v2/encode.go delete mode 100644 vendor/gopkg.in/yaml.v2/go.mod delete mode 100644 vendor/gopkg.in/yaml.v2/parserc.go delete mode 100644 vendor/gopkg.in/yaml.v2/readerc.go delete mode 100644 vendor/gopkg.in/yaml.v2/resolve.go delete mode 100644 vendor/gopkg.in/yaml.v2/scannerc.go delete mode 100644 vendor/gopkg.in/yaml.v2/sorter.go delete mode 100644 vendor/gopkg.in/yaml.v2/writerc.go delete mode 100644 vendor/gopkg.in/yaml.v2/yaml.go delete mode 100644 vendor/gopkg.in/yaml.v2/yamlh.go delete mode 100644 vendor/gopkg.in/yaml.v2/yamlprivateh.go create mode 100644 vendor/gopkg.in/yaml.v3/LICENSE create mode 100644 vendor/gopkg.in/yaml.v3/NOTICE create mode 100644 vendor/gopkg.in/yaml.v3/README.md create mode 100644 vendor/gopkg.in/yaml.v3/apic.go create mode 100644 vendor/gopkg.in/yaml.v3/decode.go create mode 100644 vendor/gopkg.in/yaml.v3/emitterc.go create mode 100644 vendor/gopkg.in/yaml.v3/encode.go create mode 100644 vendor/gopkg.in/yaml.v3/go.mod create mode 100644 vendor/gopkg.in/yaml.v3/parserc.go create mode 100644 vendor/gopkg.in/yaml.v3/readerc.go create mode 100644 vendor/gopkg.in/yaml.v3/resolve.go create mode 100644 vendor/gopkg.in/yaml.v3/scannerc.go create mode 100644 vendor/gopkg.in/yaml.v3/sorter.go create mode 100644 vendor/gopkg.in/yaml.v3/writerc.go create mode 100644 vendor/gopkg.in/yaml.v3/yaml.go create mode 100644 vendor/gopkg.in/yaml.v3/yamlh.go create mode 100644 vendor/gopkg.in/yaml.v3/yamlprivateh.go (limited to 'vendor') diff --git a/vendor/github.com/gookit/color/.gitignore b/vendor/github.com/gookit/color/.gitignore new file mode 100644 index 000000000..5efa5e3f0 --- /dev/null +++ b/vendor/github.com/gookit/color/.gitignore @@ -0,0 +1,20 @@ +*.log +*.swp +.idea +*.patch +### Go template +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, build with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out +.DS_Store +app +demo diff --git a/vendor/github.com/gookit/color/LICENSE b/vendor/github.com/gookit/color/LICENSE new file mode 100644 index 000000000..d839cdc1a --- /dev/null +++ b/vendor/github.com/gookit/color/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2016 inhere + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/vendor/github.com/gookit/color/README.md b/vendor/github.com/gookit/color/README.md new file mode 100644 index 000000000..134181dc6 --- /dev/null +++ b/vendor/github.com/gookit/color/README.md @@ -0,0 +1,468 @@ +# CLI Color + +![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/gookit/color?style=flat-square) +[![Actions Status](https://github.com/gookit/color/workflows/action-tests/badge.svg)](https://github.com/gookit/color/actions) +[![Codacy Badge](https://api.codacy.com/project/badge/Grade/51b28c5f7ffe4cc2b0f12ecf25ed247f)](https://app.codacy.com/app/inhere/color) +[![GoDoc](https://godoc.org/github.com/gookit/color?status.svg)](https://pkg.go.dev/github.com/gookit/color?tab=overview) +[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/gookit/color)](https://github.com/gookit/color) +[![Build Status](https://travis-ci.org/gookit/color.svg?branch=master)](https://travis-ci.org/gookit/color) +[![Coverage Status](https://coveralls.io/repos/github/gookit/color/badge.svg?branch=master)](https://coveralls.io/github/gookit/color?branch=master) +[![Go Report Card](https://goreportcard.com/badge/github.com/gookit/color)](https://goreportcard.com/report/github.com/gookit/color) + +A command-line color library with true color support, universal API methods and Windows support. + +> **[中文说明](README.zh-CN.md)** + +Basic color preview: + +![basic-color](_examples/images/basic-color2.png) + +Now, 256 colors and RGB colors have also been supported to work in Windows CMD and PowerShell: + +![color-on-cmd-pwsh](_examples/images/color-on-cmd-pwsh.jpg) + +## Features + + - Simple to use, zero dependencies + - Supports rich color output: 16-color (4-bit), 256-color (8-bit), true color (24-bit, RGB) + - 16-color output is the most commonly used and most widely supported, working on any Windows version + - Since `v1.2.4` **the 256-color (8-bit), true color (24-bit) support windows CMD and PowerShell** + - See [this gist](https://gist.github.com/XVilka/8346728) for information on true color support + - Generic API methods: `Print`, `Printf`, `Println`, `Sprint`, `Sprintf` + - Supports HTML tag-style color rendering, such as `message`. + - In addition to using built-in tags, it also supports custom color attributes + - Custom color attributes support the use of 16 color names, 256 color values, rgb color values and hex color values + - Support working on Windows `cmd` and `powerShell` terminal + - Basic colors: `Bold`, `Black`, `White`, `Gray`, `Red`, `Green`, `Yellow`, `Blue`, `Magenta`, `Cyan` + - Additional styles: `Info`, `Note`, `Light`, `Error`, `Danger`, `Notice`, `Success`, `Comment`, `Primary`, `Warning`, `Question`, `Secondary` + - Support by set `NO_COLOR` for disable color or use `FORCE_COLOR` for force open color render. + - Support Rgb, 256, 16 color conversion + +## GoDoc + + - [godoc for gopkg](https://pkg.go.dev/gopkg.in/gookit/color.v1) + - [godoc for github](https://pkg.go.dev/github.com/gookit/color) + +## Install + +```bash +go get github.com/gookit/color +``` + +## Quick start + +```go +package main + +import ( + "fmt" + + "github.com/gookit/color" +) + +func main() { + // quick use package func + color.Redp("Simple to use color") + color.Redln("Simple to use color") + color.Greenp("Simple to use color\n") + color.Cyanln("Simple to use color") + color.Yellowln("Simple to use color") + + // quick use like fmt.Print* + color.Red.Println("Simple to use color") + color.Green.Print("Simple to use color\n") + color.Cyan.Printf("Simple to use %s\n", "color") + color.Yellow.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") + + // internal theme/style: + color.Info.Tips("message") + color.Info.Prompt("message") + color.Info.Println("message") + color.Warn.Println("message") + color.Error.Println("message") + + // use style tag + color.Print("hello, welcome\n") + // Custom label attr: Supports the use of 16 color names, 256 color values, rgb color values and hex color values + color.Println("hello, welcome") + + // 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") +} +``` + +Run demo: `go run ./_examples/demo.go` + +![colored-out](_examples/images/color-demo.jpg) + +## Basic/16 color + +Supported on any Windows version. Provide generic API methods: `Print`, `Printf`, `Println`, `Sprint`, `Sprintf` + +```go +color.Bold.Println("bold message") +color.Black.Println("bold message") +color.White.Println("bold message") +color.Gray.Println("bold message") +color.Red.Println("yellow message") +color.Blue.Println("yellow message") +color.Cyan.Println("yellow message") +color.Yellow.Println("yellow message") +color.Magenta.Println("yellow message") + +// Only use foreground color +color.FgCyan.Printf("Simple to use %s\n", "color") +// Only use background color +color.BgRed.Printf("Simple to use %s\n", "color") +``` + +Run demo: `go run ./_examples/color_16.go` + +![basic-color](_examples/images/basic-color.png) + +### Custom build color + +```go +// Full custom: foreground, background, option +myStyle := color.New(color.FgWhite, color.BgBlack, color.OpBold) +myStyle.Println("custom color style") + +// can also: +color.Style{color.FgCyan, color.OpBold}.Println("custom color style") +``` + +custom set console settings: + +```go +// set console color +color.Set(color.FgCyan) + +// print message +fmt.Print("message") + +// reset console settings +color.Reset() +``` + +### Additional styles + +provide generic API methods: `Print`, `Printf`, `Println`, `Sprint`, `Sprintf` + +print message use defined style: + +```go +color.Info.Println("Info message") +color.Note.Println("Note message") +color.Notice.Println("Notice message") +color.Error.Println("Error message") +color.Danger.Println("Danger message") +color.Warn.Println("Warn message") +color.Debug.Println("Debug message") +color.Primary.Println("Primary message") +color.Question.Println("Question message") +color.Secondary.Println("Secondary message") +``` + +Run demo: `go run ./_examples/theme_basic.go` + +![theme-basic](_examples/images/theme-basic.png) + +**Tips style** + +```go +color.Info.Tips("Info tips message") +color.Note.Tips("Note tips message") +color.Notice.Tips("Notice tips message") +color.Error.Tips("Error tips message") +color.Danger.Tips("Danger tips message") +color.Warn.Tips("Warn tips message") +color.Debug.Tips("Debug tips message") +color.Primary.Tips("Primary tips message") +color.Question.Tips("Question tips message") +color.Secondary.Tips("Secondary tips message") +``` + +Run demo: `go run ./_examples/theme_tips.go` + +![theme-tips](_examples/images/theme-tips.png) + +**Prompt Style** + +```go +color.Info.Prompt("Info prompt message") +color.Note.Prompt("Note prompt message") +color.Notice.Prompt("Notice prompt message") +color.Error.Prompt("Error prompt message") +color.Danger.Prompt("Danger prompt message") +color.Warn.Prompt("Warn prompt message") +color.Debug.Prompt("Debug prompt message") +color.Primary.Prompt("Primary prompt message") +color.Question.Prompt("Question prompt message") +color.Secondary.Prompt("Secondary prompt message") +``` + +Run demo: `go run ./_examples/theme_prompt.go` + +![theme-prompt](_examples/images/theme-prompt.png) + +**Block Style** + +```go +color.Info.Block("Info block message") +color.Note.Block("Note block message") +color.Notice.Block("Notice block message") +color.Error.Block("Error block message") +color.Danger.Block("Danger block message") +color.Warn.Block("Warn block message") +color.Debug.Block("Debug block message") +color.Primary.Block("Primary block message") +color.Question.Block("Question block message") +color.Secondary.Block("Secondary block message") +``` + +Run demo: `go run ./_examples/theme_block.go` + +![theme-block](_examples/images/theme-block.png) + +## 256-color usage + +> 256 colors support Windows CMD, PowerShell environment after `v1.2.4` + +### Set the foreground or background color + +- `color.C256(val uint8, isBg ...bool) Color256` + +```go +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") +``` + +### 256-color style + +Can be used to set foreground and background colors at the same time. + +- `S256(fgAndBg ...uint8) *Style256` + +```go +s := color.S256(32, 203) +s.Println("message") +s.Printf("format %s", "message") +``` + +with options: + +```go +s := color.S256(32, 203) +s.SetOpts(color.Opts{color.OpBold}) + +s.Println("style with options") +s.Printf("style with %s\n", "options") +``` + +Run demo: `go run ./_examples/color_256.go` + +![color-tags](_examples/images/color-256.png) + +## RGB/True color + +> RGB colors support Windows `CMD`, `PowerShell` environment after `v1.2.4` + +**Preview:** + +> Run demo: `Run demo: go run ./_examples/color_rgb.go` + +![color-rgb](_examples/images/color-rgb.png) + +example: + +```go +color.RGB(30, 144, 255).Println("message. use RGB number") + +color.HEX("#1976D2").Println("blue-darken") +color.HEX("#D50000", true).Println("red-accent. use HEX style") + +color.RGBStyleFromString("213,0,0").Println("red-accent. use RGB number") +color.HEXStyle("eee", "D50000").Println("deep-purple color") +``` + +### Set the foreground or background color + +- `color.RGB(r, g, b uint8, isBg ...bool) RGBColor` + +```go +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") +``` + +Create a style from an hexadecimal color string: + +- `color.HEX(hex string, isBg ...bool) RGBColor` + +```go +c := color.HEX("ccc") // can also: "cccccc" "#cccccc" +c.Println("message") +c.Printf("format %s", "message") + +c = color.HEX("aabbcc", true) // as bg color +c.Println("message") +c.Printf("format %s", "message") +``` + +### RGB color style + +Can be used to set the foreground and background colors at the same time. + +- `color.NewRGBStyle(fg RGBColor, bg ...RGBColor) *RGBStyle` + +```go +s := color.NewRGBStyle(RGB(20, 144, 234), RGB(234, 78, 23)) +s.Println("message") +s.Printf("format %s", "message") +``` + +Create a style from an hexadecimal color string: + +- `color.HEXStyle(fg string, bg ...string) *RGBStyle` + +```go +s := color.HEXStyle("11aa23", "eee") +s.Println("message") +s.Printf("format %s", "message") +``` + +with options: + +```go +s := color.HEXStyle("11aa23", "eee") +s.SetOpts(color.Opts{color.OpBold}) + +s.Println("style with options") +s.Printf("style with %s\n", "options") +``` + +## HTML-like tag usage + +**Supported** on Windows `cmd.exe` `PowerShell` . + +```go +// use style tag +color.Print("hello, welcome") +color.Println("hello") +color.Println("hello") +color.Println("hello") + +// custom color attributes +color.Print("hello, welcome\n") + +// Custom label attr: Supports the use of 16 color names, 256 color values, rgb color values and hex color values +color.Println("hello, welcome") +``` + +- `color.Tag` + +```go +// 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") +``` + +Run demo: `go run ./_examples/color_tag.go` + +![color-tags](_examples/images/color-tags.png) + +## Color convert + +Supports conversion between Rgb, 256, 16 colors, `Rgb <=> 256 <=> 16` + +```go +basic := color.Red +basic.Println("basic color") + +c256 := color.Red.C256() +c256.Println("256 color") +c256.C16().Println("basic color") + +rgb := color.Red.RGB() +rgb.Println("rgb color") +rgb.C256().Println("256 color") +``` + +## Func refer + +There are some useful functions reference + +- `Disable()` disable color render +- `SetOutput(io.Writer)` custom set the colored text output writer +- `ForceOpenColor()` force open color render +- `Colors2code(colors ...Color) string` Convert colors to code. return like "32;45;3" +- `ClearCode(str string) string` Use for clear color codes +- `ClearTag(s string) string` clear all color html-tag for a string +- `IsConsole(w io.Writer)` Determine whether w is one of stderr, stdout, stdin +- `HexToRgb(hex string) (rgb []int)` Convert hex color string to RGB numbers +- `RgbToHex(rgb []int) string` Convert RGB to hex code +- More useful func please see https://pkg.go.dev/github.com/gookit/color + +## Project use + +Check out these projects, which use https://github.com/gookit/color : + +- https://github.com/Delta456/box-cli-maker Make Highly Customized Boxes for your CLI + +## Gookit packages + + - [gookit/ini](https://github.com/gookit/ini) Go config management, use INI files + - [gookit/rux](https://github.com/gookit/rux) Simple and fast request router for golang HTTP + - [gookit/gcli](https://github.com/gookit/gcli) build CLI application, tool library, running CLI commands + - [gookit/slog](https://github.com/gookit/slog) Concise and extensible go log library + - [gookit/event](https://github.com/gookit/event) Lightweight event manager and dispatcher implements by Go + - [gookit/cache](https://github.com/gookit/cache) Generic cache use and cache manager for golang. support File, Memory, Redis, Memcached. + - [gookit/config](https://github.com/gookit/config) Go config management. support JSON, YAML, TOML, INI, HCL, ENV and Flags + - [gookit/color](https://github.com/gookit/color) A command-line color library with true color support, universal API methods and Windows support + - [gookit/filter](https://github.com/gookit/filter) Provide filtering, sanitizing, and conversion of golang data + - [gookit/validate](https://github.com/gookit/validate) Use for data validation and filtering. support Map, Struct, Form data + - [gookit/goutil](https://github.com/gookit/goutil) Some utils for the Go: string, array/slice, map, format, cli, env, filesystem, test and more + - More, please see https://github.com/gookit + +## See also + + - [inhere/console](https://github.com/inhere/php-console) + - [xo/terminfo](https://github.com/xo/terminfo) + - [beego/bee](https://github.com/beego/bee) + - [issue9/term](https://github.com/issue9/term) + - [ANSI escape code](https://en.wikipedia.org/wiki/ANSI_escape_code) + - [Standard ANSI color map](https://conemu.github.io/en/AnsiEscapeCodes.html#Standard_ANSI_color_map) + - [Terminal Colors](https://gist.github.com/XVilka/8346728) + +## License + +[MIT](/LICENSE) diff --git a/vendor/github.com/gookit/color/README.zh-CN.md b/vendor/github.com/gookit/color/README.zh-CN.md new file mode 100644 index 000000000..dee1458b0 --- /dev/null +++ b/vendor/github.com/gookit/color/README.zh-CN.md @@ -0,0 +1,472 @@ +# CLI Color + +![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/gookit/color?style=flat-square) +[![Actions Status](https://github.com/gookit/color/workflows/action-tests/badge.svg)](https://github.com/gookit/color/actions) +[![Codacy Badge](https://api.codacy.com/project/badge/Grade/51b28c5f7ffe4cc2b0f12ecf25ed247f)](https://app.codacy.com/app/inhere/color) +[![GoDoc](https://godoc.org/github.com/gookit/color?status.svg)](https://pkg.go.dev/github.com/gookit/color?tab=overview) +[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/gookit/color)](https://github.com/gookit/color) +[![Build Status](https://travis-ci.org/gookit/color.svg?branch=master)](https://travis-ci.org/gookit/color) +[![Coverage Status](https://coveralls.io/repos/github/gookit/color/badge.svg?branch=master)](https://coveralls.io/github/gookit/color?branch=master) +[![Go Report Card](https://goreportcard.com/badge/github.com/gookit/color)](https://goreportcard.com/report/github.com/gookit/color) + +Golang下的命令行色彩使用库, 拥有丰富的色彩渲染输出,通用的API方法,兼容Windows系统 + +> **[EN README](README.md)** + +基本颜色预览: + +![basic-color](_examples/images/basic-color2.png) + +现在,256色和RGB色彩也已经支持windows CMD和PowerShell中工作: + +![color-on-cmd-pwsh](_examples/images/color-on-cmd-pwsh.jpg) + +## 功能特色 + + - 使用简单方便 + - 支持丰富的颜色输出, 16色(4bit),256色(8bit),RGB色彩(24bit, RGB) + - 16色(4bit)是最常用和支持最广的,支持Windows `cmd.exe` + - 自 `v1.2.4` 起 **256色(8bit),RGB色彩(24bit)均支持Windows CMD和PowerShell终端** + - 请查看 [this gist](https://gist.github.com/XVilka/8346728) 了解支持RGB色彩的终端 + - 提供通用的API方法:`Print` `Printf` `Println` `Sprint` `Sprintf` + - 同时支持html标签式的颜色渲染,除了使用内置标签,同时支持自定义颜色属性 + - 例如: `this an message` 标签内部的文本将会渲染为绿色字体 + - 自定义颜色属性: 支持使用16色彩名称,256色彩值,rgb色彩值以及hex色彩值 + - 基础色彩: `Bold` `Black` `White` `Gray` `Red` `Green` `Yellow` `Blue` `Magenta` `Cyan` + - 扩展风格: `Info` `Note` `Light` `Error` `Danger` `Notice` `Success` `Comment` `Primary` `Warning` `Question` `Secondary` + - 支持通过设置环境变量 `NO_COLOR` 来禁用色彩,或者使用 `FORCE_COLOR` 来强制使用色彩渲染. + - 支持 Rgb, 256, 16 色彩之间的互相转换 + - 支持Linux、Mac,同时兼容Windows系统环境 + +## GoDoc + + - [godoc for gopkg](https://pkg.go.dev/gopkg.in/gookit/color.v1) + - [godoc for github](https://pkg.go.dev/github.com/gookit/color) + +## 安装 + +```bash +go get github.com/gookit/color +``` + +## 快速开始 + +如下,引入当前包就可以快速的使用 + +```go +package main + +import ( + "fmt" + + "github.com/gookit/color" +) + +func main() { + // 简单快速的使用,跟 fmt.Print* 类似 + color.Redp("Simple to use color") + color.Redln("Simple to use color") + color.Greenp("Simple to use color\n") + color.Cyanln("Simple to use color") + color.Yellowln("Simple to use color") + + // 简单快速的使用,跟 fmt.Print* 类似 + color.Red.Println("Simple to use color") + color.Green.Print("Simple to use color\n") + color.Cyan.Printf("Simple to use %s\n", "color") + color.Yellow.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("hello, welcome\n") + // 自定义标签: 支持使用16色彩名称,256色彩值,rgb色彩值以及hex色彩值 + color.Println("hello, welcome") + + // 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/demo.go` + +![colored-out](_examples/images/color-demo.jpg) + +## 基础颜色(16-color) + +提供通用的API方法:`Print` `Printf` `Println` `Sprint` `Sprintf` + +> 支持在windows `cmd.exe` `powerShell` 等终端使用 + +```go +color.Bold.Println("bold message") +color.Black.Println("bold message") +color.White.Println("bold message") +color.Gray.Println("bold message") +color.Red.Println("yellow message") +color.Blue.Println("yellow message") +color.Cyan.Println("yellow message") +color.Yellow.Println("yellow message") +color.Magenta.Println("yellow message") + +// Only use foreground color +color.FgCyan.Printf("Simple to use %s\n", "color") +// Only use background color +color.BgRed.Printf("Simple to use %s\n", "color") +``` + +> 运行demo: `go run ./_examples/color_16.go` + +![basic-color](_examples/images/basic-color.png) + +### 构建风格 + +```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") +``` + +直接设置控制台属性: + +```go +// 设置console颜色 +color.Set(color.FgCyan) + +// 输出信息 +fmt.Print("message") + +// 重置console颜色 +color.Reset() +``` + +> 当然,color已经内置丰富的色彩风格支持 + +### 扩展风格方法 + +提供通用的API方法:`Print` `Printf` `Println` `Sprint` `Sprintf` + +> 支持在windows `cmd.exe` `powerShell` 等终端使用 + +基础使用: + +```go +// print message +color.Info.Println("Info message") +color.Note.Println("Note message") +color.Notice.Println("Notice message") +color.Error.Println("Error message") +color.Danger.Println("Danger message") +color.Warn.Println("Warn message") +color.Debug.Println("Debug message") +color.Primary.Println("Primary message") +color.Question.Println("Question message") +color.Secondary.Println("Secondary message") +``` + +Run demo: `go run ./_examples/theme_basic.go` + +![theme-basic](_examples/images/theme-basic.png) + +**简约提示风格** + +```go +color.Info.Tips("Info tips message") +color.Note.Tips("Note tips message") +color.Notice.Tips("Notice tips message") +color.Error.Tips("Error tips message") +color.Danger.Tips("Danger tips message") +color.Warn.Tips("Warn tips message") +color.Debug.Tips("Debug tips message") +color.Primary.Tips("Primary tips message") +color.Question.Tips("Question tips message") +color.Secondary.Tips("Secondary tips message") +``` + +Run demo: `go run ./_examples/theme_tips.go` + +![theme-tips](_examples/images/theme-tips.png) + +**着重提示风格** + +```go +color.Info.Prompt("Info prompt message") +color.Note.Prompt("Note prompt message") +color.Notice.Prompt("Notice prompt message") +color.Error.Prompt("Error prompt message") +color.Danger.Prompt("Danger prompt message") +``` + +Run demo: `go run ./_examples/theme_prompt.go` + +![theme-prompt](_examples/images/theme-prompt.png) + +**强调提示风格** + +```go +color.Warn.Block("Warn block message") +color.Debug.Block("Debug block message") +color.Primary.Block("Primary block message") +color.Question.Block("Question block message") +color.Secondary.Block("Secondary block message") +``` + +Run demo: `go run ./_examples/theme_block.go` + +![theme-block](_examples/images/theme-block.png) + +## 256 色彩使用 + +> 256色彩在 `v1.2.4` 后支持Windows CMD,PowerShell 环境 + +### 使用前景或后景色 + + - `color.C256(val uint8, isBg ...bool) Color256` + +```go +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") +``` + +### 使用256 色彩风格 + +> 可同时设置前景和背景色 + +- `color.S256(fgAndBg ...uint8) *Style256` + +```go +s := color.S256(32, 203) +s.Println("message") +s.Printf("format %s", "message") +``` + +可以同时添加选项设置: + +```go +s := color.S256(32, 203) +s.SetOpts(color.Opts{color.OpBold}) + +s.Println("style with options") +s.Printf("style with %s\n", "options") +``` + +> 运行 demo: `go run ./_examples/color_256.go` + +![color-tags](_examples/images/color-256.png) + +## RGB/True色彩使用 + +> RGB色彩在 `v1.2.4` 后支持 Windows `CMD`, `PowerShell` 环境 + +**效果预览:** + +> 运行 demo: `Run demo: go run ./_examples/color_rgb.go` + +![color-rgb](_examples/images/color-rgb.png) + +代码示例: + +```go +color.RGB(30, 144, 255).Println("message. use RGB number") + +color.HEX("#1976D2").Println("blue-darken") +color.HEX("#D50000", true).Println("red-accent. use HEX style") + +color.RGBStyleFromString("213,0,0").Println("red-accent. use RGB number") +color.HEXStyle("eee", "D50000").Println("deep-purple color") +``` + +### 使用前景或后景色 + +- `color.RGB(r, g, b uint8, isBg ...bool) RGBColor` + +```go +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进制颜色创建 + +```go +c := color.HEX("ccc") // 也可以写为: "cccccc" "#cccccc" +c.Println("message") +c.Printf("format %s", "message") + +c = color.HEX("aabbcc", true) // as bg color +c.Println("message") +c.Printf("format %s", "message") +``` + +### 使用RGB风格 + +> 可同时设置前景和背景色 + +- `color.NewRGBStyle(fg RGBColor, bg ...RGBColor) *RGBStyle` + +```go +s := color.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进制颜色创建 + +```go +s := color.HEXStyle("11aa23", "eee") +s.Println("message") +s.Printf("format %s", "message") +``` + +- 可以同时添加选项设置: + +```go +s := color.HEXStyle("11aa23", "eee") +s.SetOpts(color.Opts{color.OpBold}) + +s.Println("style with options") +s.Printf("style with %s\n", "options") +``` + +## 使用颜色标签 + +> **支持** 在windows `cmd.exe` `PowerShell` 使用 + +使用内置的颜色标签,可以非常方便简单的构建自己需要的任何格式 + +> 同时支持自定义颜色属性: 支持使用16色彩名称,256色彩值,rgb色彩值以及hex色彩值 + +```go +// 使用内置的 color tag +color.Print("hello, welcome") +color.Println("hello") +color.Println("hello") +color.Println("hello") + +// 自定义颜色属性 +color.Print("hello, welcome\n") + +// 自定义颜色属性: 支持使用16色彩名称,256色彩值,rgb色彩值以及hex色彩值 +color.Println("hello, welcome") +``` + +- 使用 `color.Tag` + +给后面输出的文本信息加上给定的颜色风格标签 + +```go +// 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/color_tag.go` + +![color-tags](_examples/images/color-tags.png) + +## 颜色转换 + +支持 Rgb, 256, 16 色彩之间的互相转换 `Rgb <=> 256 <=> 16` + +```go +basic := color.Red +basic.Println("basic color") + +c256 := color.Red.C256() +c256.Println("256 color") +c256.C16().Println("basic color") + +rgb := color.Red.RGB() +rgb.Println("rgb color") +rgb.C256().Println("256 color") +``` + +## 方法参考 + +一些有用的工具方法参考 + +- `Disable()` disable color render +- `SetOutput(io.Writer)` custom set the colored text output writer +- `ForceOpenColor()` force open color render +- `ClearCode(str string) string` Use for clear color codes +- `Colors2code(colors ...Color) string` Convert colors to code. return like "32;45;3" +- `ClearTag(s string) string` clear all color html-tag for a string +- `IsConsole(w io.Writer)` Determine whether w is one of stderr, stdout, stdin +- `HexToRgb(hex string) (rgb []int)` Convert hex color string to RGB numbers +- `RgbToHex(rgb []int) string` Convert RGB to hex code +- 更多请查看文档 https://pkg.go.dev/github.com/gookit/color + +## 使用color的项目 + +看看这些使用了 https://github.com/gookit/color 的项目: + +- https://github.com/Delta456/box-cli-maker Make Highly Customized Boxes for your CLI + +## Gookit 工具包 + + - [gookit/ini](https://github.com/gookit/ini) INI配置读取管理,支持多文件加载,数据覆盖合并, 解析ENV变量, 解析变量引用 + - [gookit/rux](https://github.com/gookit/rux) Simple and fast request router for golang HTTP + - [gookit/gcli](https://github.com/gookit/gcli) Go的命令行应用,工具库,运行CLI命令,支持命令行色彩,用户交互,进度显示,数据格式化显示 + - [gookit/slog](https://github.com/gookit/slog) 简洁易扩展的go日志库 + - [gookit/event](https://github.com/gookit/event) Go实现的轻量级的事件管理、调度程序库, 支持设置监听器的优先级, 支持对一组事件进行监听 + - [gookit/cache](https://github.com/gookit/cache) 通用的缓存使用包装库,通过包装各种常用的驱动,来提供统一的使用API + - [gookit/config](https://github.com/gookit/config) Go应用配置管理,支持多种格式(JSON, YAML, TOML, INI, HCL, ENV, Flags),多文件加载,远程文件加载,数据合并 + - [gookit/color](https://github.com/gookit/color) CLI 控制台颜色渲染工具库, 拥有简洁的使用API,支持16色,256色,RGB色彩渲染输出 + - [gookit/filter](https://github.com/gookit/filter) 提供对Golang数据的过滤,净化,转换 + - [gookit/validate](https://github.com/gookit/validate) Go通用的数据验证与过滤库,使用简单,内置大部分常用验证、过滤器 + - [gookit/goutil](https://github.com/gookit/goutil) Go 的一些工具函数,格式化,特殊处理,常用信息获取等 + - 更多请查看 https://github.com/gookit + +## 参考项目 + + - [inhere/console](https://github.com/inhere/php-console) + - [xo/terminfo](https://github.com/xo/terminfo) + - [beego/bee](https://github.com/beego/bee) + - [issue9/term](https://github.com/issue9/term) + - [ANSI转义序列](https://zh.wikipedia.org/wiki/ANSI转义序列) + - [Standard ANSI color map](https://conemu.github.io/en/AnsiEscapeCodes.html#Standard_ANSI_color_map) + - [Terminal Colors](https://gist.github.com/XVilka/8346728) + +## License + +MIT diff --git a/vendor/github.com/gookit/color/color.go b/vendor/github.com/gookit/color/color.go new file mode 100644 index 000000000..edb2a5d7b --- /dev/null +++ b/vendor/github.com/gookit/color/color.go @@ -0,0 +1,238 @@ +/* +Package color is Command line color library. +Support rich color rendering output, universal API method, compatible with Windows system + +Source code and other details for the project are available at GitHub: + + https://github.com/gookit/color + +More usage please see README and tests. +*/ +package color + +import ( + "fmt" + "io" + "os" + "regexp" + + "github.com/xo/terminfo" +) + +// terminal color available level alias of the terminfo.ColorLevel* +const ( + LevelNo = terminfo.ColorLevelNone // not support color. + Level16 = terminfo.ColorLevelBasic // 3/4 bit color supported + Level256 = terminfo.ColorLevelHundreds // 8 bit color supported + LevelRgb = terminfo.ColorLevelMillions // (24 bit)true color supported +) + +// color render templates +// ESC 操作的表示: +// "\033"(Octal 8进制) = "\x1b"(Hexadecimal 16进制) = 27 (10进制) +const ( + SettingTpl = "\x1b[%sm" + FullColorTpl = "\x1b[%sm%s\x1b[0m" +) + +// ResetSet Close all properties. +const ResetSet = "\x1b[0m" + +// CodeExpr regex to clear color codes eg "\033[1;36mText\x1b[0m" +const CodeExpr = `\033\[[\d;?]+m` + +var ( + // Enable switch color render and display + // + // NOTICE: + // if ENV: NO_COLOR is not empty, will disable color render. + Enable = os.Getenv("NO_COLOR") == "" + // RenderTag render HTML tag on call color.Xprint, color.PrintX + RenderTag = true + // debug mode for development. + // + // set env: + // COLOR_DEBUG_MODE=on + // or: + // COLOR_DEBUG_MODE=on go run ./_examples/envcheck.go + debugMode = os.Getenv("COLOR_DEBUG_MODE") == "on" + // inner errors record on detect color level + innerErrs []error + // output the default io.Writer message print + output io.Writer = os.Stdout + // mark current env, It's like in `cmd.exe` + // if not in windows, it's always is False. + isLikeInCmd bool + // the color support level for current terminal + // needVTP - need enable VTP, only for windows OS + colorLevel, needVTP = detectTermColorLevel() + // match color codes + codeRegex = regexp.MustCompile(CodeExpr) + // mark current env is support color. + // Always: isLikeInCmd != supportColor + // supportColor = IsSupportColor() +) + +// TermColorLevel value on current ENV +func TermColorLevel() terminfo.ColorLevel { + return colorLevel +} + +// SupportColor on the current ENV +func SupportColor() bool { + return colorLevel > terminfo.ColorLevelNone +} + +// Support16Color on the current ENV +// func Support16Color() bool { +// return colorLevel > terminfo.ColorLevelNone +// } + +// Support256Color on the current ENV +func Support256Color() bool { + return colorLevel > terminfo.ColorLevelBasic +} + +// SupportTrueColor on the current ENV +func SupportTrueColor() bool { + return colorLevel > terminfo.ColorLevelHundreds +} + +/************************************************************* + * global settings + *************************************************************/ + +// Set set console color attributes +func Set(colors ...Color) (int, error) { + code := Colors2code(colors...) + err := SetTerminal(code) + return 0, err +} + +// Reset reset console color attributes +func Reset() (int, error) { + err := ResetTerminal() + return 0, err +} + +// Disable disable color output +func Disable() bool { + oldVal := Enable + Enable = false + return oldVal +} + +// NotRenderTag on call color.Xprint, color.PrintX +func NotRenderTag() { + RenderTag = false +} + +// SetOutput set default colored text output +func SetOutput(w io.Writer) { + output = w +} + +// ResetOutput reset output +func ResetOutput() { + output = os.Stdout +} + +// ResetOptions reset all package option setting +func ResetOptions() { + RenderTag = true + Enable = true + output = os.Stdout +} + +// ForceColor force open color render +func ForceSetColorLevel(level terminfo.ColorLevel) terminfo.ColorLevel { + oldLevelVal := colorLevel + colorLevel = level + return oldLevelVal +} + +// ForceColor force open color render +func ForceColor() terminfo.ColorLevel { + return ForceOpenColor() +} + +// ForceOpenColor force open color render +func ForceOpenColor() terminfo.ColorLevel { + // TODO should set level to ? + return ForceSetColorLevel(terminfo.ColorLevelMillions) +} + +// IsLikeInCmd check result +// Deprecated +func IsLikeInCmd() bool { + return isLikeInCmd +} + +// InnerErrs info +func InnerErrs() []error { + return innerErrs +} + +/************************************************************* + * render color code + *************************************************************/ + +// RenderCode render message by color code. +// Usage: +// msg := RenderCode("3;32;45", "some", "message") +func RenderCode(code string, args ...interface{}) string { + var message string + if ln := len(args); ln == 0 { + return "" + } + + message = fmt.Sprint(args...) + if len(code) == 0 { + return message + } + + // disabled OR not support color + if !Enable || !SupportColor() { + return ClearCode(message) + } + + return fmt.Sprintf(FullColorTpl, code, message) +} + +// RenderWithSpaces Render code with spaces. +// If the number of args is > 1, a space will be added between the args +func RenderWithSpaces(code string, args ...interface{}) string { + message := formatArgsForPrintln(args) + if len(code) == 0 { + return message + } + + // disabled OR not support color + if !Enable || !SupportColor() { + return ClearCode(message) + } + + return fmt.Sprintf(FullColorTpl, code, message) +} + +// RenderString render a string with color code. +// Usage: +// msg := RenderString("3;32;45", "a message") +func RenderString(code string, str string) string { + if len(code) == 0 || str == "" { + return str + } + + // disabled OR not support color + if !Enable || !SupportColor() { + return ClearCode(str) + } + + return fmt.Sprintf(FullColorTpl, code, str) +} + +// ClearCode clear color codes. +// eg: "\033[36;1mText\x1b[0m" -> "Text" +func ClearCode(str string) string { + return codeRegex.ReplaceAllString(str, "") +} diff --git a/vendor/github.com/gookit/color/color_16.go b/vendor/github.com/gookit/color/color_16.go new file mode 100644 index 000000000..28e1048e0 --- /dev/null +++ b/vendor/github.com/gookit/color/color_16.go @@ -0,0 +1,440 @@ +package color + +import ( + "fmt" + "strconv" +) + +// Color Color16, 16 color value type +// 3(2^3=8) OR 4(2^4=16) bite color. +type Color uint8 +type Basic = Color // alias of Color + +// Opts basic color options. code: 0 - 9 +type Opts []Color + +// Add option value +func (o *Opts) Add(ops ...Color) { + for _, op := range ops { + if uint8(op) < 10 { + *o = append(*o, op) + } + } +} + +// IsValid options +func (o Opts) IsValid() bool { + return len(o) > 0 +} + +// IsEmpty options +func (o Opts) IsEmpty() bool { + return len(o) == 0 +} + +// String options to string. eg: "1;3" +func (o Opts) String() string { + return Colors2code(o...) +} + +/************************************************************* + * Basic 16 color definition + *************************************************************/ + +// Base value for foreground/background color +const ( + FgBase uint8 = 30 + BgBase uint8 = 40 + // hi color base code + HiFgBase uint8 = 90 + HiBgBase uint8 = 100 +) + +// Foreground colors. basic foreground colors 30 - 37 +const ( + FgBlack Color = iota + 30 + FgRed + FgGreen + FgYellow + FgBlue + FgMagenta // 品红 + FgCyan // 青色 + FgWhite + // FgDefault revert default FG + FgDefault Color = 39 +) + +// Extra foreground color 90 - 97(非标准) +const ( + FgDarkGray Color = iota + 90 // 亮黑(灰) + FgLightRed + FgLightGreen + FgLightYellow + FgLightBlue + FgLightMagenta + FgLightCyan + FgLightWhite + // FgGray is alias of FgDarkGray + FgGray Color = 90 // 亮黑(灰) +) + +// Background colors. basic background colors 40 - 47 +const ( + BgBlack Color = iota + 40 + BgRed + BgGreen + BgYellow // BgBrown like yellow + BgBlue + BgMagenta + BgCyan + BgWhite + // BgDefault revert default BG + BgDefault Color = 49 +) + +// Extra background color 100 - 107(非标准) +const ( + BgDarkGray Color = iota + 100 + BgLightRed + BgLightGreen + BgLightYellow + BgLightBlue + BgLightMagenta + BgLightCyan + BgLightWhite + // BgGray is alias of BgDarkGray + BgGray Color = 100 +) + +// Option settings +const ( + OpReset Color = iota // 0 重置所有设置 + OpBold // 1 加粗 + OpFuzzy // 2 模糊(不是所有的终端仿真器都支持) + OpItalic // 3 斜体(不是所有的终端仿真器都支持) + OpUnderscore // 4 下划线 + OpBlink // 5 闪烁 + OpFastBlink // 5 快速闪烁(未广泛支持) + OpReverse // 7 颠倒的 交换背景色与前景色 + OpConcealed // 8 隐匿的 + OpStrikethrough // 9 删除的,删除线(未广泛支持) +) + +// There are basic and light foreground color aliases +const ( + Red = FgRed + Cyan = FgCyan + Gray = FgDarkGray // is light Black + Blue = FgBlue + Black = FgBlack + Green = FgGreen + White = FgWhite + Yellow = FgYellow + Magenta = FgMagenta + + // special + + Bold = OpBold + Normal = FgDefault + + // extra light + + LightRed = FgLightRed + LightCyan = FgLightCyan + LightBlue = FgLightBlue + LightGreen = FgLightGreen + LightWhite = FgLightWhite + LightYellow = FgLightYellow + LightMagenta = FgLightMagenta + + HiRed = FgLightRed + HiCyan = FgLightCyan + HiBlue = FgLightBlue + HiGreen = FgLightGreen + HiWhite = FgLightWhite + HiYellow = FgLightYellow + HiMagenta = FgLightMagenta + + BgHiRed = BgLightRed + BgHiCyan = BgLightCyan + BgHiBlue = BgLightBlue + BgHiGreen = BgLightGreen + BgHiWhite = BgLightWhite + BgHiYellow = BgLightYellow + BgHiMagenta = BgLightMagenta +) + +// Bit4 an method for create Color +func Bit4(code uint8) Color { + return Color(code) +} + +/************************************************************* + * Color render methods + *************************************************************/ + +// Name get color code name. +func (c Color) Name() string { + name, ok := basic2nameMap[uint8(c)] + if ok { + return name + } + return "unknown" +} + +// Text render a text message +func (c Color) Text(message string) string { + return RenderString(c.String(), message) +} + +// Render messages by color setting +// Usage: +// green := color.FgGreen.Render +// fmt.Println(green("message")) +func (c Color) Render(a ...interface{}) string { + return RenderCode(c.String(), a...) +} + +// Renderln messages by color setting. +// like Println, will add spaces for each argument +// Usage: +// green := color.FgGreen.Renderln +// fmt.Println(green("message")) +func (c Color) Renderln(a ...interface{}) string { + return RenderWithSpaces(c.String(), a...) +} + +// Sprint render messages by color setting. is alias of the Render() +func (c Color) Sprint(a ...interface{}) string { + return RenderCode(c.String(), a...) +} + +// Sprintf format and render message. +// Usage: +// green := color.Green.Sprintf +// colored := green("message") +func (c Color) Sprintf(format string, args ...interface{}) string { + return RenderString(c.String(), fmt.Sprintf(format, args...)) +} + +// Print messages. +// Usage: +// color.Green.Print("message") +// OR: +// green := color.FgGreen.Print +// green("message") +func (c Color) Print(args ...interface{}) { + doPrintV2(c.Code(), fmt.Sprint(args...)) +} + +// Printf format and print messages. +// Usage: +// color.Cyan.Printf("string %s", "arg0") +func (c Color) Printf(format string, a ...interface{}) { + doPrintV2(c.Code(), fmt.Sprintf(format, a...)) +} + +// Println messages with new line +func (c Color) Println(a ...interface{}) { + doPrintlnV2(c.String(), a) +} + +// Light current color. eg: 36(FgCyan) -> 96(FgLightCyan). +// Usage: +// lightCyan := Cyan.Light() +// lightCyan.Print("message") +func (c Color) Light() Color { + val := int(c) + if val >= 30 && val <= 47 { + return Color(uint8(c) + 60) + } + + // don't change + return c +} + +// Darken current color. eg. 96(FgLightCyan) -> 36(FgCyan) +// Usage: +// cyan := LightCyan.Darken() +// cyan.Print("message") +func (c Color) Darken() Color { + val := int(c) + if val >= 90 && val <= 107 { + return Color(uint8(c) - 60) + } + + // don't change + return c +} + +// C256 convert 16 color to 256-color code. +func (c Color) C256() Color256 { + val := uint8(c) + if val < 10 { // is option code + return emptyC256 // empty + } + + var isBg uint8 + if val >= BgBase && val <= 47 { // is bg + isBg = AsBg + val = val - 10 // to fg code + } else if val >= HiBgBase && val <= 107 { // is hi bg + isBg = AsBg + val = val - 10 // to fg code + } + + if c256, ok := basicTo256Map[val]; ok { + return Color256{c256, isBg} + } + + // use raw value direct convert + return Color256{val} +} + +// RGB convert 16 color to 256-color code. +func (c Color) RGB() RGBColor { + val := uint8(c) + if val < 10 { // is option code + return emptyRGBColor + } + + return HEX(Basic2hex(val)) +} + +// Code convert to code string. eg "35" +func (c Color) Code() string { + // return fmt.Sprintf("%d", c) + return strconv.Itoa(int(c)) +} + +// String convert to code string. eg "35" +func (c Color) String() string { + // return fmt.Sprintf("%d", c) + return strconv.Itoa(int(c)) +} + +// IsValid color value +func (c Color) IsValid() bool { + return c < 107 +} + +/************************************************************* + * basic color maps + *************************************************************/ + +// FgColors foreground colors map +var FgColors = map[string]Color{ + "black": FgBlack, + "red": FgRed, + "green": FgGreen, + "yellow": FgYellow, + "blue": FgBlue, + "magenta": FgMagenta, + "cyan": FgCyan, + "white": FgWhite, + "default": FgDefault, +} + +// BgColors background colors map +var BgColors = map[string]Color{ + "black": BgBlack, + "red": BgRed, + "green": BgGreen, + "yellow": BgYellow, + "blue": BgBlue, + "magenta": BgMagenta, + "cyan": BgCyan, + "white": BgWhite, + "default": BgDefault, +} + +// ExFgColors extra foreground colors map +var ExFgColors = map[string]Color{ + "darkGray": FgDarkGray, + "lightRed": FgLightRed, + "lightGreen": FgLightGreen, + "lightYellow": FgLightYellow, + "lightBlue": FgLightBlue, + "lightMagenta": FgLightMagenta, + "lightCyan": FgLightCyan, + "lightWhite": FgLightWhite, +} + +// ExBgColors extra background colors map +var ExBgColors = map[string]Color{ + "darkGray": BgDarkGray, + "lightRed": BgLightRed, + "lightGreen": BgLightGreen, + "lightYellow": BgLightYellow, + "lightBlue": BgLightBlue, + "lightMagenta": BgLightMagenta, + "lightCyan": BgLightCyan, + "lightWhite": BgLightWhite, +} + +// Options color options map +// Deprecated +// NOTICE: please use AllOptions instead. +var Options = AllOptions + +// AllOptions color options map +var AllOptions = map[string]Color{ + "reset": OpReset, + "bold": OpBold, + "fuzzy": OpFuzzy, + "italic": OpItalic, + "underscore": OpUnderscore, + "blink": OpBlink, + "reverse": OpReverse, + "concealed": OpConcealed, +} + +var ( + // TODO basic name alias + // basicNameAlias = map[string]string{} + + // basic color name to code + name2basicMap = initName2basicMap() + // basic2nameMap basic color code to name + basic2nameMap = map[uint8]string{ + 30: "black", + 31: "red", + 32: "green", + 33: "yellow", + 34: "blue", + 35: "magenta", + 36: "cyan", + 37: "white", + // hi color code + 90: "lightBlack", + 91: "lightRed", + 92: "lightGreen", + 93: "lightYellow", + 94: "lightBlue", + 95: "lightMagenta", + 96: "lightCyan", + 97: "lightWhite", + // options + 0: "reset", + 1: "bold", + 2: "fuzzy", + 3: "italic", + 4: "underscore", + 5: "blink", + 7: "reverse", + 8: "concealed", + } +) + +// Basic2nameMap data +func Basic2nameMap() map[uint8]string { + return basic2nameMap +} + +func initName2basicMap() map[string]uint8 { + n2b := make(map[string]uint8, len(basic2nameMap)) + for u, s := range basic2nameMap { + n2b[s] = u + } + return n2b +} diff --git a/vendor/github.com/gookit/color/color_256.go b/vendor/github.com/gookit/color/color_256.go new file mode 100644 index 000000000..efd6dca30 --- /dev/null +++ b/vendor/github.com/gookit/color/color_256.go @@ -0,0 +1,308 @@ +package color + +import ( + "fmt" + "strconv" + "strings" +) + +/* +from wikipedia, 256 color: + ESC[ … 38;5; … m选择前景色 + ESC[ … 48;5; … m选择背景色 + 0- 7:标准颜色(同 ESC[30–37m) + 8- 15:高强度颜色(同 ESC[90–97m) + 16-231:6 × 6 × 6 立方(216色): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5) + 232-255:从黑到白的24阶灰度色 +*/ + +// tpl for 8 bit 256 color(`2^8`) +// +// format: +// ESC[ … 38;5; … m // 选择前景色 +// ESC[ … 48;5; … m // 选择背景色 +// +// example: +// fg "\x1b[38;5;242m" +// bg "\x1b[48;5;208m" +// both "\x1b[38;5;242;48;5;208m" +// +// links: +// https://zh.wikipedia.org/wiki/ANSI%E8%BD%AC%E4%B9%89%E5%BA%8F%E5%88%97#8位 +const ( + TplFg256 = "38;5;%d" + TplBg256 = "48;5;%d" + Fg256Pfx = "38;5;" + Bg256Pfx = "48;5;" +) + +/************************************************************* + * 8bit(256) Color: Bit8Color Color256 + *************************************************************/ + +// Color256 256 color (8 bit), uint8 range at 0 - 255 +// +// 颜色值使用10进制和16进制都可 0x98 = 152 +// +// The color consists of two uint8: +// 0: color value +// 1: color type; Fg=0, Bg=1, >1: unset value +// +// example: +// fg color: [152, 0] +// bg color: [152, 1] +// +// NOTICE: now support 256 color on windows CMD, PowerShell +// lint warn - Name starts with package name +type Color256 [2]uint8 +type Bit8Color = Color256 // alias + +var emptyC256 = Color256{1: 99} + +// Bit8 create a color256 +func Bit8(val uint8, isBg ...bool) Color256 { + return C256(val, isBg...) +} + +// C256 create a color256 +func C256(val uint8, isBg ...bool) Color256 { + bc := Color256{val} + + // mark is bg color + if len(isBg) > 0 && isBg[0] { + bc[1] = AsBg + } + + return bc +} + +// Set terminal by 256 color code +func (c Color256) Set() error { + return SetTerminal(c.String()) +} + +// Reset terminal. alias of the ResetTerminal() +func (c Color256) Reset() error { + return ResetTerminal() +} + +// Print print message +func (c Color256) Print(a ...interface{}) { + doPrintV2(c.String(), fmt.Sprint(a...)) +} + +// Printf format and print message +func (c Color256) Printf(format string, a ...interface{}) { + doPrintV2(c.String(), fmt.Sprintf(format, a...)) +} + +// Println print message with newline +func (c Color256) Println(a ...interface{}) { + doPrintlnV2(c.String(), a) +} + +// Sprint returns rendered message +func (c Color256) Sprint(a ...interface{}) string { + return RenderCode(c.String(), a...) +} + +// Sprintf returns format and rendered message +func (c Color256) Sprintf(format string, a ...interface{}) string { + return RenderString(c.String(), fmt.Sprintf(format, a...)) +} + +// C16 convert color-256 to 16 color. +func (c Color256) C16() Color { + return c.Basic() +} + +// Basic convert color-256 to basic 16 color. +func (c Color256) Basic() Color { + return Color(c[0]) // TODO +} + +// RGB convert color-256 to RGB color. +func (c Color256) RGB() RGBColor { + return RGBFromSlice(C256ToRgb(c[0]), c[1] == AsBg) +} + +// RGBColor convert color-256 to RGB color. +func (c Color256) RGBColor() RGBColor { + return c.RGB() +} + +// Value return color value +func (c Color256) Value() uint8 { + return c[0] +} + +// Code convert to color code string. eg: "12" +func (c Color256) Code() string { + return strconv.Itoa(int(c[0])) +} + +// FullCode convert to color code string with prefix. eg: "38;5;12" +func (c Color256) FullCode() string { + return c.String() +} + +// String convert to color code string with prefix. eg: "38;5;12" +func (c Color256) String() string { + if c[1] == AsFg { // 0 is Fg + // return fmt.Sprintf(TplFg256, c[0]) + return Fg256Pfx + strconv.Itoa(int(c[0])) + } + + if c[1] == AsBg { // 1 is Bg + // return fmt.Sprintf(TplBg256, c[0]) + return Bg256Pfx + strconv.Itoa(int(c[0])) + } + + return "" // empty +} + +// IsFg color +func (c Color256) IsFg() bool { + return c[1] == AsFg +} + +// ToFg 256 color +func (c Color256) ToFg() Color256 { + c[1] = AsFg + return c +} + +// IsBg color +func (c Color256) IsBg() bool { + return c[1] == AsBg +} + +// ToBg 256 color +func (c Color256) ToBg() Color256 { + c[1] = AsBg + return c +} + +// IsEmpty value +func (c Color256) IsEmpty() bool { + return c[1] > 1 +} + +/************************************************************* + * 8bit(256) Style + *************************************************************/ + +// Style256 definition +// +// 前/背景色 +// 都是由两位uint8组成, 第一位是色彩值; +// 第二位与 Bit8Color 不一样的是,在这里表示是否设置了值 0 未设置 !=0 已设置 +type Style256 struct { + // p Printer + + // Name of the style + Name string + // color options of the style + opts Opts + // fg and bg color + fg, bg Color256 +} + +// S256 create a color256 style +// Usage: +// s := color.S256() +// s := color.S256(132) // fg +// s := color.S256(132, 203) // fg and bg +func S256(fgAndBg ...uint8) *Style256 { + s := &Style256{} + vl := len(fgAndBg) + if vl > 0 { // with fg + s.fg = Color256{fgAndBg[0], 1} + + if vl > 1 { // and with bg + s.bg = Color256{fgAndBg[1], 1} + } + } + + return s +} + +// Set fg and bg color value, can also with color options +func (s *Style256) Set(fgVal, bgVal uint8, opts ...Color) *Style256 { + s.fg = Color256{fgVal, 1} + s.bg = Color256{bgVal, 1} + s.opts.Add(opts...) + return s +} + +// SetBg set bg color value +func (s *Style256) SetBg(bgVal uint8) *Style256 { + s.bg = Color256{bgVal, 1} + return s +} + +// SetFg set fg color value +func (s *Style256) SetFg(fgVal uint8) *Style256 { + s.fg = Color256{fgVal, 1} + return s +} + +// SetOpts set options +func (s *Style256) SetOpts(opts Opts) *Style256 { + s.opts = opts + return s +} + +// AddOpts add options +func (s *Style256) AddOpts(opts ...Color) *Style256 { + s.opts.Add(opts...) + return s +} + +// Print message +func (s *Style256) Print(a ...interface{}) { + doPrintV2(s.String(), fmt.Sprint(a...)) +} + +// Printf format and print message +func (s *Style256) Printf(format string, a ...interface{}) { + doPrintV2(s.String(), fmt.Sprintf(format, a...)) +} + +// Println print message with newline +func (s *Style256) Println(a ...interface{}) { + doPrintlnV2(s.String(), a) +} + +// Sprint returns rendered message +func (s *Style256) Sprint(a ...interface{}) string { + return RenderCode(s.Code(), a...) +} + +// Sprintf returns format and rendered message +func (s *Style256) Sprintf(format string, a ...interface{}) string { + return RenderString(s.Code(), fmt.Sprintf(format, a...)) +} + +// Code convert to color code string +func (s *Style256) Code() string { + return s.String() +} + +// String convert to color code string +func (s *Style256) String() string { + var ss []string + if s.fg[1] > 0 { + ss = appen