diff --git a/go.mod b/go.mod index 46a95527..13196de6 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/obalunenko/getenv v1.10.0 github.com/obalunenko/logger v0.6.0 github.com/obalunenko/version v1.1.0 - github.com/savioxavier/termlink v1.2.1 + github.com/savioxavier/termlink v1.3.0 github.com/stretchr/testify v1.8.4 github.com/urfave/cli/v2 v2.25.5 ) @@ -21,7 +21,6 @@ require ( github.com/evalphobia/logrus_sentry v0.8.2 // indirect github.com/fatih/color v1.13.0 // indirect github.com/getsentry/raven-go v0.2.0 // indirect - github.com/jwalton/go-supportscolor v1.1.0 // indirect github.com/mattn/go-colorable v0.1.9 // indirect github.com/mattn/go-isatty v0.0.14 // indirect github.com/pkg/errors v0.9.1 // indirect diff --git a/go.sum b/go.sum index cd218073..9436f1f0 100644 --- a/go.sum +++ b/go.sum @@ -19,8 +19,6 @@ github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/getsentry/raven-go v0.2.0 h1:no+xWJRb5ZI7eE8TWgIq1jLulQiIoLG0IfYxv5JYMGs= github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ= -github.com/jwalton/go-supportscolor v1.1.0 h1:HsXFJdMPjRUAx8cIW6g30hVSFYaxh9yRQwEWgkAR7lQ= -github.com/jwalton/go-supportscolor v1.1.0/go.mod h1:hFVUAZV2cWg+WFFC4v8pT2X/S2qUUBYMioBD9AINXGs= github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA= github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg= github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U= @@ -40,8 +38,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/savioxavier/termlink v1.2.1 h1:O9ZQvk9BPQQK4JQeMB56ZfV8uam0Ts+f97mJme7+dq8= -github.com/savioxavier/termlink v1.2.1/go.mod h1:WA7FTALNwN41NGnmQMIrnjAYTsEhIAZ4RuzgEiB0Jp8= +github.com/savioxavier/termlink v1.3.0 h1:3Gl4FzQjUyiHzmoEDfmWEhgIwDiJY4poOQHP+k8ReA4= +github.com/savioxavier/termlink v1.3.0/go.mod h1:5T5ePUlWbxCHIwyF8/Ez1qufOoGM89RCg9NvG+3G3gc= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -55,13 +53,10 @@ github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsr golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= diff --git a/vendor/github.com/jwalton/go-supportscolor/LICENSE b/vendor/github.com/jwalton/go-supportscolor/LICENSE deleted file mode 100644 index f4d0b1e1..00000000 --- a/vendor/github.com/jwalton/go-supportscolor/LICENSE +++ /dev/null @@ -1,23 +0,0 @@ -MIT License - -Copyright (c) Jason Walton (https://www.thedreaming.org) - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - - -This software was ported from https://github.com/chalk/supports-color/, which has the following license: - -MIT License - -Copyright (c) Sindre Sorhus (https://sindresorhus.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/github.com/jwalton/go-supportscolor/Makefile b/vendor/github.com/jwalton/go-supportscolor/Makefile deleted file mode 100644 index ca432864..00000000 --- a/vendor/github.com/jwalton/go-supportscolor/Makefile +++ /dev/null @@ -1,85 +0,0 @@ -# Adapted from https://github.com/vincentbernat/hellogopher - -MODULE = $(shell env GO111MODULE=on $(GO) list -m) -DATE ?= $(shell date +%FT%T%z) -VERSION ?= $(shell git describe --tags --always --dirty --match=v* | cut -c2- 2> /dev/null || \ - cat $(CURDIR)/.version 2> /dev/null || echo v0) -COMMIT ?= $(shell git rev-parse HEAD) -PKGS = $(or $(PKG),$(shell env GO111MODULE=on $(GO) list ./...)) -TESTPKGS = $(shell env GO111MODULE=on $(GO) list -f \ - '{{ if or .TestGoFiles .XTestGoFiles }}{{ .ImportPath }}{{ end }}' \ - $(PKGS)) -GO_FILES := $(shell find . -name '*.go' | grep -v /vendor/) - -GO = go -GOLINT = golint -GOLANGCILINT = golangci-lint -GOCOV = gocov -GOCOVXML = gocov-xml - -TIMEOUT = 15 -V = 0 -Q = $(if $(filter 1,$V),,@) -# Prompt shown before each item -M = $(shell printf "\033[34;1m▶\033[0m") - -export GO111MODULE=on - -.PHONY: all -all: fmt lint test ## Build, format, and test - -# Tests - -TEST_TARGETS := test-default test-bench test-short test-verbose test-race -.PHONY: $(TEST_TARGETS) check test tests -test-bench: ARGS=-run=__absolutelynothing__ -bench=. ## Run benchmarks -test-short: ARGS=-short ## Run only short tests -test-verbose: ARGS=-v ## Run tests in verbose mode with coverage reporting -test-race: ARGS=-race ## Run tests with race detector -$(TEST_TARGETS): NAME=$(MAKECMDGOALS:test-%=%) -$(TEST_TARGETS): test -test: lint ; $(info $(M) running $(NAME:%=% )tests…) @ ## Run tests - $Q $(GO) test -timeout $(TIMEOUT)s $(ARGS) $(TESTPKGS) - -COVERAGE_MODE = atomic -COVERAGE_PROFILE = $(COVERAGE_DIR)/profile.out -COVERAGE_XML = $(COVERAGE_DIR)/coverage.xml -COVERAGE_HTML = $(COVERAGE_DIR)/index.html -.PHONY: test-coverage test-coverage-tools -test-coverage-tools: | $(GOCOV) $(GOCOVXML) -test-coverage: COVERAGE_DIR := $(CURDIR)/test/coverage.$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") -test-coverage: lint test-coverage-tools ; $(info $(M) running coverage tests…) @ ## Run coverage tests - $Q mkdir -p $(COVERAGE_DIR) - $Q $(GO) test \ - -coverpkg=$$($(GO) list -f '{{ join .Deps "\n" }}' $(TESTPKGS) | \ - grep '^$(MODULE)/' | \ - tr '\n' ',' | sed 's/,$$//') \ - -covermode=$(COVERAGE_MODE) \ - -coverprofile="$(COVERAGE_PROFILE)" $(TESTPKGS) - $Q $(GO) tool cover -html=$(COVERAGE_PROFILE) -o $(COVERAGE_HTML) - $Q $(GOCOV) convert $(COVERAGE_PROFILE) | $(GOCOVXML) > $(COVERAGE_XML) - -.PHONY: lint -lint: golint golangci-lint ## Run linters - -golint: | ; $(info $(M) running golint…) @ ## Run golint - $Q $(GOLINT) -set_exit_status ./... - -.PHONY: golangci-lint -golangci-lint: | ; $(info $(M) running golangci-lint…) @ ## Run golangci-lint - $Q $(GOLANGCILINT) run - -.PHONY: fmt -fmt: ; $(info $(M) running gofmt…) @ ## Run gofmt on all source files - $Q $(GO) fmt $(PKGS) - -# Misc - -.PHONY: help -help: - @grep -hE '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \ - awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-17s\033[0m %s\n", $$1, $$2}' - -.PHONY: version -version: - @echo $(VERSION) diff --git a/vendor/github.com/jwalton/go-supportscolor/README.md b/vendor/github.com/jwalton/go-supportscolor/README.md deleted file mode 100644 index e81819d9..00000000 --- a/vendor/github.com/jwalton/go-supportscolor/README.md +++ /dev/null @@ -1,72 +0,0 @@ -# supports-color - -Go library to detect whether a terminal supports color, and enables ANSI color support in recent Windows 10 builds. - -This is a port of the Node.js package [supports-color](https://github.com/chalk/supports-color) v8.1.1 by [Sindre Sorhus](https://github.com/sindresorhus) and [Josh Junon](https://github.com/qix-). - -## Install - -```sh -$ go get github.com/jwalton/go-supportscolor -``` - -## Usage - -```go -import ( - "fmt" - "github.com/jwalton/go-supportscolor" -) - -if supportscolor.Stdout().SupportsColor { - fmt.Println("Terminal stdout supports color") -} - -if supportscolor.Stdout().Has256 { - fmt.Println("Terminal stdout supports 256 colors") -} - -if supportscolor.Stderr().Has16m { - fmt.Println("Terminal stderr supports 16 million colors (true color)") -} -``` - -## Windows 10 Support - -`supportscolor` is cross-platform, and will work on Linux and MacOS systems, but will also work on Windows 10. - -Many ANSI color libraries for Go do a poor job of handling colors in Windows. This is because historically, Windows has not supported ANSI color codes, so hacks like [ansicon](https://github.com/adoxa/ansicon) or [go-colorable](https://github.com/mattn/go-colorable) were required. However, Windows 10 has supported ANSI escape codes since 2017 (build 10586 for 256 color support, and build 14931 for 16.7 million true color support). In [Windows Terminal](https://github.com/Microsoft/Terminal) this is enabled by default, but in `CMD.EXE` or PowerShell, ANSI support must be enabled via [`ENABLE_VIRTUAL_TERMINAL_PROCESSING`](https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences). - -This library takes care of all of this for you, though - if you call `supportscolor.Stdout()` on a modern build of Windows 10, it will set the `ENABLE_VIRTUAL_TERMINAL_PROCESSING` console mode automatically if required, and return the correct color level, and then you can just write ANSI escape codes to stdout and not worry about it. If someone uses your app on an old version of Windows, this will return `SupportsColor == false`, and you can write black and white to stdout. - -## API - -Returns a `supportscolor.Support` with a `Stdout()` and `Stderr()` function for testing either stream. (There's one for stdout and one for stderr, because if you run `mycmd > foo.txt` then stdout would be redirected to a file, and since it would not be a TTY would not have color support, while stderr would still be going to the console and would have color support.) - -The `Stdout()`/`Stderr()` objects specify a level of support for color through a `.Level` property and a corresponding flag: - -- `.Level = None` and `.SupportsColor = false`: No color support -- `.Level = Basic` and `.SupportsColor = true`: Basic color support (16 colors) -- `.Level = Ansi256` and `.Has256 = true`: 256 color support -- `.Level = Ansi16m` and `.Has16m = true`: True color support (16 million colors) - -### `supportscolor.SupportsColor(fd, ...options)` - -Additionally, `supportscolor` exposes the `.SupportsColor()` function that takes an arbitrary file descriptor (e.g. `os.Stdout.Fd()`) and options and will (re-)evaluate color support for an arbitrary stream. - -For example, `supportscolor.Stdout()` is the equivalent of `supportscolor.SupportsColor(os.Stdout.Fd())`. - -Available options are: - -- `supportscolor.IsTTYOption(isTTY bool)` - Force whether the given file should be considered a TTY or not. If this not specified, TTY status will be detected automatically via `term.IsTerminal()`. -- `supportscolor.SniffFlagsOption(sniffFlags bool)` - By default it is `true`, which instructs `SupportsColor()` to sniff `os.Args` for the multitude of `--color` flags (see _Info_ below). If `false`, then `os.Args` is not considered when determining color support. - -## Info - -By default, supportscolor checks `os.Args` for the `--color` and `--no-color` CLI flags. - -For situations where using `--color` is not possible, use the environment variable `FORCE_COLOR=1` (level 1 - 16 colors), `FORCE_COLOR=2` (level 2 - 256 colors), or `FORCE_COLOR=3` (level 3 - true color) to forcefully enable color, or `FORCE_COLOR=0` to forcefully disable. The use of `FORCE_COLOR` overrides all other color support checks. - -If `NO_COLOR` is specified and `FORCE_COLOR` is not, then colors will be disabled. - -Explicit 256/True color mode can be enabled using the `--color=256` and `--color=16m` flags, respectively. diff --git a/vendor/github.com/jwalton/go-supportscolor/colorlevel_string.go b/vendor/github.com/jwalton/go-supportscolor/colorlevel_string.go deleted file mode 100644 index db260224..00000000 --- a/vendor/github.com/jwalton/go-supportscolor/colorlevel_string.go +++ /dev/null @@ -1,26 +0,0 @@ -// Code generated by "stringer -type=ColorLevel"; DO NOT EDIT. - -package supportscolor - -import "strconv" - -func _() { - // An "invalid array index" compiler error signifies that the constant values have changed. - // Re-run the stringer command to generate them again. - var x [1]struct{} - _ = x[None-0] - _ = x[Basic-1] - _ = x[Ansi256-2] - _ = x[Ansi16m-3] -} - -const _ColorLevel_name = "NoneBasicAnsi256Ansi16m" - -var _ColorLevel_index = [...]uint8{0, 4, 9, 16, 23} - -func (i ColorLevel) String() string { - if i < 0 || i >= ColorLevel(len(_ColorLevel_index)-1) { - return "ColorLevel(" + strconv.FormatInt(int64(i), 10) + ")" - } - return _ColorLevel_name[_ColorLevel_index[i]:_ColorLevel_index[i+1]] -} diff --git a/vendor/github.com/jwalton/go-supportscolor/colorlevels.go b/vendor/github.com/jwalton/go-supportscolor/colorlevels.go deleted file mode 100644 index d49dc5a5..00000000 --- a/vendor/github.com/jwalton/go-supportscolor/colorlevels.go +++ /dev/null @@ -1,17 +0,0 @@ -package supportscolor - -//go:generate stringer -type=ColorLevel - -// ColorLevel represents the ANSI color level supported by the terminal. -type ColorLevel int - -const ( - // None represents a terminal that does not support color at all. - None ColorLevel = 0 - // Basic represents a terminal with basic 16 color support. - Basic ColorLevel = 1 - // Ansi256 represents a terminal with 256 color support. - Ansi256 ColorLevel = 2 - // Ansi16m represents a terminal with full true color support. - Ansi16m ColorLevel = 3 -) diff --git a/vendor/github.com/jwalton/go-supportscolor/di.go b/vendor/github.com/jwalton/go-supportscolor/di.go deleted file mode 100644 index 1b0a51c5..00000000 --- a/vendor/github.com/jwalton/go-supportscolor/di.go +++ /dev/null @@ -1,52 +0,0 @@ -package supportscolor - -import ( - "os" - "runtime" - - hasflag "github.com/jwalton/go-supportscolor/pkg/hasFlag" - "golang.org/x/term" -) - -type environment interface { - LookupEnv(name string) (string, bool) - Getenv(name string) string - HasFlag(name string) bool - IsTerminal(fd int) bool - getWindowsVersion() (majorVersion, minorVersion, buildNumber uint32) - osEnableColor() bool - getGOOS() string -} - -type defaultEnvironmentType struct{} - -func (*defaultEnvironmentType) LookupEnv(name string) (string, bool) { - return os.LookupEnv(name) -} - -func (*defaultEnvironmentType) Getenv(name string) string { - return os.Getenv(name) -} - -func (*defaultEnvironmentType) HasFlag(flag string) bool { - return hasflag.HasFlag(flag) -} - -func (*defaultEnvironmentType) IsTerminal(fd int) bool { - // TODO: Replace with github.com/mattn/go-isatty? - return term.IsTerminal(int(fd)) -} - -func (*defaultEnvironmentType) getWindowsVersion() (majorVersion, minorVersion, buildNumber uint32) { - return getWindowsVersion() -} - -func (*defaultEnvironmentType) osEnableColor() bool { - return enableColor() -} - -func (*defaultEnvironmentType) getGOOS() string { - return runtime.GOOS -} - -var defaultEnvironment = defaultEnvironmentType{} diff --git a/vendor/github.com/jwalton/go-supportscolor/osutils.go b/vendor/github.com/jwalton/go-supportscolor/osutils.go deleted file mode 100644 index 7206e475..00000000 --- a/vendor/github.com/jwalton/go-supportscolor/osutils.go +++ /dev/null @@ -1,13 +0,0 @@ -// +build !windows - -package supportscolor - -func getWindowsVersion() (majorVersion, minorVersion, buildNumber uint32) { - return 0, 0, 0 -} - -// enableColor will enable color in the terminal. Returns true if color was -// enabled, false otherwise. -func enableColor() bool { - return true -} diff --git a/vendor/github.com/jwalton/go-supportscolor/osutils_windows.go b/vendor/github.com/jwalton/go-supportscolor/osutils_windows.go deleted file mode 100644 index d53ee36c..00000000 --- a/vendor/github.com/jwalton/go-supportscolor/osutils_windows.go +++ /dev/null @@ -1,39 +0,0 @@ -// +build windows - -package supportscolor - -import ( - "golang.org/x/sys/windows" -) - -func getWindowsVersion() (majorVersion, minorVersion, buildNumber uint32) { - return windows.RtlGetNtVersionNumbers() -} - -func enableColor() bool { - handle, err := windows.GetStdHandle(windows.STD_OUTPUT_HANDLE) - if err != nil { - return false - } - - // Get the existing console mode. - var mode uint32 - err = windows.GetConsoleMode(handle, &mode) - if err != nil { - return false - } - - // If ENABLE_VIRTUAL_TERMINAL_PROCESSING is not set, then set it. This will - // enable native ANSI color support from Windows. - if mode&windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING != windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING { - // Enable color. - // See https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences. - mode = mode | windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING - err = windows.SetConsoleMode(handle, mode) - if err != nil { - return false - } - } - - return true -} diff --git a/vendor/github.com/jwalton/go-supportscolor/pkg/hasFlag/LICENSE b/vendor/github.com/jwalton/go-supportscolor/pkg/hasFlag/LICENSE deleted file mode 100644 index 93932b4d..00000000 --- a/vendor/github.com/jwalton/go-supportscolor/pkg/hasFlag/LICENSE +++ /dev/null @@ -1,11 +0,0 @@ -The files in this folder were ported from https://github.com/sindresorhus/has-flag, which had the following copyright notice: - -MIT License - -Copyright (c) Sindre Sorhus (sindresorhus.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/github.com/jwalton/go-supportscolor/pkg/hasFlag/hasFlag.go b/vendor/github.com/jwalton/go-supportscolor/pkg/hasFlag/hasFlag.go deleted file mode 100644 index ded2ca63..00000000 --- a/vendor/github.com/jwalton/go-supportscolor/pkg/hasFlag/hasFlag.go +++ /dev/null @@ -1,45 +0,0 @@ -// Package hasflag checks if `os.Args` has a specific flag. Correctly stops looking -// after an -- argument terminator. -// -// Ported from https://github.com/sindresorhus/has-flag -// -package hasflag - -import ( - "os" - "strings" -) - -func argIndexOf(argv []string, str string) int { - result := -1 - for index, arg := range argv { - if arg == str { - result = index - break - } - } - - return result -} - -// HasFlag checks to see if the given flag was supplied on the command line. -// -func HasFlag(flag string) bool { - return hasFlag(flag, os.Args[1:]) -} - -func hasFlag(flag string, argv []string) bool { - var prefix string - - if strings.HasPrefix(flag, "-") { - prefix = "" - } else if len(flag) == 1 { - prefix = "-" - } else { - prefix = "--" - } - - position := argIndexOf(argv, prefix+flag) - terminatorPosition := argIndexOf(argv, "--") - return position != -1 && (terminatorPosition == -1 || position < terminatorPosition) -} diff --git a/vendor/github.com/jwalton/go-supportscolor/supportscolor.go b/vendor/github.com/jwalton/go-supportscolor/supportscolor.go deleted file mode 100644 index f2c71268..00000000 --- a/vendor/github.com/jwalton/go-supportscolor/supportscolor.go +++ /dev/null @@ -1,362 +0,0 @@ -// Package supportscolor detects whether a terminal supports color, and enables ANSI color support in recent Windows 10 builds. -// -// This is a port of the Node.js package supports-color (https://github.com/chalk/supports-color) by -// Sindre Sorhus and Josh Junon. -// -// Returns a `supportscolor.Support` with a `Stdout()` and `Stderr()` function for -// testing either stream. Note that on recent Windows 10 machines, these -// functions will also set the `ENABLE_VIRTUAL_TERMINAL_PROCESSING` console mode -// if required, which will enable support for normal ANSI escape codes on stdout -// and stderr. -// -// The `Stdout()`/`Stderr()` objects specify a level of support for color through -// a `.Level` property and a corresponding flag: -// -// - `.Level = None` and `.SupportsColor = false`: No color support -// - `.Level = Basic` and `.SupportsColor = true`: Basic color support (16 colors) -// - `.Level = Ansi256` and `.Has256 = true`: 256 color support -// - `.Level = Ansi16m` and `.Has16m = true`: True color support (16 million colors) -// -// Additionally, `supportscolor` exposes the `.SupportsColor()` function that -// takes an arbitrary file descriptor (e.g. `os.Stdout.Fd()`) and options, and will -// (re-)evaluate color support for an arbitrary stream. -// -// For example, `supportscolor.Stdout()` is the equivalent of `supportscolor.SupportsColor(os.Stdout.Fd())`. -// -// Available options are: -// -// `supportscolor.IsTTYOption(isTTY bool)` - Force whether the given file -// should be considered a TTY or not. If this not specified, TTY status will -// be detected automatically via `term.IsTerminal()`. -// -// `supportscolor.SniffFlagsOption(sniffFlags bool)` - By default it is `true`, -// which instructs `SupportsColor()` to sniff `os.Args` for the multitude of -// `--color` flags (see Info section in README.md). If `false`, then `os.Args` -// is not considered when determining color support. -// -package supportscolor - -import ( - "os" - "regexp" - "strconv" - "strings" -) - -// Support represents the color support available. -// -// Level will be the supported ColorLevel. SupportsColor will be true if the -// terminal supports basic 16 color ANSI color escape codes. Has256 will be -// true if the terminal supports ANSI 256 color, and Has16m will be true if the -// terminal supports true color. -// -type Support struct { - Level ColorLevel - SupportsColor bool - Has256 bool - Has16m bool -} - -func checkForceColorFlags(env environment) *ColorLevel { - var flagForceColor ColorLevel = None - var flagForceColorPreset bool = false - // TODO: It would be very nice if `HasFlag` supported `--color false`. - if env.HasFlag("no-color") || - env.HasFlag("no-colors") || - env.HasFlag("color=false") || - env.HasFlag("color=never") { - flagForceColor = None - flagForceColorPreset = true - } else if env.HasFlag("color") || - env.HasFlag("colors") || - env.HasFlag("color=true") || - env.HasFlag("color=always") { - flagForceColor = Basic - flagForceColorPreset = true - } - - if flagForceColorPreset { - return &flagForceColor - } - return nil -} - -func checkForceColorEnv(env environment) *ColorLevel { - forceColor, present := env.LookupEnv("FORCE_COLOR") - if present { - if forceColor == "true" || forceColor == "" { - result := Basic - return &result - } - - if forceColor == "false" { - result := None - return &result - } - - forceColorInt, err := strconv.ParseInt(forceColor, 10, 8) - if err == nil { - var result ColorLevel - if forceColorInt <= 0 { - result = None - } else if forceColorInt >= 3 { - result = Ansi16m - } else { - result = ColorLevel(forceColorInt) - } - return &result - } - } - - if _, isNoColor := env.LookupEnv("NO_COLOR"); isNoColor { - result := None - return &result - } - - return nil -} - -func translateLevel(level ColorLevel) Support { - return Support{ - Level: level, - SupportsColor: level >= 1, - Has256: level >= 2, - Has16m: level >= 3, - } -} - -func supportsColor(config *configuration) ColorLevel { - env := config.env - - // TODO: We don't have to call `checkForceColorFlags` multiple times, - // as it's not common practice to modify `os.Args`. We can call it once - // and cache the result, in say `init()`. - flagForceColor := checkForceColorFlags(env) - noFlagForceColor := checkForceColorEnv(env) - - // Env preferences should override flags - if noFlagForceColor != nil { - flagForceColor = noFlagForceColor - } - - var forceColor *ColorLevel - if config.sniffFlags { - forceColor = flagForceColor - } else { - forceColor = noFlagForceColor - } - - if forceColor != nil && *forceColor == None { - return None - } - - if config.sniffFlags { - if env.HasFlag("color=16m") || - env.HasFlag("color=full") || - env.HasFlag("color=truecolor") { - env.osEnableColor() - return Ansi16m - } - - if env.HasFlag("color=256") { - env.osEnableColor() - return Ansi256 - } - } - - if !config.isTTY && forceColor == nil { - return None - } - - min := None - if forceColor != nil { - min = *forceColor - } - - term := env.Getenv("TERM") - if term == "dumb" { - return min - } - - osColorEnabled := env.osEnableColor() - if (!osColorEnabled) && forceColor == nil { - return None - } - - if env.getGOOS() == "windows" { - // If we couldn't get windows to enable color, return basic. - if !osColorEnabled { - return None - } - - // Windows 10 build 10586 is the first Windows release that supports 256 colors. - // Windows 10 build 14931 is the first release that supports 16m/True color. - major, minor, build := env.getWindowsVersion() - if (major == 10 && minor >= 1) || major > 10 { - // Optimistically hope that future versions of windows won't backslide. - return Ansi16m - } else if major >= 10 && build >= 14931 { - return Ansi16m - } else if major >= 10 && build >= 10586 { - return Ansi256 - } - - // We should be able to return Basic here - if the terminal doesn't support - // basic ANSI escape codes, we should have gotten false from `osEnableColor()` - // because we should have gotten an error when we tried to set - // ENABLE_VIRTUAL_TERMINAL_PROCESSING. - // TODO: Make sure this is really true on an old version of Windows. - return Basic - } - - if _, ci := env.LookupEnv("CI"); ci { - var ciEnvNames = []string{"TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE", "DRONE"} - for _, ciEnvName := range ciEnvNames { - _, exists := env.LookupEnv(ciEnvName) - if exists { - return Basic - } - } - - if env.Getenv("CI_NAME") == "codeship" { - return Basic - } - - return min - } - - if teamCityVersion, isTeamCity := env.LookupEnv("TEAMCITY_VERSION"); isTeamCity { - versionRegex := regexp.MustCompile(`^(9\.(0*[1-9]\d*)\.|\d{2,}\.)`) - if versionRegex.MatchString(teamCityVersion) { - return Basic - } - return None - } - - if env.Getenv("COLORTERM") == "truecolor" { - return Ansi16m - } - - termProgram, termProgramPreset := env.LookupEnv("TERM_PROGRAM") - if termProgramPreset { - switch termProgram { - case "iTerm.app": - termProgramVersion := strings.Split(env.Getenv("TERM_PROGRAM_VERSION"), ".") - version, err := strconv.ParseInt(termProgramVersion[0], 10, 64) - if err == nil && version >= 3 { - return Ansi16m - } - return Ansi256 - case "Apple_Terminal": - return Ansi256 - - default: - // No default - } - } - - var term256Regex = regexp.MustCompile("(?i)-256(color)?$") - if term256Regex.MatchString(term) { - return Ansi256 - } - - var termBasicRegex = regexp.MustCompile("(?i)^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux") - - if termBasicRegex.MatchString(term) { - return Basic - } - - if _, colorTerm := env.LookupEnv("COLORTERM"); colorTerm { - return Basic - } - - return min -} - -type configuration struct { - isTTY bool - forceIsTTY bool - sniffFlags bool - env environment -} - -// Option is the type for an option which can be passed to SupportsColor(). -type Option func(*configuration) - -// IsTTYOption is an option which can be passed to `SupportsColor` to force -// whether the given file should be considered a TTY or not. If this not -// specified, TTY status will be detected automatically via `term.IsTerminal()`. -func IsTTYOption(isTTY bool) Option { - return func(config *configuration) { - config.forceIsTTY = true - config.isTTY = isTTY - } -} - -func setEnvironment(env environment) Option { - return func(config *configuration) { - config.env = env - } -} - -// SniffFlagsOption can be passed to SupportsColor to enable or disable checking -// command line flags to force supporting color. If set true (the default), then -// the following flags will disable color support: -// -// --no-color -// --no-colors -// --color=false -// --color=never -// -// And the following will force color support -// -// --colors -// --color=true -// --color=always -// --color=256 // Ansi 256 color mode -// --color=16m // 16.7 million color support -// --color=full // 16.7 million color support -// --color=truecolor // 16.7 million color support -// -func SniffFlagsOption(sniffFlags bool) Option { - return func(config *configuration) { - config.sniffFlags = sniffFlags - } -} - -// SupportsColor returns color support information for the given file handle. -func SupportsColor(fd uintptr, options ...Option) Support { - config := configuration{sniffFlags: true, env: &defaultEnvironment} - for _, opt := range options { - opt(&config) - } - - if !config.forceIsTTY { - config.isTTY = config.env.IsTerminal(int(fd)) - } - - level := supportsColor(&config) - return translateLevel(level) -} - -var stdout *Support - -// Stdout returns color support information for os.Stdout. -func Stdout() Support { - if stdout == nil { - result := SupportsColor(os.Stdout.Fd()) - stdout = &result - } - return *stdout -} - -var stderr *Support - -// Stderr returns color support information for os.Stderr. -func Stderr() Support { - if stderr == nil { - result := SupportsColor(os.Stderr.Fd()) - stderr = &result - } - return *stderr -} diff --git a/vendor/github.com/savioxavier/termlink/README.md b/vendor/github.com/savioxavier/termlink/README.md index 727b0d51..6f5f0a2b 100644 --- a/vendor/github.com/savioxavier/termlink/README.md +++ b/vendor/github.com/savioxavier/termlink/README.md @@ -4,11 +4,16 @@ > Clickable links in the terminal for Go +[![Release](https://img.shields.io/github/release/savioxavier/termlink.svg)](https://github.com/savioxavier/termlink/releases/latest) +[![Go Reference](https://pkg.go.dev/badge/github.com/savioxavier/termlink.svg)](https://pkg.go.dev/github.com/savioxavier/termlink) +[![License](https://img.shields.io/github/license/savioxavier/termlink)](/LICENSE) +[![Go Report Card](https://goreportcard.com/badge/github.com/savioxavier/termlink)](https://goreportcard.com/report/github.com/savioxavier/termlink) + ![termlink_demo_nyoom](https://user-images.githubusercontent.com/38729705/163217599-6fecf944-c10e-4546-9669-1c7d047da55e.gif) * **Termlink is a Go package that allows you to create fully customizable clickable links in the terminal. It is the Go version of Sindre Sorhus' popular [terminal-link](https://github.com/sindresorhus/terminal-link/) library.** -**It includes multiple features including dynamic and fully customizable colored links in terminal.** +**It includes multiple features including dynamic and fully customizable colored links in terminal, along with smart hyperlink support detection.** ## 🛠️ Install @@ -50,7 +55,22 @@ func main() { } ``` -- You can also use this package in combination with another popular Go package [fatih/color](https://github.com/fatih/color) +- Check if your current terminal supports hyperlinks: + +```go +import ( + "fmt" + + "github.com/savioxavier/termlink" +) + +func main() { + fmt.Println(termlink.SupportsHyperlinks()) + // prints either true or false, depending on your terminal +} +``` + +- Since `termlink.Link` returns a string, you can use it with your favorite text color formatting libraries such as [fatih/color](https://github.com/fatih/color), [mgutz/ansi](https://github.com/mgutz/ansi), etc. Alternatively, you can use `termlink.ColorLink` as well. ```go import ( @@ -62,11 +82,12 @@ import ( func main() { // With fatih/color package - color.Cyan(termlink.Link("Example link using the colors package", "https://example.com")) + color.Cyan(termlink.Link("Example link using the fatih/color package", "https://example.com")) } ``` -> #### Note: For unsupported terminals, the link will be printed in parentheses after the text (see below image) +> **Note** +> **For unsupported terminals, the link will be printed in parentheses after the text (see below image)** > > ![image](https://user-images.githubusercontent.com/38729705/163216009-abb81d39-aff0-4fb5-8c5f-da36e241b395.png) @@ -76,6 +97,15 @@ func main() { More examples can be found in the [`examples/`](examples/) directory. +For a quick demo, execute the following commands in your terminal: + +```bash +git clone https://github.com/savioxavier/termlink.git +cd termlink/ +go get github.com/savioxavier/termlink +go run examples/start.go +``` + --- ## 🔮 Features @@ -96,6 +126,15 @@ More examples can be found in the [`examples/`](examples/) directory. - With formatting: `green bold`, `red bgGreen italic`, `italic blue bgGreen`, etc. - The `shouldForce` is an optional boolean parameter which allows you to force the above unsupported terminal hyperlinks format `text (url)` to be printed, even in supported terminals +> `shouldForce` can be used in the following manner: +> +> ```go +> termlink.Link(text, url, true) +> termlink.ColorLink(text, url, color, true) +> ``` +> +> You don't always need to specify this argument. By default, this parameter is `false` + - **`termlink.SupportsHyperlinks()`**: - Returns `true` if the terminal supports hyperlinks, `false` otherwise. @@ -104,7 +143,7 @@ More examples can be found in the [`examples/`](examples/) directory. ## 🧪 Tests -You can run unit tests _locally_ by running the following command +You can run unit tests _locally_ by running the following command: ```bash go test -v @@ -131,6 +170,6 @@ You can support further development of this project by **giving it a 🌟** and ## 💫 Attributions and special thanks - [terminal-link](https://github.com/sindresorhus/terminal-link) - Sindre Sorhus' original package for providing inspiration for this package. -- [go-supportscolor](https://github.com/jwalton/go-supportscolor) - A package for detecting terminal color support. +- [supports-hyperlinks](https://github.com/zkat/supports-hyperlinks) - Zkat's package for additional hyperlink handling support. * The paperclip icon shown in the demo at the top of this README isn't included when you create the link, it's purely for decorative purposes only. diff --git a/vendor/github.com/savioxavier/termlink/termlink.go b/vendor/github.com/savioxavier/termlink/termlink.go index e59a3a8a..88833a8d 100644 --- a/vendor/github.com/savioxavier/termlink/termlink.go +++ b/vendor/github.com/savioxavier/termlink/termlink.go @@ -5,79 +5,171 @@ import ( "fmt" "os" "strings" - - "github.com/jwalton/go-supportscolor" ) -func parseVersion(version string) (int, int, int) { +// EnvironmentVariables represent the set of standalone environment variables +// ie, those which do not require any special handling or version checking +var EnvironmentVariables = []string{ + "DOMTERM", + "WT_SESSION", + "KONSOLE_VERSION", +} + +// Version struct represents a semver version (usually, with some exceptions) +// with major, minor, and patch segments +type Version struct { + major int + minor int + patch int +} + +// parseVersion takes a string "version" number and returns +// a Version struct with the major, minor, and patch +// segments parsed from the string. +// If a version number is not provided +func parseVersion(version string) Version { var major, minor, patch int fmt.Sscanf(version, "%d.%d.%d", &major, &minor, &patch) - return major, minor, patch + return Version{ + major: major, + minor: minor, + patch: patch, + } +} + +// hasEnvironmentVariables returns true if the environment variable "name" +// is present in the environment, false otherwise +func hasEnv(name string) bool { + _, envExists := os.LookupEnv(name) + + return envExists +} + +// checkAllEnvs returns true if any of the environment variables in the "vars" +// string slice are actually present in the environment, false otherwise +func checkAllEnvs(vars []string) bool { + for _, v := range vars { + if hasEnv(v) { + return true + } + } + + return false +} + +// getEnv returns the value of the environment variable, if it exists +func getEnv(name string) string { + envValue, _ := os.LookupEnv(name) + + return envValue +} + +// matchesEnv returns true if the environment variable "name" matches any +// of the given values in the "values" string slice, false otherwise +func matchesEnv(name string, values []string) bool { + if hasEnv(name) { + for _, value := range values { + if getEnv(name) == value { + return true + } + } + } + return false } func supportsHyperlinks() bool { - if os.Getenv("FORCE_HYPERLINK") != "" { + // Allow hyperlinks to be forced, independent of any environment variables + // Instead of checking whether it is equal to anything other than "0", + // a set of allowed values are provided, as something like + // FORCE_HYPERLINK="do-not-enable-it" wouldn't make sense if it returned true + if matchesEnv("FORCE_HYPERLINK", []string{"1", "true", "always", "enabled"}) { return true } - if os.Getenv("DOMTERM") != "" { - // DomTerm - return true + // VTE-based terminals (Gnome Terminal, Guake, ROXTerm, etc) + // VTE_VERSION is rendered as four-digit version string + // eg: 0.52.2 => 5202 + // parseVersion will parse it with a standalone major segment + // with minor and patch segments set to 0 + // 0.50.0 (parsed as 5000) was supposed to support hyperlinks, but throws a segfault + // so we check if the "major" version is greater than 5000 (5000 exclusive) + if hasEnv("VTE_VERSION") { + v := parseVersion(getEnv("VTE_VERSION")) + return v.major > 5000 } - if os.Getenv("VTE_VERSION") != "" { - // VTE-based terminals above v0.50 (Gnome Terminal, Guake, ROXTerm, etc) - major, minor, patch := parseVersion(os.Getenv("VTE_VERSION")) - if major >= 5000 && minor >= 50 && patch >= 50 { - return true + // Terminals which have a TERM_PROGRAM variable set + // This is the most versatile environment variable as it also provides another + // variable called TERM_PROGRAM_VERSION, which helps us to determine + // the exact version of the program, and allow for stricter variable checks + if hasEnv("TERM_PROGRAM") { + v := parseVersion(getEnv("TERM_PROGRAM_VERSION")) + + switch term := getEnv("TERM_PROGRAM"); term { + case "iTerm.app": + if v.major == 3 { + return v.minor >= 1 + } + return v.major > 3 + case "WezTerm": + // Even though WezTerm's version is something like 20200620-160318-e00b076c + // parseVersion will still parse it with a standalone major segment (ie: 20200620) + // with minor and patch segments set to 0 + return v.major >= 20200620 + case "vscode": + return v.major > 1 || (v.major == 1 && v.minor >= 72) + + // Hyper Terminal used to be included in this list, and it even supports hyperlinks + // but the hyperlinks are pseudo-hyperlinks and are actually not clickable } } - if os.Getenv("TERM_PROGRAM") != "" { - if os.Getenv("TERM_PROGRAM") == "Hyper" || - os.Getenv("TERM_PROGRAM") == "iTerm.app" || - os.Getenv("TERM_PROGRAM") == "terminology" || - os.Getenv("TERM_PROGRAM") == "WezTerm" { - return true - } + // Terminals which have a TERM variable set + if matchesEnv("TERM", []string{"xterm-kitty", "alacritty", "alacritty-direct"}) { + return true } - if os.Getenv("TERM") != "" { - // Kitty - if os.Getenv("TERM") == "xterm-kitty" { - return true - } + // Terminals which have a COLORTERM variable set + if matchesEnv("COLORTERM", []string{"xfce4-terminal"}) { + return true } - // Windows Terminal and Konsole - if os.Getenv("WT_SESSION") != "" || os.Getenv("KONSOLE_VERSION") != "" { + // Match standalone environment variables + // ie, those which do not require any special handling + // or version checking + if checkAllEnvs(EnvironmentVariables) { return true } return false } -var colorsList = map[string]string{ - "black": "30", - "red": "31", - "green": "32", - "yellow": "33", - "blue": "34", - "magenta": "35", - "cyan": "36", - "white": "37", - "bold": "1", - "italic": "3", - "bgBlack": "40", - "bgRed": "41", - "bgGreen": "42", - "bgYellow": "43", - "bgBlue": "44", - "bgMagenta": "45", - "bgCyan": "46", - "bgWhite": "47", +var colorsList = map[string]int{ + "reset": 0, + "bold": 1, + "dim": 2, + "italic": 3, + "underline": 4, + "blink": 5, + "black": 30, + "red": 31, + "green": 32, + "yellow": 33, + "blue": 34, + "magenta": 35, + "cyan": 36, + "white": 37, + "bgBlack": 40, + "bgRed": 41, + "bgGreen": 42, + "bgYellow": 43, + "bgBlue": 44, + "bgMagenta": 45, + "bgCyan": 46, + "bgWhite": 47, } +// isInList returns true if a given value is present in a string slice, false otherwise func isInList(list []string, value string) bool { for _, v := range list { if v == value { @@ -87,84 +179,95 @@ func isInList(list []string, value string) bool { return false } -func parseColor(color string) string { - acceptedForegroundColors := []string{"black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"} +var colors []string - acceptedBackgroundColors := []string{"bgBlack", "bgRed", "bgGreen", "bgYellow", "bgBlue", "bgMagenta", "bgCyan", "bgWhite"} +// addColor adds a color to be later used while parsing the color string +func addColor(value string) []string { + colors = append(colors, fmt.Sprint(colorsList[value])) + + return colors +} + +// clearSlice clears a string slice by re-slicing it to have a length of 0 +func clearSlice(slice []string) []string { + slice = slice[:0] + return slice +} + +// isValidColor checks if a given color string is a valid key in a map of predefined colors +func isValidColor(color string) bool { + // Create a slice with keys of the colorsList map + keys := make([]string, len(colorsList)) + + i := 0 + for k := range colorsList { + keys[i] = k + i++ + } + + // Check if the color is in the keys slice + return isInList(keys, color) +} +// parseColor yields a set of ANSI color codes, based on the "color" string. +// The color codes are parsed from the colorsList map +func parseColor(color string) string { + // Clear the colors slice first + colors = clearSlice(colors) + + // If nothing is provided, return empty string if color == "" { return "" } - var colors []string - for _, c := range strings.Split(color, " ") { - if c == "" { + colorNames := strings.Split(color, " ") + + for _, c := range colorNames { + // If the color doesn't exist, skip and go to the next word + if !isValidColor(c) { continue } - if c == "bold" { - colors = append(colors, colorsList["bold"]) - } else if c == "italic" { - colors = append(colors, colorsList["italic"]) - } else if c == "underline" { - colors = append(colors, colorsList["underline"]) - } else if c == "blink" { - colors = append(colors, colorsList["blink"]) - } else if c == "reverse" { - colors = append(colors, colorsList["reverse"]) - } else if c == "hidden" { - colors = append(colors, colorsList["hidden"]) - } else if c == "strike" { - colors = append(colors, colorsList["strike"]) - } else if isInList(acceptedForegroundColors, c) { - colors = append(colors, colorsList[c]) - } else if isInList(acceptedBackgroundColors, c) { - colors = append(colors, colorsList[c]) - } else if c == "reset" { - colors = append(colors, colorsList["reset"]) - } else { - return "" - } - } - if len(colors) == 0 { - return "" + // Add the color, if present in colorsList + addColor(c) + } return "\u001b[" + strings.Join(colors, ";") + "m" } -func supportsColor() bool { - return supportscolor.Stdout().SupportsColor -} - -// Function Link creates a clickable link in the terminal's stdout. +// Link returns a clickable link, which can be used in the terminal // // The function takes two required parameters: text and url // and one optional parameter: shouldForce // // The text parameter is the text to be displayed. // The url parameter is the URL to be opened when the link is clicked. -// The shouldForce parameter indicates whether to force the non-hyperlink supported behavior (i.e., text (url)) +// The shouldForce is an optional parameter indicates whether to force the non-hyperlink supported behavior (i.e., text (url)) // // The function returns the clickable link. func Link(text string, url string, shouldForce ...bool) string { + + // Default shouldForce to false shouldForceDefault := false if len(shouldForce) > 0 { + // If a value for shouldForce is provided, set it to that instead + // Since shouldForce is a slice, we only consider its first element shouldForceDefault = shouldForce[0] } if shouldForceDefault { - return text + " (" + url + ")" + parseColor("reset") + return text + " (" + url + ")" + "\u001b[0m" } else { if supportsHyperlinks() { - return "\x1b]8;;" + url + "\x07" + text + "\x1b]8;;\x07" + parseColor("reset") + return "\x1b]8;;" + url + "\x07" + text + "\x1b]8;;\x07" + "\u001b[0m" } - return text + " (" + url + ")" + parseColor("reset") + return text + " (" + url + ")" + "\u001b[0m" } } -// Function LinkColor creates a colored clickable link in the terminal's stdout. +// ColorLink returns a colored clickable link, which can be used in the terminal // // The function takes three required parameters: text, url and color // and one optional parameter: shouldForce @@ -172,35 +275,33 @@ func Link(text string, url string, shouldForce ...bool) string { // The text parameter is the text to be displayed. // The url parameter is the URL to be opened when the link is clicked. // The color parameter is the color of the link. -// The shouldForce parameter indicates whether to force the non-hyperlink supported behavior (i.e., text (url)) +// The shouldForce is an optional parameter indicates whether to force the non-hyperlink supported behavior (i.e., text (url)) // // The function returns the clickable link. func ColorLink(text string, url string, color string, shouldForce ...bool) string { - var textColor string - - if supportsColor() { - textColor = parseColor(color) - } else { - textColor = "" - } + textColor := parseColor(color) + // Default shouldForce to false shouldForceDefault := false if len(shouldForce) > 0 { + // If a value for shouldForce is provided, set it to that instead + // Since shouldForce is a slice, we only consider its first element shouldForceDefault = shouldForce[0] } if shouldForceDefault { - return textColor + text + " (" + url + ")" + parseColor("reset") + return textColor + text + " (" + url + ")" + "\u001b[0m" } else { if supportsHyperlinks() { - return "\x1b]8;;" + url + "\x07" + textColor + text + "\x1b]8;;\x07" + parseColor("reset") + return "\x1b]8;;" + url + "\x07" + textColor + text + "\x1b]8;;\x07" + "\u001b[0m" } - return textColor + text + " (" + url + ")" + parseColor("reset") + return textColor + text + " (" + url + ")" + "\u001b[0m" } + } -// Function SupportsHyperlinks returns true if the terminal supports hyperlinks. +// SupportsHyperlinks returns true if the terminal supports hyperlinks. // // The function returns true if the terminal supports hyperlinks, false otherwise. func SupportsHyperlinks() bool { diff --git a/vendor/modules.txt b/vendor/modules.txt index 787d7167..7c56934a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -22,10 +22,6 @@ github.com/fatih/color # github.com/getsentry/raven-go v0.2.0 ## explicit github.com/getsentry/raven-go -# github.com/jwalton/go-supportscolor v1.1.0 -## explicit; go 1.15 -github.com/jwalton/go-supportscolor -github.com/jwalton/go-supportscolor/pkg/hasFlag # github.com/manifoldco/promptui v0.9.0 ## explicit; go 1.12 github.com/manifoldco/promptui @@ -57,7 +53,7 @@ github.com/pmezard/go-difflib/difflib # github.com/russross/blackfriday/v2 v2.1.0 ## explicit github.com/russross/blackfriday/v2 -# github.com/savioxavier/termlink v1.2.1 +# github.com/savioxavier/termlink v1.3.0 ## explicit; go 1.17 github.com/savioxavier/termlink # github.com/sirupsen/logrus v1.9.0