summaryrefslogtreecommitdiff
path: root/vendor/github.com/morikuni/aec/ansi.go
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin@redhat.com>2019-10-24 10:37:22 -0400
committerNalin Dahyabhai <nalin@redhat.com>2019-10-29 13:35:18 -0400
commita4a70b4506ec4abb8b3bbc3873ee5ca015a8ed08 (patch)
tree4e7a50576d4db83450c58054e276f33bbd2cdb3a /vendor/github.com/morikuni/aec/ansi.go
parent59582c55b798f0a2d086981ca9a8ddd8314fd0c2 (diff)
downloadpodman-a4a70b4506ec4abb8b3bbc3873ee5ca015a8ed08.tar.gz
podman-a4a70b4506ec4abb8b3bbc3873ee5ca015a8ed08.tar.bz2
podman-a4a70b4506ec4abb8b3bbc3873ee5ca015a8ed08.zip
bump containers/image to v5.0.0, buildah to v1.11.4
Move to containers/image v5 and containers/buildah to v1.11.4. Replace an equality check with a type assertion when checking for a docker.ErrUnauthorizedForCredentials in `podman login`. Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
Diffstat (limited to 'vendor/github.com/morikuni/aec/ansi.go')
-rw-r--r--vendor/github.com/morikuni/aec/ansi.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/vendor/github.com/morikuni/aec/ansi.go b/vendor/github.com/morikuni/aec/ansi.go
new file mode 100644
index 000000000..e60722e6e
--- /dev/null
+++ b/vendor/github.com/morikuni/aec/ansi.go
@@ -0,0 +1,59 @@
+package aec
+
+import (
+ "fmt"
+ "strings"
+)
+
+const esc = "\x1b["
+
+// Reset resets SGR effect.
+const Reset string = "\x1b[0m"
+
+var empty = newAnsi("")
+
+// ANSI represents ANSI escape code.
+type ANSI interface {
+ fmt.Stringer
+
+ // With adapts given ANSIs.
+ With(...ANSI) ANSI
+
+ // Apply wraps given string in ANSI.
+ Apply(string) string
+}
+
+type ansiImpl string
+
+func newAnsi(s string) *ansiImpl {
+ r := ansiImpl(s)
+ return &r
+}
+
+func (a *ansiImpl) With(ansi ...ANSI) ANSI {
+ return concat(append([]ANSI{a}, ansi...))
+}
+
+func (a *ansiImpl) Apply(s string) string {
+ return a.String() + s + Reset
+}
+
+func (a *ansiImpl) String() string {
+ return string(*a)
+}
+
+// Apply wraps given string in ANSIs.
+func Apply(s string, ansi ...ANSI) string {
+ if len(ansi) == 0 {
+ return s
+ }
+ return concat(ansi).Apply(s)
+}
+
+func concat(ansi []ANSI) ANSI {
+ strs := make([]string, 0, len(ansi))
+ for _, p := range ansi {
+ strs = append(strs, p.String())
+ }
+ return newAnsi(strings.Join(strs, ""))
+}