diff --git a/Readme.md b/Readme.md index 4df19f1..6fc8187 100644 --- a/Readme.md +++ b/Readme.md @@ -33,6 +33,7 @@ vars: AB: {{$bval}}B --- install: + doc: I'm a description what this command do script: - touch test.gomake.txt - echo "Hallo" > test.gomake.txt @@ -113,7 +114,7 @@ There is a [Dockerimage](https://hub.docker.com/r/fasibio/gomake) You can use same stage for different commands ```yaml -buildBin: +buildBin: stage: build color: "{{$root.Colors.purple}}" script: diff --git a/command/commands.go b/command/commands.go index 0f734b7..aa682da 100644 --- a/command/commands.go +++ b/command/commands.go @@ -10,11 +10,12 @@ import ( type MakeStruct map[string]Operation type Operation struct { - Script []string - Image *DockerOperation - On_Failure []string - Stage string - Color string + Script []string `yaml:"script,omitempty"` + Doc string `yaml:"doc,omitempty"` + Image *DockerOperation `yaml:"image,omitempty"` + On_Failure []string `yaml:"on_failure,omitempty"` + Stage string `yaml:"stage,omitempty"` + Color string `yaml:"color,omitempty"` } type DockerOperation struct { diff --git a/go.mod b/go.mod index aba8ddc..03d49f8 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.19 require ( github.com/Masterminds/sprig/v3 v3.2.3 + github.com/andreazorzetto/yh v0.4.0 github.com/pkg/errors v0.9.1 github.com/schollz/closestmatch v2.1.0+incompatible github.com/urfave/cli/v2 v2.23.7 @@ -17,6 +18,7 @@ require ( github.com/google/uuid v1.1.1 // indirect github.com/huandu/xstrings v1.3.3 // indirect github.com/imdario/mergo v0.3.11 // indirect + github.com/logrusorgru/aurora v2.0.3+incompatible // indirect github.com/mitchellh/copystructure v1.0.0 // indirect github.com/mitchellh/reflectwalk v1.0.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect diff --git a/go.sum b/go.sum index 71bbf86..1e46034 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7Y github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA= github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM= +github.com/andreazorzetto/yh v0.4.0 h1:kXQJxhT7v9/JqUNifD+yIBRLKXDWeBgO2/UjxwRQsto= +github.com/andreazorzetto/yh v0.4.0/go.mod h1:c7MhXod3cApIEJDb9VSXA9cZVVaEZbvW+GhMPiVg2tM= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -15,6 +17,8 @@ github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4 github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA= github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= +github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8= +github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY= diff --git a/gomake.yml b/gomake.yml index a1573ad..cc1f7ea 100644 --- a/gomake.yml +++ b/gomake.yml @@ -23,6 +23,7 @@ buildAll: build: stage: b + doc: create a Binary for each GOOS and GOARCH color: "{{$root.Colors.purple}}" script: - mkdir {{.Vars.dist}} diff --git a/interpreter/dryRun.go b/interpreter/dryRun.go index 929bad8..df9647f 100644 --- a/interpreter/dryRun.go +++ b/interpreter/dryRun.go @@ -1,8 +1,10 @@ package interpreter import ( + "bytes" "fmt" + "github.com/andreazorzetto/yh/highlight" "github.com/fasibio/gomake/command" "gopkg.in/yaml.v2" ) @@ -25,6 +27,8 @@ func (i Interpreter) printDryRun(command []StageOperationWrapper, variables map[ if err != nil { return err } - fmt.Println(string(out)) - return nil + reader := bytes.NewReader(out) + r, err := highlight.Highlight(reader) + fmt.Print(r) + return err } diff --git a/interpreter/interpreter.go b/interpreter/interpreter.go index f8846ca..ee9af7e 100644 --- a/interpreter/interpreter.go +++ b/interpreter/interpreter.go @@ -108,7 +108,6 @@ func (r *Interpreter) GetExecuteTemplate(file string, extraVariables map[string] varStr, err := r.getParsedTemplate("gomake_vars", varCommandArr[0], TemplateData{Env: env, Vars: tempVar, Colors: getColorKeyMap()}) - log.Println(string(varStr)) if err != nil { return nil, nil, err } diff --git a/main.go b/main.go index 5e2f74f..879c8d5 100644 --- a/main.go +++ b/main.go @@ -369,7 +369,7 @@ func (r *Runner) List(c *cli.Context) error { } fmt.Println("List of executed Commands (for run):") for k := range list { - fmt.Println(k) + fmt.Printf("%s %s \n", k, list[k].Doc) } fmt.Println("\nList of executed Stages (for srun):") diff --git a/vendor/github.com/andreazorzetto/yh/.gitignore b/vendor/github.com/andreazorzetto/yh/.gitignore new file mode 100644 index 0000000..562d4f6 --- /dev/null +++ b/vendor/github.com/andreazorzetto/yh/.gitignore @@ -0,0 +1,4 @@ +.idea +.DS_Store +*.zip +main \ No newline at end of file diff --git a/vendor/github.com/andreazorzetto/yh/LICENSE b/vendor/github.com/andreazorzetto/yh/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/vendor/github.com/andreazorzetto/yh/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/github.com/andreazorzetto/yh/README.md b/vendor/github.com/andreazorzetto/yh/README.md new file mode 100644 index 0000000..4210bca --- /dev/null +++ b/vendor/github.com/andreazorzetto/yh/README.md @@ -0,0 +1,44 @@ +# yh - YAML Highlighter + +A dummy syntax highlighter that brings colours to YAML output, jq style. + +This project starts with the author's incapacity to give up on colours while playing with kubernetes cli and YAML output (`kubectl get something -o yaml`). + +Unable to find another YAML highlighter where he could simply dump something on, with little to no ~~respect~~ expectations, and inspired by the recent Go training, he decided to write one from scratch. + +![Comparison with or without yh](https://raw.githubusercontent.com/andreazorzetto/yh/master/images/comparison.png) + +# How to use + +As **easy** as you secretly hoped + +`kubectl get pod alpine -o yaml | yh` + +Other commands: + +- `yh help` +- `yh version` + +# Download & installation + +Find the latest releases here: + +- [Releases](https://github.com/andreazorzetto/yh/releases) + +**Linux or MacOS** + +Unzip + +`unzip yh--.zip` + +Move the binary somewhere in your PATH + +`mv yh /usr/local/bin/` + +**Windows** + +Like above but with your mouse + +# Future developments + +The aim of this project is to be a simple highlighting tool, while there are more featured projects our there to do YAML parsing. However I intend to keep maintaining the code and introduce new features and/or explore different routes in the future. Anyone thinking to contribute or make suggestions/requests would be more than welcome. diff --git a/vendor/github.com/andreazorzetto/yh/highlight/highlight.go b/vendor/github.com/andreazorzetto/yh/highlight/highlight.go new file mode 100644 index 0000000..a1ed283 --- /dev/null +++ b/vendor/github.com/andreazorzetto/yh/highlight/highlight.go @@ -0,0 +1,131 @@ +package highlight + +import ( + "bufio" + "fmt" + "io" + "strings" + + . "github.com/logrusorgru/aurora" +) + +func Highlight(r io.Reader) (string, error) { + // Service vars + foundChompingIndicator := false + indentationSpacesBeforeComment := 0 + + // Warm-up the engine + scanner := bufio.NewScanner(r) + + var buf strings.Builder + + // Get the juice + for scanner.Scan() { + if scanner.Text() == "EOF" { + break + } + + // Check for errors during Stdin read + if err := scanner.Err(); err != nil { + return "", err + } + + // Drink the juice + l := yamlLine{raw: scanner.Text()} + + if foundChompingIndicator && (l.indentationSpaces() > indentationSpacesBeforeComment) { + // Found multiline comment or configmap, not treated as YAML at all + buf.WriteString(multiline(l)) + + } else if l.isKeyValue() { + // This is a valid YAML key: value line. Key and value are returned in l + + if l.isComment() { + // This line is a comment + buf.WriteString(comment(l)) + } else if l.valueIsNumberOrIP() { + // The value is a number or an IP address x.x.x.x + buf.WriteString(keyNumberOrIP(l)) + + } else if l.valueIsBoolean() { + // The value is boolean true or false + buf.WriteString(keyBool(l)) + + } else { + // The is a normal key/value line + buf.WriteString(keyValue(l)) + } + + if l.valueContainsChompingIndicator() { + // This line contains a chomping indicator, sign of a possible multiline text coming next + + // Setting flag for next execution + foundChompingIndicator = true + + // Saving current number of indentation spaces + indentationSpacesBeforeComment = l.indentationSpaces() + + } else { + // Resetting multiline flag + foundChompingIndicator = false + } + + } else if !l.isEmptyLine() { + // This is not a YAML key: value line and is not empty + + if l.isUrl() { + // Value is a URL + buf.WriteString(url(l)) + } else if l.isComment() { + // This line is a comment + buf.WriteString(comment(l)) + } else if l.isElementOfList() { + // This line is an element of a list + buf.WriteString(listElement(l)) + } else { + // This line is not valid YAML + buf.WriteString(invalidLine(l)) + } + + foundChompingIndicator = false + + } else if l.isEmptyLine() { + // This is an empty line + fmt.Println(l.raw) + } + + } + + return buf.String(), nil +} + +func keyValue(l yamlLine) string { + return fmt.Sprintf("%v: %v\n", BrightRed(l.key), Yellow(l.value)) +} + +func keyNumberOrIP(l yamlLine) string { + return fmt.Sprintf("%v: %v\n", BrightRed(l.key), Blue(l.value)) +} + +func keyBool(l yamlLine) string { + return fmt.Sprintf("%v: %v\n", BrightRed(l.key), Blue(l.value)) +} + +func comment(l yamlLine) string { + return fmt.Sprintf("%v %v\n", Gray(13, l.key), Gray(13, l.value)) +} + +func listElement(l yamlLine) string { + return fmt.Sprintf("%v\n", Yellow(l.raw)) +} + +func invalidLine(l yamlLine) string { + return fmt.Sprintf("%v\n", Black(l.raw).BgBrightRed()) +} + +func multiline(l yamlLine) string { + return fmt.Sprintf("%v\n", Gray(20-1, l.raw)) +} +func url(l yamlLine) string { + return fmt.Sprintf("%v\n", Yellow(l.raw)) +} diff --git a/vendor/github.com/andreazorzetto/yh/highlight/lines.go b/vendor/github.com/andreazorzetto/yh/highlight/lines.go new file mode 100644 index 0000000..c3a7af5 --- /dev/null +++ b/vendor/github.com/andreazorzetto/yh/highlight/lines.go @@ -0,0 +1,125 @@ +package highlight + +import ( + "strconv" + "strings" +) + +type yamlLine struct { + raw string + key string + value string +} + +func (l *yamlLine) isKeyValue() bool { + if strings.Contains(l.raw, "://") { + // It's a URL not k/v + + return false + + } else if strings.Contains(l.raw, ":") { + // Contains the separator but it might not be a k/v + + // Split the string + t := strings.Split(l.raw, ":") + + if strings.HasPrefix(t[1], " ") || len(t[1]) == 0 { + /* Checking if it's either: + - a proper k/v entry with a space after: + - just key:\n + */ + + l.key = t[0] + l.value = strings.TrimSpace(strings.Join(t[1:len(t)], ":")) + return true + + } else if len(t) > 2 && (strings.HasPrefix(t[len(t)-1], " ") || len(t[len(t)-1]) == 0) { + // Multiple : found, checking last one + /* + k:{"type":"Available"}: + .: {} + f:lastTransitionTime: {} + f:lastUpdateTime: {} + */ + + l.key = strings.Join(t[0:len(t)-1], ":") + l.value = strings.TrimSpace(t[len(t)-1]) + return true + } + } + return false + +} + +func (l yamlLine) isComment() bool { + if string(strings.TrimSpace(l.raw)[0]) == "#" { + // Line is a comment + return true + } + return false +} + +func (l yamlLine) valueIsBoolean() bool { + if (strings.ToLower(l.value) == "true") || (strings.ToLower(l.value) == "false") { + // Line is a boolean value + return true + } + return false +} + +func (l yamlLine) valueIsNumberOrIP() bool { + _, err := strconv.Atoi(strings.ReplaceAll(l.value, ".", "")) + if err == nil { + // Line is a number or IP + return true + } + return false +} + +func (l yamlLine) isEmptyLine() bool { + if len(strings.TrimSpace(l.raw)) > 0 { + return false + } + return true +} + +func (l yamlLine) isElementOfList() bool { + if string(strings.TrimSpace(l.raw)[0]) == "-" { + return true + } + return false +} + +func (l yamlLine) isUrl() bool { + if strings.Contains(l.raw, "://") { + return true + } + return false +} + +func (l yamlLine) indentationSpaces() int { + // This function checks how many indentation spaces where used + // before chomping indicator to catch a possible multiline comment or config + count := 0 + + for _, v := range l.raw { + if string(v) == " " { + count += 1 + } else { + break + } + } + return count +} + +func (l yamlLine) valueContainsChompingIndicator() bool { + // this function checks for multline chomping indicator + indicators := []string{">", ">-", ">+", "|", "|-", "|+"} + + for _, in := range indicators { + if strings.Contains(l.value, in) { + return true + } + } + return false +} diff --git a/vendor/github.com/andreazorzetto/yh/main.go b/vendor/github.com/andreazorzetto/yh/main.go new file mode 100644 index 0000000..bf50ac9 --- /dev/null +++ b/vendor/github.com/andreazorzetto/yh/main.go @@ -0,0 +1,53 @@ +package main + +import ( + "fmt" + "log" + "os" + + "github.com/andreazorzetto/yh/highlight" +) + +const version = "0.4.0" + +func main() { + log.SetFlags(0) // disable timestamp of log package + + // Checking the args, someone out there might need help + checkArgs(os.Args) + + h, err := highlight.Highlight(os.Stdin) + if err != nil { + log.Fatalln(err) + } + + fmt.Print(h) +} + +// Check args if passed +// Show help +func checkArgs(a []string) { + if len(a) >= 2 { + // Someone's looking for... + + if a[1] == "version" { + // version + fmt.Println(version) + os.Exit(0) + + } else if a[1] == "help" { + // help + fmt.Println("You don't really need to read this! \nJust pipe me some YAML. I don't bite") + fmt.Println("\nExample:") + fmt.Println("\tkubectl get myNastyPod -o yaml | yh") + fmt.Println("\nCommands:") + fmt.Println("\thelp: get this helpful help") + fmt.Println("\tversion: get the version") + os.Exit(0) + } else { + // trolling + fmt.Println("Not really sure of what you want! Maybe try help or version.") + os.Exit(0) + } + } +} diff --git a/vendor/github.com/logrusorgru/aurora/.gitignore b/vendor/github.com/logrusorgru/aurora/.gitignore new file mode 100644 index 0000000..dbcb7cc --- /dev/null +++ b/vendor/github.com/logrusorgru/aurora/.gitignore @@ -0,0 +1,34 @@ +# Compiled Object files, Static and Dynamic libs (Shared Objects) +*.o +*.a +*.so + +# Folders +_obj +_test + +# Architecture specific extensions/prefixes +*.[568vq] +[568vq].out + +*.cgo1.go +*.cgo2.c +_cgo_defun.c +_cgo_gotypes.go +_cgo_export.* + +_testmain.go + +*.exe +*.test +*.prof +*.out + +# coverage + +cover.html + +# benchcmp + +*.cmp + diff --git a/vendor/github.com/logrusorgru/aurora/.travis.yml b/vendor/github.com/logrusorgru/aurora/.travis.yml new file mode 100644 index 0000000..570e361 --- /dev/null +++ b/vendor/github.com/logrusorgru/aurora/.travis.yml @@ -0,0 +1,9 @@ +language: go +go: + - tip +before_install: + - go get github.com/axw/gocov/gocov + - go get github.com/mattn/goveralls + - go get golang.org/x/tools/cmd/cover +script: + - $HOME/gopath/bin/goveralls -service=travis-ci diff --git a/vendor/github.com/logrusorgru/aurora/AUTHORS.md b/vendor/github.com/logrusorgru/aurora/AUTHORS.md new file mode 100644 index 0000000..0ee9e3e --- /dev/null +++ b/vendor/github.com/logrusorgru/aurora/AUTHORS.md @@ -0,0 +1,8 @@ +AUTHORS +======= + +- Konstantin Ivanov @logrusorgru +- Mattias Eriksson @snaggen +- Ousmane Traore @otraore +- Simon Legner @simon04 +- Sevenate @sevenate diff --git a/vendor/github.com/logrusorgru/aurora/CHANGELOG.md b/vendor/github.com/logrusorgru/aurora/CHANGELOG.md new file mode 100644 index 0000000..ad0a202 --- /dev/null +++ b/vendor/github.com/logrusorgru/aurora/CHANGELOG.md @@ -0,0 +1,59 @@ +Changes +======= + +--- +16:05:02 +Thursday, July 2, 2020 + +Change license from the WTFPL to the Unlicense due to pkg.go.dev restriction. + +--- +15:39:40 +Wednesday, April 17, 2019 + +- Bright background and foreground colors +- 8-bit indexed colors `Index`, `BgIndex` +- 24 grayscale colors `Gray`, `BgGray` +- `Yellow` and `BgYellow` methods, mark Brow and BgBrown as deprecated + Following specifications, correct name of the colors are yellow, but + by historical reason they are called brown. Both, the `Yellow` and the + `Brown` methods (including `Bg+`) represents the same colors. The Brown + are leaved for backward compatibility until Go modules production release. +- Additional formats + + `Faint` that is opposite to the `Bold` + + `DoublyUnderline` + + `Fraktur` + + `Italic` + + `Underline` + + `SlowBlink` with `Blink` alias + + `RapidBlink` + + `Reverse` that is alias for the `Inverse` + + `Conceal` with `Hidden` alias + + `CrossedOut` with `StrikeThrough` alias + + `Framed` + + `Encircled` + + `Overlined` +- Add AUTHORS.md file and change all copyright notices. +- `Reset` method to create clear value. `Reset` method that replaces + `Bleach` method. The `Bleach` method was marked as deprecated. + +--- + +14:25:49 +Friday, August 18, 2017 + +- LICENSE.md changed to LICENSE +- fix email in README.md +- add "no warranty" to README.md +- set proper copyright date + +--- + +16:59:28 +Tuesday, November 8, 2016 + +- Rid out off sync.Pool +- Little optimizations (very little) +- Improved benchmarks + +--- diff --git a/vendor/github.com/logrusorgru/aurora/LICENSE b/vendor/github.com/logrusorgru/aurora/LICENSE new file mode 100644 index 0000000..68a49da --- /dev/null +++ b/vendor/github.com/logrusorgru/aurora/LICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +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 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. + +For more information, please refer to diff --git a/vendor/github.com/logrusorgru/aurora/README.md b/vendor/github.com/logrusorgru/aurora/README.md new file mode 100644 index 0000000..e0afce1 --- /dev/null +++ b/vendor/github.com/logrusorgru/aurora/README.md @@ -0,0 +1,314 @@ +Aurora +====== + +[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white)](https://pkg.go.dev/github.com/logrusorgru/aurora?tab=doc) +[![Unlicense](https://img.shields.io/badge/license-unlicense-blue.svg)](http://unlicense.org/) +[![Build Status](https://travis-ci.org/logrusorgru/aurora.svg)](https://travis-ci.org/logrusorgru/aurora) +[![Coverage Status](https://coveralls.io/repos/logrusorgru/aurora/badge.svg?branch=master)](https://coveralls.io/r/logrusorgru/aurora?branch=master) +[![GoReportCard](https://goreportcard.com/badge/logrusorgru/aurora)](https://goreportcard.com/report/logrusorgru/aurora) +[![Gitter](https://img.shields.io/badge/chat-on_gitter-46bc99.svg?logo=data:image%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMTQiIHdpZHRoPSIxNCI%2BPGcgZmlsbD0iI2ZmZiI%2BPHJlY3QgeD0iMCIgeT0iMyIgd2lkdGg9IjEiIGhlaWdodD0iNSIvPjxyZWN0IHg9IjIiIHk9IjQiIHdpZHRoPSIxIiBoZWlnaHQ9IjciLz48cmVjdCB4PSI0IiB5PSI0IiB3aWR0aD0iMSIgaGVpZ2h0PSI3Ii8%2BPHJlY3QgeD0iNiIgeT0iNCIgd2lkdGg9IjEiIGhlaWdodD0iNCIvPjwvZz48L3N2Zz4%3D&logoWidth=10)](https://gitter.im/logrusorgru/aurora) + +Ultimate ANSI colors for Golang. The package supports Printf/Sprintf etc. + + +![aurora logo](https://github.com/logrusorgru/aurora/blob/master/gopher_aurora.png) + +# TOC + +- [Installation](#installation) +- [Usage](#usage) + + [Simple](#simple) + + [Printf](#printf) + + [aurora.Sprintf](#aurorasprintf) + + [Enable/Disable colors](#enabledisable-colors) +- [Chains](#chains) +- [Colorize](#colorize) +- [Grayscale](#grayscale) +- [8-bit colors](#8-bit-colors) +- [Supported Colors & Formats](#supported-colors--formats) + + [All colors](#all-colors) + + [Standard and bright colors](#standard-and-bright-colors) + + [Formats are likely supported](#formats-are-likely-supported) + + [Formats are likely unsupported](#formats-are-likely-unsupported) +- [Limitations](#limitations) + + [Windows](#windows) + + [TTY](#tty) +- [Licensing](#licensing) + +# Installation + +Get +``` +go get -u github.com/logrusorgru/aurora +``` +Test +``` +go test -cover github.com/logrusorgru/aurora +``` + +# Usage + +### Simple + +```go +package main + +import ( + "fmt" + + . "github.com/logrusorgru/aurora" +) + +func main() { + fmt.Println("Hello,", Magenta("Aurora")) + fmt.Println(Bold(Cyan("Cya!"))) +} + +``` + +![simple png](https://github.com/logrusorgru/aurora/blob/master/simple.png) + +### Printf + +```go +package main + +import ( + "fmt" + + . "github.com/logrusorgru/aurora" +) + +func main() { + fmt.Printf("Got it %d times\n", Green(1240)) + fmt.Printf("PI is %+1.2e\n", Cyan(3.14)) +} + +``` + +![printf png](https://github.com/logrusorgru/aurora/blob/master/printf.png) + +### aurora.Sprintf + +```go +package main + +import ( + "fmt" + + . "github.com/logrusorgru/aurora" +) + +func main() { + fmt.Println(Sprintf(Magenta("Got it %d times"), Green(1240))) +} + +``` + +![sprintf png](https://github.com/logrusorgru/aurora/blob/master/sprintf.png) + +### Enable/Disable colors + +```go +package main + +import ( + "fmt" + "flag" + + "github.com/logrusorgru/aurora" +) + +// colorizer +var au aurora.Aurora + +var colors = flag.Bool("colors", false, "enable or disable colors") + +func init() { + flag.Parse() + au = aurora.NewAurora(*colors) +} + +func main() { + // use colorizer + fmt.Println(au.Green("Hello")) +} + +``` +Without flags: +![disable png](https://github.com/logrusorgru/aurora/blob/master/disable.png) + +With `-colors` flag: +![enable png](https://github.com/logrusorgru/aurora/blob/master/enable.png) + +# Chains + +The following samples are equal + +```go +x := BgMagenta(Bold(Red("x"))) +``` + +```go +x := Red("x").Bold().BgMagenta() +``` + +The second is more readable + +# Colorize + +There is `Colorize` function that allows to choose some colors and +format from a side + +```go + +func getColors() Color { + // some stuff that returns appropriate colors and format +} + +// [...] + +func main() { + fmt.Println(Colorize("Greeting", getColors())) +} + +``` +Less complicated example + +```go +x := Colorize("Greeting", GreenFg|GrayBg|BoldFm) +``` + +Unlike other color functions and methods (such as Red/BgBlue etc) +a `Colorize` clears previous colors + +```go +x := Red("x").Colorize(BgGreen) // will be with green background only +``` + +# Grayscale + +```go +fmt.Println(" ", + Gray(1-1, " 00-23 ").BgGray(24-1), + Gray(4-1, " 03-19 ").BgGray(20-1), + Gray(8-1, " 07-15 ").BgGray(16-1), + Gray(12-1, " 11-11 ").BgGray(12-1), + Gray(16-1, " 15-07 ").BgGray(8-1), + Gray(20-1, " 19-03 ").BgGray(4-1), + Gray(24-1, " 23-00 ").BgGray(1-1), +) +``` + +![grayscale png](https://github.com/logrusorgru/aurora/blob/master/aurora_grayscale.png) + +# 8-bit colors + +Methods `Index` and `BgIndex` implements 8-bit colors. + +| Index/BgIndex | Meaning | Foreground | Background | +| -------------- | --------------- | ---------- | ---------- | +| 0- 7 | standard colors | 30- 37 | 40- 47 | +| 8- 15 | bright colors | 90- 97 | 100-107 | +| 16-231 | 216 colors | 38;5;n | 48;5;n | +| 232-255 | 24 grayscale | 38;5;n | 48;5;n | + + +# Supported colors & formats + +- formats + + bold (1) + + faint (2) + + doubly-underline (21) + + fraktur (20) + + italic (3) + + underline (4) + + slow blink (5) + + rapid blink (6) + + reverse video (7) + + conceal (8) + + crossed out (9) + + framed (51) + + encircled (52) + + overlined (53) +- background and foreground colors, including bright + + black + + red + + green + + yellow (brown) + + blue + + magenta + + cyan + + white + + 24 grayscale colors + + 216 8-bit colors + +### All colors + +![linux png](https://github.com/logrusorgru/aurora/blob/master/aurora_colors_black.png) +![white png](https://github.com/logrusorgru/aurora/blob/master/aurora_colors_white.png) + +### Standard and bright colors + +![linux black standard png](https://github.com/logrusorgru/aurora/blob/master/aurora_black_standard.png) +![linux white standard png](https://github.com/logrusorgru/aurora/blob/master/aurora_white_standard.png) + +### Formats are likely supported + +![formats supported gif](https://github.com/logrusorgru/aurora/blob/master/aurora_formats.gif) + +### Formats are likely unsupported + +![formats rarely supported png](https://github.com/logrusorgru/aurora/blob/master/aurora_rarely_supported.png) + +# Limitations + +There is no way to represent `%T` and `%p` with colors using +a standard approach + +```go +package main + +import ( + "fmt" + + . "github.com/logrusorgru/aurora" +) + +func main() { + r := Red("red") + var i int + fmt.Printf("%T %p\n", r, Green(&i)) +} +``` + +Output will be without colors + +``` +aurora.value %!p(aurora.value={0xc42000a310 768 0}) +``` + +The obvious workaround is `Red(fmt.Sprintf("%T", some))` + +### Windows + +The Aurora provides ANSI colors only, so there is no support for Windows. That said, there are workarounds available. +Check out these comments to learn more: + +- [Using go-colorable](https://github.com/logrusorgru/aurora/issues/2#issuecomment-299014211). +- [Using registry for Windows 10](https://github.com/logrusorgru/aurora/issues/10#issue-476361247). + +### TTY + +The Aurora has no internal TTY detectors by design. Take a look + [this comment](https://github.com/logrusorgru/aurora/issues/2#issuecomment-299030108) if you want turn +on colors for a terminal only, and turn them off for a file. + +### Licensing + +Copyright © 2016-2020 The Aurora Authors. This work is free. +It comes without any warranty, to the extent permitted by applicable +law. You can redistribute it and/or modify it under the terms of the +the Unlicense. See the LICENSE file for more details. + + diff --git a/vendor/github.com/logrusorgru/aurora/aurora.go b/vendor/github.com/logrusorgru/aurora/aurora.go new file mode 100644 index 0000000..3b30230 --- /dev/null +++ b/vendor/github.com/logrusorgru/aurora/aurora.go @@ -0,0 +1,725 @@ +// +// Copyright (c) 2016-2020 The Aurora Authors. All rights reserved. +// This program is free software. It comes without any warranty, +// to the extent permitted by applicable law. You can redistribute +// it and/or modify it under the terms of the Unlicense. See LICENSE +// file for more details or see below. +// + +// +// This is free and unencumbered software released into the public domain. +// +// Anyone is free to copy, modify, publish, use, compile, sell, or +// distribute this software, either in source code form or as a compiled +// binary, for any purpose, commercial or non-commercial, and by any +// means. +// +// In jurisdictions that recognize copyright laws, the author or authors +// of this software dedicate any and all copyright interest in the +// software to the public domain. We make this dedication for the benefit +// of the public at large and to the detriment of our heirs and +// successors. We intend this dedication to be an overt act of +// relinquishment in perpetuity of all present and future rights to this +// software under copyright law. +// +// 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 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. +// +// For more information, please refer to +// + +// Package aurora implements ANSI-colors +package aurora + +import ( + "fmt" +) + +// An Aurora implements colorizer interface. +// It also can be a non-colorizer +type Aurora interface { + + // Reset wraps given argument returning Value + // without formats and colors. + Reset(arg interface{}) Value + + // + // Formats + // + // + // Bold or increased intensity (1). + Bold(arg interface{}) Value + // Faint, decreased intensity (2). + Faint(arg interface{}) Value + // + // DoublyUnderline or Bold off, double-underline + // per ECMA-48 (21). + DoublyUnderline(arg interface{}) Value + // Fraktur, rarely supported (20). + Fraktur(arg interface{}) Value + // + // Italic, not widely supported, sometimes + // treated as inverse (3). + Italic(arg interface{}) Value + // Underline (4). + Underline(arg interface{}) Value + // + // SlowBlink, blinking less than 150 + // per minute (5). + SlowBlink(arg interface{}) Value + // RapidBlink, blinking 150+ per minute, + // not widely supported (6). + RapidBlink(arg interface{}) Value + // Blink is alias for the SlowBlink. + Blink(arg interface{}) Value + // + // Reverse video, swap foreground and + // background colors (7). + Reverse(arg interface{}) Value + // Inverse is alias for the Reverse + Inverse(arg interface{}) Value + // + // Conceal, hidden, not widely supported (8). + Conceal(arg interface{}) Value + // Hidden is alias for the Conceal + Hidden(arg interface{}) Value + // + // CrossedOut, characters legible, but + // marked for deletion (9). + CrossedOut(arg interface{}) Value + // StrikeThrough is alias for the CrossedOut. + StrikeThrough(arg interface{}) Value + // + // Framed (51). + Framed(arg interface{}) Value + // Encircled (52). + Encircled(arg interface{}) Value + // + // Overlined (53). + Overlined(arg interface{}) Value + + // + // Foreground colors + // + // + // Black foreground color (30) + Black(arg interface{}) Value + // Red foreground color (31) + Red(arg interface{}) Value + // Green foreground color (32) + Green(arg interface{}) Value + // Yellow foreground color (33) + Yellow(arg interface{}) Value + // Brown foreground color (33) + // + // Deprecated: use Yellow instead, following specification + Brown(arg interface{}) Value + // Blue foreground color (34) + Blue(arg interface{}) Value + // Magenta foreground color (35) + Magenta(arg interface{}) Value + // Cyan foreground color (36) + Cyan(arg interface{}) Value + // White foreground color (37) + White(arg interface{}) Value + // + // Bright foreground colors + // + // BrightBlack foreground color (90) + BrightBlack(arg interface{}) Value + // BrightRed foreground color (91) + BrightRed(arg interface{}) Value + // BrightGreen foreground color (92) + BrightGreen(arg interface{}) Value + // BrightYellow foreground color (93) + BrightYellow(arg interface{}) Value + // BrightBlue foreground color (94) + BrightBlue(arg interface{}) Value + // BrightMagenta foreground color (95) + BrightMagenta(arg interface{}) Value + // BrightCyan foreground color (96) + BrightCyan(arg interface{}) Value + // BrightWhite foreground color (97) + BrightWhite(arg interface{}) Value + // + // Other + // + // Index of pre-defined 8-bit foreground color + // from 0 to 255 (38;5;n). + // + // 0- 7: standard colors (as in ESC [ 30–37 m) + // 8- 15: high intensity colors (as in ESC [ 90–97 m) + // 16-231: 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5) + // 232-255: grayscale from black to white in 24 steps + // + Index(n uint8, arg interface{}) Value + // Gray from 0 to 23. + Gray(n uint8, arg interface{}) Value + + // + // Background colors + // + // + // BgBlack background color (40) + BgBlack(arg interface{}) Value + // BgRed background color (41) + BgRed(arg interface{}) Value + // BgGreen background color (42) + BgGreen(arg interface{}) Value + // BgYellow background color (43) + BgYellow(arg interface{}) Value + // BgBrown background color (43) + // + // Deprecated: use BgYellow instead, following specification + BgBrown(arg interface{}) Value + // BgBlue background color (44) + BgBlue(arg interface{}) Value + // BgMagenta background color (45) + BgMagenta(arg interface{}) Value + // BgCyan background color (46) + BgCyan(arg interface{}) Value + // BgWhite background color (47) + BgWhite(arg interface{}) Value + // + // Bright background colors + // + // BgBrightBlack background color (100) + BgBrightBlack(arg interface{}) Value + // BgBrightRed background color (101) + BgBrightRed(arg interface{}) Value + // BgBrightGreen background color (102) + BgBrightGreen(arg interface{}) Value + // BgBrightYellow background color (103) + BgBrightYellow(arg interface{}) Value + // BgBrightBlue background color (104) + BgBrightBlue(arg interface{}) Value + // BgBrightMagenta background color (105) + BgBrightMagenta(arg interface{}) Value + // BgBrightCyan background color (106) + BgBrightCyan(arg interface{}) Value + // BgBrightWhite background color (107) + BgBrightWhite(arg interface{}) Value + // + // Other + // + // BgIndex of 8-bit pre-defined background color + // from 0 to 255 (48;5;n). + // + // 0- 7: standard colors (as in ESC [ 40–47 m) + // 8- 15: high intensity colors (as in ESC [100–107 m) + // 16-231: 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5) + // 232-255: grayscale from black to white in 24 steps + // + BgIndex(n uint8, arg interface{}) Value + // BgGray from 0 to 23. + BgGray(n uint8, arg interface{}) Value + + // + // Special + // + // Colorize removes existing colors and + // formats of the argument and applies given. + Colorize(arg interface{}, color Color) Value + + // + // Support methods + // + // Sprintf allows to use colored format. + Sprintf(format interface{}, args ...interface{}) string +} + +// NewAurora returns a new Aurora interface that +// will support or not support colors depending +// the enableColors argument +func NewAurora(enableColors bool) Aurora { + if enableColors { + return aurora{} + } + return auroraClear{} +} + +// no colors + +type auroraClear struct{} + +func (auroraClear) Reset(arg interface{}) Value { return valueClear{arg} } + +func (auroraClear) Bold(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) Faint(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) DoublyUnderline(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) Fraktur(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) Italic(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) Underline(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) SlowBlink(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) RapidBlink(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) Blink(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) Reverse(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) Inverse(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) Conceal(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) Hidden(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) CrossedOut(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) StrikeThrough(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) Framed(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) Encircled(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) Overlined(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) Black(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) Red(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) Green(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) Yellow(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) Brown(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) Blue(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) Magenta(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) Cyan(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) White(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BrightBlack(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BrightRed(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BrightGreen(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BrightYellow(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BrightBlue(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BrightMagenta(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BrightCyan(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BrightWhite(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) Index(_ uint8, arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) Gray(_ uint8, arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BgBlack(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BgRed(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BgGreen(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BgYellow(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BgBrown(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BgBlue(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BgMagenta(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BgCyan(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BgWhite(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BgBrightBlack(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BgBrightRed(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BgBrightGreen(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BgBrightYellow(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BgBrightBlue(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BgBrightMagenta(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BgBrightCyan(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BgBrightWhite(arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BgIndex(_ uint8, arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) BgGray(_ uint8, arg interface{}) Value { + return valueClear{arg} +} + +func (auroraClear) Colorize(arg interface{}, _ Color) Value { + return valueClear{arg} +} + +func (auroraClear) Sprintf(format interface{}, args ...interface{}) string { + if str, ok := format.(string); ok { + return fmt.Sprintf(str, args...) + } + return fmt.Sprintf(fmt.Sprint(format), args...) +} + +// colorized + +type aurora struct{} + +func (aurora) Reset(arg interface{}) Value { + return Reset(arg) +} + +func (aurora) Bold(arg interface{}) Value { + return Bold(arg) +} + +func (aurora) Faint(arg interface{}) Value { + return Faint(arg) +} + +func (aurora) DoublyUnderline(arg interface{}) Value { + return DoublyUnderline(arg) +} + +func (aurora) Fraktur(arg interface{}) Value { + return Fraktur(arg) +} + +func (aurora) Italic(arg interface{}) Value { + return Italic(arg) +} + +func (aurora) Underline(arg interface{}) Value { + return Underline(arg) +} + +func (aurora) SlowBlink(arg interface{}) Value { + return SlowBlink(arg) +} + +func (aurora) RapidBlink(arg interface{}) Value { + return RapidBlink(arg) +} + +func (aurora) Blink(arg interface{}) Value { + return Blink(arg) +} + +func (aurora) Reverse(arg interface{}) Value { + return Reverse(arg) +} + +func (aurora) Inverse(arg interface{}) Value { + return Inverse(arg) +} + +func (aurora) Conceal(arg interface{}) Value { + return Conceal(arg) +} + +func (aurora) Hidden(arg interface{}) Value { + return Hidden(arg) +} + +func (aurora) CrossedOut(arg interface{}) Value { + return CrossedOut(arg) +} + +func (aurora) StrikeThrough(arg interface{}) Value { + return StrikeThrough(arg) +} + +func (aurora) Framed(arg interface{}) Value { + return Framed(arg) +} + +func (aurora) Encircled(arg interface{}) Value { + return Encircled(arg) +} + +func (aurora) Overlined(arg interface{}) Value { + return Overlined(arg) +} + +func (aurora) Black(arg interface{}) Value { + return Black(arg) +} + +func (aurora) Red(arg interface{}) Value { + return Red(arg) +} + +func (aurora) Green(arg interface{}) Value { + return Green(arg) +} + +func (aurora) Yellow(arg interface{}) Value { + return Yellow(arg) +} + +func (aurora) Brown(arg interface{}) Value { + return Brown(arg) +} + +func (aurora) Blue(arg interface{}) Value { + return Blue(arg) +} + +func (aurora) Magenta(arg interface{}) Value { + return Magenta(arg) +} + +func (aurora) Cyan(arg interface{}) Value { + return Cyan(arg) +} + +func (aurora) White(arg interface{}) Value { + return White(arg) +} + +func (aurora) BrightBlack(arg interface{}) Value { + return BrightBlack(arg) +} + +func (aurora) BrightRed(arg interface{}) Value { + return BrightRed(arg) +} + +func (aurora) BrightGreen(arg interface{}) Value { + return BrightGreen(arg) +} + +func (aurora) BrightYellow(arg interface{}) Value { + return BrightYellow(arg) +} + +func (aurora) BrightBlue(arg interface{}) Value { + return BrightBlue(arg) +} + +func (aurora) BrightMagenta(arg interface{}) Value { + return BrightMagenta(arg) +} + +func (aurora) BrightCyan(arg interface{}) Value { + return BrightCyan(arg) +} + +func (aurora) BrightWhite(arg interface{}) Value { + return BrightWhite(arg) +} + +func (aurora) Index(index uint8, arg interface{}) Value { + return Index(index, arg) +} + +func (aurora) Gray(n uint8, arg interface{}) Value { + return Gray(n, arg) +} + +func (aurora) BgBlack(arg interface{}) Value { + return BgBlack(arg) +} + +func (aurora) BgRed(arg interface{}) Value { + return BgRed(arg) +} + +func (aurora) BgGreen(arg interface{}) Value { + return BgGreen(arg) +} + +func (aurora) BgYellow(arg interface{}) Value { + return BgYellow(arg) +} + +func (aurora) BgBrown(arg interface{}) Value { + return BgBrown(arg) +} + +func (aurora) BgBlue(arg interface{}) Value { + return BgBlue(arg) +} + +func (aurora) BgMagenta(arg interface{}) Value { + return BgMagenta(arg) +} + +func (aurora) BgCyan(arg interface{}) Value { + return BgCyan(arg) +} + +func (aurora) BgWhite(arg interface{}) Value { + return BgWhite(arg) +} + +func (aurora) BgBrightBlack(arg interface{}) Value { + return BgBrightBlack(arg) +} + +func (aurora) BgBrightRed(arg interface{}) Value { + return BgBrightRed(arg) +} + +func (aurora) BgBrightGreen(arg interface{}) Value { + return BgBrightGreen(arg) +} + +func (aurora) BgBrightYellow(arg interface{}) Value { + return BgBrightYellow(arg) +} + +func (aurora) BgBrightBlue(arg interface{}) Value { + return BgBrightBlue(arg) +} + +func (aurora) BgBrightMagenta(arg interface{}) Value { + return BgBrightMagenta(arg) +} + +func (aurora) BgBrightCyan(arg interface{}) Value { + return BgBrightCyan(arg) +} + +func (aurora) BgBrightWhite(arg interface{}) Value { + return BgBrightWhite(arg) +} + +func (aurora) BgIndex(n uint8, arg interface{}) Value { + return BgIndex(n, arg) +} + +func (aurora) BgGray(n uint8, arg interface{}) Value { + return BgGray(n, arg) +} + +func (aurora) Colorize(arg interface{}, color Color) Value { + return Colorize(arg, color) +} + +func (aurora) Sprintf(format interface{}, args ...interface{}) string { + return Sprintf(format, args...) +} diff --git a/vendor/github.com/logrusorgru/aurora/aurora_black_standard.png b/vendor/github.com/logrusorgru/aurora/aurora_black_standard.png new file mode 100644 index 0000000..83658d6 Binary files /dev/null and b/vendor/github.com/logrusorgru/aurora/aurora_black_standard.png differ diff --git a/vendor/github.com/logrusorgru/aurora/aurora_colors_black.png b/vendor/github.com/logrusorgru/aurora/aurora_colors_black.png new file mode 100644 index 0000000..61b1602 Binary files /dev/null and b/vendor/github.com/logrusorgru/aurora/aurora_colors_black.png differ diff --git a/vendor/github.com/logrusorgru/aurora/aurora_colors_white.png b/vendor/github.com/logrusorgru/aurora/aurora_colors_white.png new file mode 100644 index 0000000..ec42b07 Binary files /dev/null and b/vendor/github.com/logrusorgru/aurora/aurora_colors_white.png differ diff --git a/vendor/github.com/logrusorgru/aurora/aurora_formats.gif b/vendor/github.com/logrusorgru/aurora/aurora_formats.gif new file mode 100644 index 0000000..670dd1c Binary files /dev/null and b/vendor/github.com/logrusorgru/aurora/aurora_formats.gif differ diff --git a/vendor/github.com/logrusorgru/aurora/aurora_grayscale.png b/vendor/github.com/logrusorgru/aurora/aurora_grayscale.png new file mode 100644 index 0000000..40ecac6 Binary files /dev/null and b/vendor/github.com/logrusorgru/aurora/aurora_grayscale.png differ diff --git a/vendor/github.com/logrusorgru/aurora/aurora_rarely_supported.png b/vendor/github.com/logrusorgru/aurora/aurora_rarely_supported.png new file mode 100644 index 0000000..51b7b6d Binary files /dev/null and b/vendor/github.com/logrusorgru/aurora/aurora_rarely_supported.png differ diff --git a/vendor/github.com/logrusorgru/aurora/aurora_white_standard.png b/vendor/github.com/logrusorgru/aurora/aurora_white_standard.png new file mode 100644 index 0000000..1fe99d7 Binary files /dev/null and b/vendor/github.com/logrusorgru/aurora/aurora_white_standard.png differ diff --git a/vendor/github.com/logrusorgru/aurora/color.go b/vendor/github.com/logrusorgru/aurora/color.go new file mode 100644 index 0000000..486fb67 --- /dev/null +++ b/vendor/github.com/logrusorgru/aurora/color.go @@ -0,0 +1,398 @@ +// +// Copyright (c) 2016-2020 The Aurora Authors. All rights reserved. +// This program is free software. It comes without any warranty, +// to the extent permitted by applicable law. You can redistribute +// it and/or modify it under the terms of the Unlicense. See LICENSE +// file for more details or see below. +// + +// +// This is free and unencumbered software released into the public domain. +// +// Anyone is free to copy, modify, publish, use, compile, sell, or +// distribute this software, either in source code form or as a compiled +// binary, for any purpose, commercial or non-commercial, and by any +// means. +// +// In jurisdictions that recognize copyright laws, the author or authors +// of this software dedicate any and all copyright interest in the +// software to the public domain. We make this dedication for the benefit +// of the public at large and to the detriment of our heirs and +// successors. We intend this dedication to be an overt act of +// relinquishment in perpetuity of all present and future rights to this +// software under copyright law. +// +// 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 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. +// +// For more information, please refer to +// + +package aurora + +// A Color type is a color. It can contain +// one background color, one foreground color +// and a format, including ideogram related +// formats. +type Color uint + +/* + + Developer note. + + The int type is architecture depended and can be + represented as int32 or int64. + + Thus, we can use 32-bits only to be fast and + cross-platform. + + All supported formats requires 14 bits. It is + first 14 bits. + + A foreground color requires 8 bit + 1 bit (presence flag). + And the same for background color. + + The Color representations + + [ bg 8 bit ] [fg 8 bit ] [ fg/bg 2 bits ] [ fm 14 bits ] + + https://play.golang.org/p/fq2zcNstFoF + +*/ + +// Special formats +const ( + BoldFm Color = 1 << iota // 1 + FaintFm // 2 + ItalicFm // 3 + UnderlineFm // 4 + SlowBlinkFm // 5 + RapidBlinkFm // 6 + ReverseFm // 7 + ConcealFm // 8 + CrossedOutFm // 9 + + FrakturFm // 20 + DoublyUnderlineFm // 21 or bold off for some systems + + FramedFm // 51 + EncircledFm // 52 + OverlinedFm // 53 + + InverseFm = ReverseFm // alias to ReverseFm + BlinkFm = SlowBlinkFm // alias to SlowBlinkFm + HiddenFm = ConcealFm // alias to ConcealFm + StrikeThroughFm = CrossedOutFm // alias to CrossedOutFm + + maskFm = BoldFm | FaintFm | + ItalicFm | UnderlineFm | + SlowBlinkFm | RapidBlinkFm | + ReverseFm | + ConcealFm | CrossedOutFm | + + FrakturFm | DoublyUnderlineFm | + + FramedFm | EncircledFm | OverlinedFm + + flagFg Color = 1 << 14 // presence flag (14th bit) + flagBg Color = 1 << 15 // presence flag (15th bit) + + shiftFg = 16 // shift for foreground (starting from 16th bit) + shiftBg = 24 // shift for background (starting from 24th bit) +) + +// Foreground colors and related formats +const ( + + // 8 bits + + // [ 0; 7] - 30-37 + // [ 8; 15] - 90-97 + // [ 16; 231] - RGB + // [232; 255] - grayscale + + BlackFg Color = (iota << shiftFg) | flagFg // 30, 90 + RedFg // 31, 91 + GreenFg // 32, 92 + YellowFg // 33, 93 + BlueFg // 34, 94 + MagentaFg // 35, 95 + CyanFg // 36, 96 + WhiteFg // 37, 97 + + BrightFg Color = ((1 << 3) << shiftFg) | flagFg // -> 90 + + // the BrightFg itself doesn't represent + // a color, thus it has not flagFg + + // 5 bits + + // BrownFg represents brown foreground color. + // + // Deprecated: use YellowFg instead, following specifications + BrownFg = YellowFg + + // + maskFg = (0xff << shiftFg) | flagFg +) + +// Background colors and related formats +const ( + + // 8 bits + + // [ 0; 7] - 40-47 + // [ 8; 15] - 100-107 + // [ 16; 231] - RGB + // [232; 255] - grayscale + + BlackBg Color = (iota << shiftBg) | flagBg // 40, 100 + RedBg // 41, 101 + GreenBg // 42, 102 + YellowBg // 43, 103 + BlueBg // 44, 104 + MagentaBg // 45, 105 + CyanBg // 46, 106 + WhiteBg // 47, 107 + + BrightBg Color = ((1 << 3) << shiftBg) | flagBg // -> 100 + + // the BrightBg itself doesn't represent + // a color, thus it has not flagBg + + // 5 bits + + // BrownBg represents brown foreground color. + // + // Deprecated: use YellowBg instead, following specifications + BrownBg = YellowBg + + // + maskBg = (0xff << shiftBg) | flagBg +) + +const ( + availFlags = "-+# 0" + esc = "\033[" + clear = esc + "0m" +) + +// IsValid returns true always +// +// Deprecated: don't use this method anymore +func (c Color) IsValid() bool { + return true +} + +// Nos returns string like 1;7;31;45. It +// may be an empty string for empty color. +// If the zero is true, then the string +// is prepended with 0; +func (c Color) Nos(zero bool) string { + return string(c.appendNos(make([]byte, 0, 59), zero)) +} + +func appendCond(bs []byte, cond, semi bool, vals ...byte) []byte { + if !cond { + return bs + } + return appendSemi(bs, semi, vals...) +} + +// if the semi is true, then prepend with semicolon +func appendSemi(bs []byte, semi bool, vals ...byte) []byte { + if semi { + bs = append(bs, ';') + } + return append(bs, vals...) +} + +func itoa(t byte) string { + var ( + a [3]byte + j = 2 + ) + for i := 0; i < 3; i, j = i+1, j-1 { + a[j] = '0' + t%10 + if t = t / 10; t == 0 { + break + } + } + return string(a[j:]) +} + +func (c Color) appendFg(bs []byte, zero bool) []byte { + + if zero || c&maskFm != 0 { + bs = append(bs, ';') + } + + // 0- 7 : 30-37 + // 8-15 : 90-97 + // > 15 : 38;5;val + + switch fg := (c & maskFg) >> shiftFg; { + case fg <= 7: + // '3' and the value itself + bs = append(bs, '3', '0'+byte(fg)) + case fg <= 15: + // '9' and the value itself + bs = append(bs, '9', '0'+byte(fg&^0x08)) // clear bright flag + default: + bs = append(bs, '3', '8', ';', '5', ';') + bs = append(bs, itoa(byte(fg))...) + } + return bs +} + +func (c Color) appendBg(bs []byte, zero bool) []byte { + + if zero || c&(maskFm|maskFg) != 0 { + bs = append(bs, ';') + } + + // 0- 7 : 40- 47 + // 8-15 : 100-107 + // > 15 : 48;5;val + + switch fg := (c & maskBg) >> shiftBg; { + case fg <= 7: + // '3' and the value itself + bs = append(bs, '4', '0'+byte(fg)) + case fg <= 15: + // '1', '0' and the value itself + bs = append(bs, '1', '0', '0'+byte(fg&^0x08)) // clear bright flag + default: + bs = append(bs, '4', '8', ';', '5', ';') + bs = append(bs, itoa(byte(fg))...) + } + return bs +} + +func (c Color) appendFm9(bs []byte, zero bool) []byte { + + bs = appendCond(bs, c&ItalicFm != 0, + zero || c&(BoldFm|FaintFm) != 0, + '3') + bs = appendCond(bs, c&UnderlineFm != 0, + zero || c&(BoldFm|FaintFm|ItalicFm) != 0, + '4') + // don't combine slow and rapid blink using only + // on of them, preferring slow blink + if c&SlowBlinkFm != 0 { + bs = appendSemi(bs, + zero || c&(BoldFm|FaintFm|ItalicFm|UnderlineFm) != 0, + '5') + } else if c&RapidBlinkFm != 0 { + bs = appendSemi(bs, + zero || c&(BoldFm|FaintFm|ItalicFm|UnderlineFm) != 0, + '6') + } + + // including 1-2 + const mask6i = BoldFm | FaintFm | + ItalicFm | UnderlineFm | + SlowBlinkFm | RapidBlinkFm + + bs = appendCond(bs, c&ReverseFm != 0, + zero || c&(mask6i) != 0, + '7') + bs = appendCond(bs, c&ConcealFm != 0, + zero || c&(mask6i|ReverseFm) != 0, + '8') + bs = appendCond(bs, c&CrossedOutFm != 0, + zero || c&(mask6i|ReverseFm|ConcealFm) != 0, + '9') + + return bs +} + +// append 1;3;38;5;216 like string that represents ANSI +// color of the Color; the zero argument requires +// appending of '0' before to reset previous format +// and colors +func (c Color) appendNos(bs []byte, zero bool) []byte { + + if zero { + bs = append(bs, '0') // reset previous + } + + // formats + // + + if c&maskFm != 0 { + + // 1-2 + + // don't combine bold and faint using only on of them, preferring bold + + if c&BoldFm != 0 { + bs = appendSemi(bs, zero, '1') + } else if c&FaintFm != 0 { + bs = appendSemi(bs, zero, '2') + } + + // 3-9 + + const mask9 = ItalicFm | UnderlineFm | + SlowBlinkFm | RapidBlinkFm | + ReverseFm | ConcealFm | CrossedOutFm + + if c&mask9 != 0 { + bs = c.appendFm9(bs, zero) + } + + // 20-21 + + const ( + mask21 = FrakturFm | DoublyUnderlineFm + mask9i = BoldFm | FaintFm | mask9 + ) + + if c&mask21 != 0 { + bs = appendCond(bs, c&FrakturFm != 0, + zero || c&mask9i != 0, + '2', '0') + bs = appendCond(bs, c&DoublyUnderlineFm != 0, + zero || c&(mask9i|FrakturFm) != 0, + '2', '1') + } + + // 50-53 + + const ( + mask53 = FramedFm | EncircledFm | OverlinedFm + mask21i = mask9i | mask21 + ) + + if c&mask53 != 0 { + bs = appendCond(bs, c&FramedFm != 0, + zero || c&mask21i != 0, + '5', '1') + bs = appendCond(bs, c&EncircledFm != 0, + zero || c&(mask21i|FramedFm) != 0, + '5', '2') + bs = appendCond(bs, c&OverlinedFm != 0, + zero || c&(mask21i|FramedFm|EncircledFm) != 0, + '5', '3') + } + + } + + // foreground + if c&maskFg != 0 { + bs = c.appendFg(bs, zero) + } + + // background + if c&maskBg != 0 { + bs = c.appendBg(bs, zero) + } + + return bs +} diff --git a/vendor/github.com/logrusorgru/aurora/disable.png b/vendor/github.com/logrusorgru/aurora/disable.png new file mode 100644 index 0000000..0dd1d63 Binary files /dev/null and b/vendor/github.com/logrusorgru/aurora/disable.png differ diff --git a/vendor/github.com/logrusorgru/aurora/enable.png b/vendor/github.com/logrusorgru/aurora/enable.png new file mode 100644 index 0000000..a488367 Binary files /dev/null and b/vendor/github.com/logrusorgru/aurora/enable.png differ diff --git a/vendor/github.com/logrusorgru/aurora/gopher_aurora.png b/vendor/github.com/logrusorgru/aurora/gopher_aurora.png new file mode 100644 index 0000000..8f61bb2 Binary files /dev/null and b/vendor/github.com/logrusorgru/aurora/gopher_aurora.png differ diff --git a/vendor/github.com/logrusorgru/aurora/printf.png b/vendor/github.com/logrusorgru/aurora/printf.png new file mode 100644 index 0000000..5978844 Binary files /dev/null and b/vendor/github.com/logrusorgru/aurora/printf.png differ diff --git a/vendor/github.com/logrusorgru/aurora/simple.png b/vendor/github.com/logrusorgru/aurora/simple.png new file mode 100644 index 0000000..50edf04 Binary files /dev/null and b/vendor/github.com/logrusorgru/aurora/simple.png differ diff --git a/vendor/github.com/logrusorgru/aurora/sprintf.go b/vendor/github.com/logrusorgru/aurora/sprintf.go new file mode 100644 index 0000000..b92d593 --- /dev/null +++ b/vendor/github.com/logrusorgru/aurora/sprintf.go @@ -0,0 +1,68 @@ +// +// Copyright (c) 2016-2020 The Aurora Authors. All rights reserved. +// This program is free software. It comes without any warranty, +// to the extent permitted by applicable law. You can redistribute +// it and/or modify it under the terms of the Unlicense. See LICENSE +// file for more details or see below. +// + +// +// This is free and unencumbered software released into the public domain. +// +// Anyone is free to copy, modify, publish, use, compile, sell, or +// distribute this software, either in source code form or as a compiled +// binary, for any purpose, commercial or non-commercial, and by any +// means. +// +// In jurisdictions that recognize copyright laws, the author or authors +// of this software dedicate any and all copyright interest in the +// software to the public domain. We make this dedication for the benefit +// of the public at large and to the detriment of our heirs and +// successors. We intend this dedication to be an overt act of +// relinquishment in perpetuity of all present and future rights to this +// software under copyright law. +// +// 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 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. +// +// For more information, please refer to +// + +package aurora + +import ( + "fmt" +) + +// Sprintf allows to use Value as format. For example +// +// v := Sprintf(Red("total: +3.5f points"), Blue(3.14)) +// +// In this case "total:" and "points" will be red, but +// 3.14 will be blue. But, in another example +// +// v := Sprintf(Red("total: +3.5f points"), 3.14) +// +// full string will be red. And no way to clear 3.14 to +// default format and color +func Sprintf(format interface{}, args ...interface{}) string { + switch ft := format.(type) { + case string: + return fmt.Sprintf(ft, args...) + case Value: + for i, v := range args { + if val, ok := v.(Value); ok { + args[i] = val.setTail(ft.Color()) + continue + } + } + return fmt.Sprintf(ft.String(), args...) + } + // unknown type of format (we hope it's a string) + return fmt.Sprintf(fmt.Sprint(format), args...) +} diff --git a/vendor/github.com/logrusorgru/aurora/sprintf.png b/vendor/github.com/logrusorgru/aurora/sprintf.png new file mode 100644 index 0000000..df2b2cc Binary files /dev/null and b/vendor/github.com/logrusorgru/aurora/sprintf.png differ diff --git a/vendor/github.com/logrusorgru/aurora/value.go b/vendor/github.com/logrusorgru/aurora/value.go new file mode 100644 index 0000000..feda25a --- /dev/null +++ b/vendor/github.com/logrusorgru/aurora/value.go @@ -0,0 +1,745 @@ +// +// Copyright (c) 2016-2020 The Aurora Authors. All rights reserved. +// This program is free software. It comes without any warranty, +// to the extent permitted by applicable law. You can redistribute +// it and/or modify it under the terms of the Unlicense. See LICENSE +// file for more details or see below. +// + +// +// This is free and unencumbered software released into the public domain. +// +// Anyone is free to copy, modify, publish, use, compile, sell, or +// distribute this software, either in source code form or as a compiled +// binary, for any purpose, commercial or non-commercial, and by any +// means. +// +// In jurisdictions that recognize copyright laws, the author or authors +// of this software dedicate any and all copyright interest in the +// software to the public domain. We make this dedication for the benefit +// of the public at large and to the detriment of our heirs and +// successors. We intend this dedication to be an overt act of +// relinquishment in perpetuity of all present and future rights to this +// software under copyright law. +// +// 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 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. +// +// For more information, please refer to +// + +package aurora + +import ( + "fmt" + "strconv" + "unicode/utf8" +) + +// A Value represents any printable value +// with it's color +type Value interface { + // String returns string with colors. If there are any color + // or format the string will be terminated with \033[0m + fmt.Stringer + // Format implements fmt.Formatter interface + fmt.Formatter + // Color returns value's color + Color() Color + // Value returns value's value (welcome to the tautology club) + Value() interface{} + + // internals + tail() Color + setTail(Color) Value + + // Bleach returns copy of original value without colors + // + // Deprecated: use Reset instead. + Bleach() Value + // Reset colors and formats + Reset() Value + + // + // Formats + // + // + // Bold or increased intensity (1). + Bold() Value + // Faint, decreased intensity, reset the Bold (2). + Faint() Value + // + // DoublyUnderline or Bold off, double-underline + // per ECMA-48 (21). It depends. + DoublyUnderline() Value + // Fraktur, rarely supported (20). + Fraktur() Value + // + // Italic, not widely supported, sometimes + // treated as inverse (3). + Italic() Value + // Underline (4). + Underline() Value + // + // SlowBlink, blinking less than 150 + // per minute (5). + SlowBlink() Value + // RapidBlink, blinking 150+ per minute, + // not widely supported (6). + RapidBlink() Value + // Blink is alias for the SlowBlink. + Blink() Value + // + // Reverse video, swap foreground and + // background colors (7). + Reverse() Value + // Inverse is alias for the Reverse + Inverse() Value + // + // Conceal, hidden, not widely supported (8). + Conceal() Value + // Hidden is alias for the Conceal + Hidden() Value + // + // CrossedOut, characters legible, but + // marked for deletion (9). + CrossedOut() Value + // StrikeThrough is alias for the CrossedOut. + StrikeThrough() Value + // + // Framed (51). + Framed() Value + // Encircled (52). + Encircled() Value + // + // Overlined (53). + Overlined() Value + + // + // Foreground colors + // + // + // Black foreground color (30) + Black() Value + // Red foreground color (31) + Red() Value + // Green foreground color (32) + Green() Value + // Yellow foreground color (33) + Yellow() Value + // Brown foreground color (33) + // + // Deprecated: use Yellow instead, following specification + Brown() Value + // Blue foreground color (34) + Blue() Value + // Magenta foreground color (35) + Magenta() Value + // Cyan foreground color (36) + Cyan() Value + // White foreground color (37) + White() Value + // + // Bright foreground colors + // + // BrightBlack foreground color (90) + BrightBlack() Value + // BrightRed foreground color (91) + BrightRed() Value + // BrightGreen foreground color (92) + BrightGreen() Value + // BrightYellow foreground color (93) + BrightYellow() Value + // BrightBlue foreground color (94) + BrightBlue() Value + // BrightMagenta foreground color (95) + BrightMagenta() Value + // BrightCyan foreground color (96) + BrightCyan() Value + // BrightWhite foreground color (97) + BrightWhite() Value + // + // Other + // + // Index of pre-defined 8-bit foreground color + // from 0 to 255 (38;5;n). + // + // 0- 7: standard colors (as in ESC [ 30–37 m) + // 8- 15: high intensity colors (as in ESC [ 90–97 m) + // 16-231: 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5) + // 232-255: grayscale from black to white in 24 steps + // + Index(n uint8) Value + // Gray from 0 to 24. + Gray(n uint8) Value + + // + // Background colors + // + // + // BgBlack background color (40) + BgBlack() Value + // BgRed background color (41) + BgRed() Value + // BgGreen background color (42) + BgGreen() Value + // BgYellow background color (43) + BgYellow() Value + // BgBrown background color (43) + // + // Deprecated: use BgYellow instead, following specification + BgBrown() Value + // BgBlue background color (44) + BgBlue() Value + // BgMagenta background color (45) + BgMagenta() Value + // BgCyan background color (46) + BgCyan() Value + // BgWhite background color (47) + BgWhite() Value + // + // Bright background colors + // + // BgBrightBlack background color (100) + BgBrightBlack() Value + // BgBrightRed background color (101) + BgBrightRed() Value + // BgBrightGreen background color (102) + BgBrightGreen() Value + // BgBrightYellow background color (103) + BgBrightYellow() Value + // BgBrightBlue background color (104) + BgBrightBlue() Value + // BgBrightMagenta background color (105) + BgBrightMagenta() Value + // BgBrightCyan background color (106) + BgBrightCyan() Value + // BgBrightWhite background color (107) + BgBrightWhite() Value + // + // Other + // + // BgIndex of 8-bit pre-defined background color + // from 0 to 255 (48;5;n). + // + // 0- 7: standard colors (as in ESC [ 40–47 m) + // 8- 15: high intensity colors (as in ESC [100–107 m) + // 16-231: 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5) + // 232-255: grayscale from black to white in 24 steps + // + BgIndex(n uint8) Value + // BgGray from 0 to 24. + BgGray(n uint8) Value + + // + // Special + // + // Colorize removes existing colors and + // formats of the argument and applies given. + Colorize(color Color) Value +} + +// Value without colors + +type valueClear struct { + value interface{} +} + +func (vc valueClear) String() string { return fmt.Sprint(vc.value) } + +func (vc valueClear) Color() Color { return 0 } +func (vc valueClear) Value() interface{} { return vc.value } + +func (vc valueClear) tail() Color { return 0 } +func (vc valueClear) setTail(Color) Value { return vc } + +func (vc valueClear) Bleach() Value { return vc } +func (vc valueClear) Reset() Value { return vc } + +func (vc valueClear) Bold() Value { return vc } +func (vc valueClear) Faint() Value { return vc } +func (vc valueClear) DoublyUnderline() Value { return vc } +func (vc valueClear) Fraktur() Value { return vc } +func (vc valueClear) Italic() Value { return vc } +func (vc valueClear) Underline() Value { return vc } +func (vc valueClear) SlowBlink() Value { return vc } +func (vc valueClear) RapidBlink() Value { return vc } +func (vc valueClear) Blink() Value { return vc } +func (vc valueClear) Reverse() Value { return vc } +func (vc valueClear) Inverse() Value { return vc } +func (vc valueClear) Conceal() Value { return vc } +func (vc valueClear) Hidden() Value { return vc } +func (vc valueClear) CrossedOut() Value { return vc } +func (vc valueClear) StrikeThrough() Value { return vc } +func (vc valueClear) Framed() Value { return vc } +func (vc valueClear) Encircled() Value { return vc } +func (vc valueClear) Overlined() Value { return vc } + +func (vc valueClear) Black() Value { return vc } +func (vc valueClear) Red() Value { return vc } +func (vc valueClear) Green() Value { return vc } +func (vc valueClear) Yellow() Value { return vc } +func (vc valueClear) Brown() Value { return vc } +func (vc valueClear) Blue() Value { return vc } +func (vc valueClear) Magenta() Value { return vc } +func (vc valueClear) Cyan() Value { return vc } +func (vc valueClear) White() Value { return vc } +func (vc valueClear) BrightBlack() Value { return vc } +func (vc valueClear) BrightRed() Value { return vc } +func (vc valueClear) BrightGreen() Value { return vc } +func (vc valueClear) BrightYellow() Value { return vc } +func (vc valueClear) BrightBlue() Value { return vc } +func (vc valueClear) BrightMagenta() Value { return vc } +func (vc valueClear) BrightCyan() Value { return vc } +func (vc valueClear) BrightWhite() Value { return vc } +func (vc valueClear) Index(uint8) Value { return vc } +func (vc valueClear) Gray(uint8) Value { return vc } + +func (vc valueClear) BgBlack() Value { return vc } +func (vc valueClear) BgRed() Value { return vc } +func (vc valueClear) BgGreen() Value { return vc } +func (vc valueClear) BgYellow() Value { return vc } +func (vc valueClear) BgBrown() Value { return vc } +func (vc valueClear) BgBlue() Value { return vc } +func (vc valueClear) BgMagenta() Value { return vc } +func (vc valueClear) BgCyan() Value { return vc } +func (vc valueClear) BgWhite() Value { return vc } +func (vc valueClear) BgBrightBlack() Value { return vc } +func (vc valueClear) BgBrightRed() Value { return vc } +func (vc valueClear) BgBrightGreen() Value { return vc } +func (vc valueClear) BgBrightYellow() Value { return vc } +func (vc valueClear) BgBrightBlue() Value { return vc } +func (vc valueClear) BgBrightMagenta() Value { return vc } +func (vc valueClear) BgBrightCyan() Value { return vc } +func (vc valueClear) BgBrightWhite() Value { return vc } +func (vc valueClear) BgIndex(uint8) Value { return vc } +func (vc valueClear) BgGray(uint8) Value { return vc } +func (vc valueClear) Colorize(Color) Value { return vc } + +func (vc valueClear) Format(s fmt.State, verb rune) { + // it's enough for many cases (%-+020.10f) + // % - 1 + // availFlags - 3 (5) + // width - 2 + // prec - 3 (.23) + // verb - 1 + // -------------- + // 10 + format := make([]byte, 1, 10) + format[0] = '%' + var f byte + for i := 0; i < len(availFlags); i++ { + if f = availFlags[i]; s.Flag(int(f)) { + format = append(format, f) + } + } + var width, prec int + var ok bool + if width, ok = s.Width(); ok { + format = strconv.AppendInt(format, int64(width), 10) + } + if prec, ok = s.Precision(); ok { + format = append(format, '.') + format = strconv.AppendInt(format, int64(prec), 10) + } + if verb > utf8.RuneSelf { + format = append(format, string(verb)...) + } else { + format = append(format, byte(verb)) + } + fmt.Fprintf(s, string(format), vc.value) +} + +// Value within colors + +type value struct { + value interface{} // value as it + color Color // this color + tailColor Color // tail color +} + +func (v value) String() string { + if v.color != 0 { + if v.tailColor != 0 { + return esc + v.color.Nos(true) + "m" + + fmt.Sprint(v.value) + + esc + v.tailColor.Nos(true) + "m" + } + return esc + v.color.Nos(false) + "m" + fmt.Sprint(v.value) + clear + } + return fmt.Sprint(v.value) +} + +func (v value) Color() Color { return v.color } + +func (v value) Bleach() Value { + v.color, v.tailColor = 0, 0 + return v +} + +func (v value) Reset() Value { + v.color, v.tailColor = 0, 0 + return v +} + +func (v value) tail() Color { return v.tailColor } + +func (v value) setTail(t Color) Value { + v.tailColor = t + return v +} + +func (v value) Value() interface{} { return v.value } + +func (v value) Format(s fmt.State, verb rune) { + + // it's enough for many cases (%-+020.10f) + // % - 1 + // availFlags - 3 (5) + // width - 2 + // prec - 3 (.23) + // verb - 1 + // -------------- + // 10 + // + + // \033[ 5 + // 0;1;3;4;5;7;8;9;20;21;51;52;53 30 + // 38;5;216 8 + // 48;5;216 8 + // m 1 + // + + // \033[0m 7 + // + // x2 (possible tail color) + // + // 10 + 59 * 2 = 128 + + format := make([]byte, 0, 128) + if v.color != 0 { + format = append(format, esc...) + format = v.color.appendNos(format, v.tailColor != 0) + format = append(format, 'm') + } + format = append(format, '%') + var f byte + for i := 0; i < len(availFlags); i++ { + if f = availFlags[i]; s.Flag(int(f)) { + format = append(format, f) + } + } + var width, prec int + var ok bool + if width, ok = s.Width(); ok { + format = strconv.AppendInt(format, int64(width), 10) + } + if prec, ok = s.Precision(); ok { + format = append(format, '.') + format = strconv.AppendInt(format, int64(prec), 10) + } + if verb > utf8.RuneSelf { + format = append(format, string(verb)...) + } else { + format = append(format, byte(verb)) + } + if v.color != 0 { + if v.tailColor != 0 { + // set next (previous) format clearing current one + format = append(format, esc...) + format = v.tailColor.appendNos(format, true) + format = append(format, 'm') + } else { + format = append(format, clear...) // just clear + } + } + fmt.Fprintf(s, string(format), v.value) +} + +func (v value) Bold() Value { + v.color = (v.color &^ FaintFm) | BoldFm + return v +} + +func (v value) Faint() Value { + v.color = (v.color &^ BoldFm) | FaintFm + return v +} + +func (v value) DoublyUnderline() Value { + v.color |= DoublyUnderlineFm + return v +} + +func (v value) Fraktur() Value { + v.color |= FrakturFm + return v +} + +func (v value) Italic() Value { + v.color |= ItalicFm + return v +} + +func (v value) Underline() Value { + v.color |= UnderlineFm + return v +} + +func (v value) SlowBlink() Value { + v.color = (v.color &^ RapidBlinkFm) | SlowBlinkFm + return v +} + +func (v value) RapidBlink() Value { + v.color = (v.color &^ SlowBlinkFm) | RapidBlinkFm + return v +} + +func (v value) Blink() Value { + return v.SlowBlink() +} + +func (v value) Reverse() Value { + v.color |= ReverseFm + return v +} + +func (v value) Inverse() Value { + return v.Reverse() +} + +func (v value) Conceal() Value { + v.color |= ConcealFm + return v +} + +func (v value) Hidden() Value { + return v.Conceal() +} + +func (v value) CrossedOut() Value { + v.color |= CrossedOutFm + return v +} + +func (v value) StrikeThrough() Value { + return v.CrossedOut() +} + +func (v value) Framed() Value { + v.color |= FramedFm + return v +} + +func (v value) Encircled() Value { + v.color |= EncircledFm + return v +} + +func (v value) Overlined() Value { + v.color |= OverlinedFm + return v +} + +func (v value) Black() Value { + v.color = (v.color &^ maskFg) | BlackFg + return v +} + +func (v value) Red() Value { + v.color = (v.color &^ maskFg) | RedFg + return v +} + +func (v value) Green() Value { + v.color = (v.color &^ maskFg) | GreenFg + return v +} + +func (v value) Yellow() Value { + v.color = (v.color &^ maskFg) | YellowFg + return v +} + +func (v value) Brown() Value { + return v.Yellow() +} + +func (v value) Blue() Value { + v.color = (v.color &^ maskFg) | BlueFg + return v +} + +func (v value) Magenta() Value { + v.color = (v.color &^ maskFg) | MagentaFg + return v +} + +func (v value) Cyan() Value { + v.color = (v.color &^ maskFg) | CyanFg + return v +} + +func (v value) White() Value { + v.color = (v.color &^ maskFg) | WhiteFg + return v +} + +func (v value) BrightBlack() Value { + v.color = (v.color &^ maskFg) | BrightFg | BlackFg + return v +} + +func (v value) BrightRed() Value { + v.color = (v.color &^ maskFg) | BrightFg | RedFg + return v +} + +func (v value) BrightGreen() Value { + v.color = (v.color &^ maskFg) | BrightFg | GreenFg + return v +} + +func (v value) BrightYellow() Value { + v.color = (v.color &^ maskFg) | BrightFg | YellowFg + return v +} + +func (v value) BrightBlue() Value { + v.color = (v.color &^ maskFg) | BrightFg | BlueFg + return v +} + +func (v value) BrightMagenta() Value { + v.color = (v.color &^ maskFg) | BrightFg | MagentaFg + return v +} + +func (v value) BrightCyan() Value { + v.color = (v.color &^ maskFg) | BrightFg | CyanFg + return v +} + +func (v value) BrightWhite() Value { + v.color = (v.color &^ maskFg) | BrightFg | WhiteFg + return v +} + +func (v value) Index(n uint8) Value { + v.color = (v.color &^ maskFg) | (Color(n) << shiftFg) | flagFg + return v +} + +func (v value) Gray(n uint8) Value { + if n > 23 { + n = 23 + } + v.color = (v.color &^ maskFg) | (Color(232+n) << shiftFg) | flagFg + return v +} + +func (v value) BgBlack() Value { + v.color = (v.color &^ maskBg) | BlackBg + return v +} + +func (v value) BgRed() Value { + v.color = (v.color &^ maskBg) | RedBg + return v +} + +func (v value) BgGreen() Value { + v.color = (v.color &^ maskBg) | GreenBg + return v +} + +func (v value) BgYellow() Value { + v.color = (v.color &^ maskBg) | YellowBg + return v +} + +func (v value) BgBrown() Value { + return v.BgYellow() +} + +func (v value) BgBlue() Value { + v.color = (v.color &^ maskBg) | BlueBg + return v +} + +func (v value) BgMagenta() Value { + v.color = (v.color &^ maskBg) | MagentaBg + return v +} + +func (v value) BgCyan() Value { + v.color = (v.color &^ maskBg) | CyanBg + return v +} + +func (v value) BgWhite() Value { + v.color = (v.color &^ maskBg) | WhiteBg + return v +} + +func (v value) BgBrightBlack() Value { + v.color = (v.color &^ maskBg) | BrightBg | BlackBg + return v +} + +func (v value) BgBrightRed() Value { + v.color = (v.color &^ maskBg) | BrightBg | RedBg + return v +} + +func (v value) BgBrightGreen() Value { + v.color = (v.color &^ maskBg) | BrightBg | GreenBg + return v +} + +func (v value) BgBrightYellow() Value { + v.color = (v.color &^ maskBg) | BrightBg | YellowBg + return v +} + +func (v value) BgBrightBlue() Value { + v.color = (v.color &^ maskBg) | BrightBg | BlueBg + return v +} + +func (v value) BgBrightMagenta() Value { + v.color = (v.color &^ maskBg) | BrightBg | MagentaBg + return v +} + +func (v value) BgBrightCyan() Value { + v.color = (v.color &^ maskBg) | BrightBg | CyanBg + return v +} + +func (v value) BgBrightWhite() Value { + v.color = (v.color &^ maskBg) | BrightBg | WhiteBg + return v +} + +func (v value) BgIndex(n uint8) Value { + v.color = (v.color &^ maskBg) | (Color(n) << shiftBg) | flagBg + return v +} + +func (v value) BgGray(n uint8) Value { + if n > 23 { + n = 23 + } + v.color = (v.color &^ maskBg) | (Color(232+n) << shiftBg) | flagBg + return v +} + +func (v value) Colorize(color Color) Value { + v.color = color + return v +} diff --git a/vendor/github.com/logrusorgru/aurora/wrap.go b/vendor/github.com/logrusorgru/aurora/wrap.go new file mode 100644 index 0000000..44e1aa6 --- /dev/null +++ b/vendor/github.com/logrusorgru/aurora/wrap.go @@ -0,0 +1,558 @@ +// +// Copyright (c) 2016-2020 The Aurora Authors. All rights reserved. +// This program is free software. It comes without any warranty, +// to the extent permitted by applicable law. You can redistribute +// it and/or modify it under the terms of the Unlicense. See LICENSE +// file for more details or see below. +// + +// +// This is free and unencumbered software released into the public domain. +// +// Anyone is free to copy, modify, publish, use, compile, sell, or +// distribute this software, either in source code form or as a compiled +// binary, for any purpose, commercial or non-commercial, and by any +// means. +// +// In jurisdictions that recognize copyright laws, the author or authors +// of this software dedicate any and all copyright interest in the +// software to the public domain. We make this dedication for the benefit +// of the public at large and to the detriment of our heirs and +// successors. We intend this dedication to be an overt act of +// relinquishment in perpetuity of all present and future rights to this +// software under copyright law. +// +// 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 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. +// +// For more information, please refer to +// + +package aurora + +// Colorize wraps given value into Value with +// given colors. For example +// +// s := Colorize("some", BlueFg|GreenBg|BoldFm) +// +// returns a Value with blue foreground, green +// background and bold. Unlike functions like +// Red/BgBlue/Bold etc. This function clears +// all previous colors and formats. Thus +// +// s := Colorize(Red("some"), BgBlue) +// +// clears red color from value +func Colorize(arg interface{}, color Color) Value { + if val, ok := arg.(value); ok { + val.color = color + return val + } + return value{arg, color, 0} +} + +// Reset wraps given argument returning Value +// without formats and colors. +func Reset(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.Reset() + } + return value{value: arg} +} + +// +// Formats +// + +// Bold or increased intensity (1). +func Bold(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.Bold() + } + return value{value: arg, color: BoldFm} +} + +// Faint decreases intensity (2). +// The Faint rejects the Bold. +func Faint(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.Faint() + } + return value{value: arg, color: FaintFm} +} + +// DoublyUnderline or Bold off, double-underline +// per ECMA-48 (21). +func DoublyUnderline(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.DoublyUnderline() + } + return value{value: arg, color: DoublyUnderlineFm} +} + +// Fraktur is rarely supported (20). +func Fraktur(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.Fraktur() + } + return value{value: arg, color: FrakturFm} +} + +// Italic is not widely supported, sometimes +// treated as inverse (3). +func Italic(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.Italic() + } + return value{value: arg, color: ItalicFm} +} + +// Underline (4). +func Underline(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.Underline() + } + return value{value: arg, color: UnderlineFm} +} + +// SlowBlink makes text blink less than +// 150 per minute (5). +func SlowBlink(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.SlowBlink() + } + return value{value: arg, color: SlowBlinkFm} +} + +// RapidBlink makes text blink 150+ per +// minute. It is not widely supported (6). +func RapidBlink(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.RapidBlink() + } + return value{value: arg, color: RapidBlinkFm} +} + +// Blink is alias for the SlowBlink. +func Blink(arg interface{}) Value { + return SlowBlink(arg) +} + +// Reverse video, swap foreground and +// background colors (7). +func Reverse(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.Reverse() + } + return value{value: arg, color: ReverseFm} +} + +// Inverse is alias for the Reverse +func Inverse(arg interface{}) Value { + return Reverse(arg) +} + +// Conceal hides text, preserving an ability to select +// the text and copy it. It is not widely supported (8). +func Conceal(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.Conceal() + } + return value{value: arg, color: ConcealFm} +} + +// Hidden is alias for the Conceal +func Hidden(arg interface{}) Value { + return Conceal(arg) +} + +// CrossedOut makes characters legible, but +// marked for deletion (9). +func CrossedOut(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.CrossedOut() + } + return value{value: arg, color: CrossedOutFm} +} + +// StrikeThrough is alias for the CrossedOut. +func StrikeThrough(arg interface{}) Value { + return CrossedOut(arg) +} + +// Framed (51). +func Framed(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.Framed() + } + return value{value: arg, color: FramedFm} +} + +// Encircled (52). +func Encircled(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.Encircled() + } + return value{value: arg, color: EncircledFm} +} + +// Overlined (53). +func Overlined(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.Overlined() + } + return value{value: arg, color: OverlinedFm} +} + +// +// Foreground colors +// +// + +// Black foreground color (30) +func Black(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.Black() + } + return value{value: arg, color: BlackFg} +} + +// Red foreground color (31) +func Red(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.Red() + } + return value{value: arg, color: RedFg} +} + +// Green foreground color (32) +func Green(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.Green() + } + return value{value: arg, color: GreenFg} +} + +// Yellow foreground color (33) +func Yellow(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.Yellow() + } + return value{value: arg, color: YellowFg} +} + +// Brown foreground color (33) +// +// Deprecated: use Yellow instead, following specification +func Brown(arg interface{}) Value { + return Yellow(arg) +} + +// Blue foreground color (34) +func Blue(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.Blue() + } + return value{value: arg, color: BlueFg} +} + +// Magenta foreground color (35) +func Magenta(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.Magenta() + } + return value{value: arg, color: MagentaFg} +} + +// Cyan foreground color (36) +func Cyan(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.Cyan() + } + return value{value: arg, color: CyanFg} +} + +// White foreground color (37) +func White(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.White() + } + return value{value: arg, color: WhiteFg} +} + +// +// Bright foreground colors +// + +// BrightBlack foreground color (90) +func BrightBlack(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BrightBlack() + } + return value{value: arg, color: BrightFg | BlackFg} +} + +// BrightRed foreground color (91) +func BrightRed(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BrightRed() + } + return value{value: arg, color: BrightFg | RedFg} +} + +// BrightGreen foreground color (92) +func BrightGreen(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BrightGreen() + } + return value{value: arg, color: BrightFg | GreenFg} +} + +// BrightYellow foreground color (93) +func BrightYellow(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BrightYellow() + } + return value{value: arg, color: BrightFg | YellowFg} +} + +// BrightBlue foreground color (94) +func BrightBlue(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BrightBlue() + } + return value{value: arg, color: BrightFg | BlueFg} +} + +// BrightMagenta foreground color (95) +func BrightMagenta(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BrightMagenta() + } + return value{value: arg, color: BrightFg | MagentaFg} +} + +// BrightCyan foreground color (96) +func BrightCyan(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BrightCyan() + } + return value{value: arg, color: BrightFg | CyanFg} +} + +// BrightWhite foreground color (97) +func BrightWhite(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BrightWhite() + } + return value{value: arg, color: BrightFg | WhiteFg} +} + +// +// Other +// + +// Index of pre-defined 8-bit foreground color +// from 0 to 255 (38;5;n). +// +// 0- 7: standard colors (as in ESC [ 30–37 m) +// 8- 15: high intensity colors (as in ESC [ 90–97 m) +// 16-231: 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5) +// 232-255: grayscale from black to white in 24 steps +// +func Index(n uint8, arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.Index(n) + } + return value{value: arg, color: (Color(n) << shiftFg) | flagFg} +} + +// Gray from 0 to 24. +func Gray(n uint8, arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.Gray(n) + } + if n > 23 { + n = 23 + } + return value{value: arg, color: (Color(232+n) << shiftFg) | flagFg} +} + +// +// Background colors +// +// + +// BgBlack background color (40) +func BgBlack(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BgBlack() + } + return value{value: arg, color: BlackBg} +} + +// BgRed background color (41) +func BgRed(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BgRed() + } + return value{value: arg, color: RedBg} +} + +// BgGreen background color (42) +func BgGreen(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BgGreen() + } + return value{value: arg, color: GreenBg} +} + +// BgYellow background color (43) +func BgYellow(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BgYellow() + } + return value{value: arg, color: YellowBg} +} + +// BgBrown background color (43) +// +// Deprecated: use BgYellow instead, following specification +func BgBrown(arg interface{}) Value { + return BgYellow(arg) +} + +// BgBlue background color (44) +func BgBlue(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BgBlue() + } + return value{value: arg, color: BlueBg} +} + +// BgMagenta background color (45) +func BgMagenta(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BgMagenta() + } + return value{value: arg, color: MagentaBg} +} + +// BgCyan background color (46) +func BgCyan(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BgCyan() + } + return value{value: arg, color: CyanBg} +} + +// BgWhite background color (47) +func BgWhite(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BgWhite() + } + return value{value: arg, color: WhiteBg} +} + +// +// Bright background colors +// + +// BgBrightBlack background color (100) +func BgBrightBlack(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BgBrightBlack() + } + return value{value: arg, color: BrightBg | BlackBg} +} + +// BgBrightRed background color (101) +func BgBrightRed(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BgBrightRed() + } + return value{value: arg, color: BrightBg | RedBg} +} + +// BgBrightGreen background color (102) +func BgBrightGreen(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BgBrightGreen() + } + return value{value: arg, color: BrightBg | GreenBg} +} + +// BgBrightYellow background color (103) +func BgBrightYellow(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BgBrightYellow() + } + return value{value: arg, color: BrightBg | YellowBg} +} + +// BgBrightBlue background color (104) +func BgBrightBlue(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BgBrightBlue() + } + return value{value: arg, color: BrightBg | BlueBg} +} + +// BgBrightMagenta background color (105) +func BgBrightMagenta(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BgBrightMagenta() + } + return value{value: arg, color: BrightBg | MagentaBg} +} + +// BgBrightCyan background color (106) +func BgBrightCyan(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BgBrightCyan() + } + return value{value: arg, color: BrightBg | CyanBg} +} + +// BgBrightWhite background color (107) +func BgBrightWhite(arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BgBrightWhite() + } + return value{value: arg, color: BrightBg | WhiteBg} +} + +// +// Other +// + +// BgIndex of 8-bit pre-defined background color +// from 0 to 255 (48;5;n). +// +// 0- 7: standard colors (as in ESC [ 40–47 m) +// 8- 15: high intensity colors (as in ESC [100–107 m) +// 16-231: 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5) +// 232-255: grayscale from black to white in 24 steps +// +func BgIndex(n uint8, arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BgIndex(n) + } + return value{value: arg, color: (Color(n) << shiftBg) | flagBg} +} + +// BgGray from 0 to 24. +func BgGray(n uint8, arg interface{}) Value { + if val, ok := arg.(Value); ok { + return val.BgGray(n) + } + if n > 23 { + n = 23 + } + return value{value: arg, color: (Color(n+232) << shiftBg) | flagBg} +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 0a58252..5202a19 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -7,6 +7,10 @@ github.com/Masterminds/semver/v3 # github.com/Masterminds/sprig/v3 v3.2.3 ## explicit; go 1.13 github.com/Masterminds/sprig/v3 +# github.com/andreazorzetto/yh v0.4.0 +## explicit; go 1.15 +github.com/andreazorzetto/yh +github.com/andreazorzetto/yh/highlight # github.com/cpuguy83/go-md2man/v2 v2.0.2 ## explicit; go 1.11 github.com/cpuguy83/go-md2man/v2/md2man @@ -19,6 +23,9 @@ github.com/huandu/xstrings # github.com/imdario/mergo v0.3.11 ## explicit; go 1.13 github.com/imdario/mergo +# github.com/logrusorgru/aurora v2.0.3+incompatible +## explicit +github.com/logrusorgru/aurora # github.com/mitchellh/copystructure v1.0.0 ## explicit github.com/mitchellh/copystructure