diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-11-13 18:28:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-13 18:28:17 +0100 |
commit | 738d62ea960af439bd545820e1853cbd73464493 (patch) | |
tree | 61a859c039565897f865db052ad7c3bee8b03bfb /vendor/github.com/juju/ansiterm/writer.go | |
parent | 2993e97dec9d998d2eca7c5aee918b1429596a85 (diff) | |
parent | 8e4a42aa429c6dec0d5face7c69554d8a0677e96 (diff) | |
download | podman-738d62ea960af439bd545820e1853cbd73464493.tar.gz podman-738d62ea960af439bd545820e1853cbd73464493.tar.bz2 podman-738d62ea960af439bd545820e1853cbd73464493.zip |
Merge pull request #7964 from vrothberg/shortnames
short-name aliasing
Diffstat (limited to 'vendor/github.com/juju/ansiterm/writer.go')
-rw-r--r-- | vendor/github.com/juju/ansiterm/writer.go | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/vendor/github.com/juju/ansiterm/writer.go b/vendor/github.com/juju/ansiterm/writer.go new file mode 100644 index 000000000..32437bb27 --- /dev/null +++ b/vendor/github.com/juju/ansiterm/writer.go @@ -0,0 +1,74 @@ +// Copyright 2016 Canonical Ltd. +// Licensed under the LGPLv3, see LICENCE file for details. + +package ansiterm + +import ( + "fmt" + "io" +) + +// Writer allows colors and styles to be specified. If the io.Writer +// is not a terminal capable of color, all attempts to set colors or +// styles are no-ops. +type Writer struct { + io.Writer + + noColor bool +} + +// NewWriter returns a Writer that allows the caller to specify colors and +// styles. If the io.Writer is not a terminal capable of color, all attempts +// to set colors or styles are no-ops. +func NewWriter(w io.Writer) *Writer { + writer, colorCapable := colorEnabledWriter(w) + return &Writer{ + Writer: writer, + noColor: !colorCapable, + } +} + +// SetColorCapable forces the writer to either write the ANSI escape color +// if capable is true, or to not write them if capable is false. +func (w *Writer) SetColorCapable(capable bool) { + w.noColor = !capable +} + +// SetForeground sets the foreground color. +func (w *Writer) SetForeground(c Color) { + w.writeSGR(c.foreground()) +} + +// SetBackground sets the background color. +func (w *Writer) SetBackground(c Color) { + w.writeSGR(c.background()) +} + +// SetStyle sets the text style. +func (w *Writer) SetStyle(s Style) { + w.writeSGR(s.enable()) +} + +// ClearStyle clears the text style. +func (w *Writer) ClearStyle(s Style) { + w.writeSGR(s.disable()) +} + +// Reset returns the default foreground and background colors with no styles. +func (w *Writer) Reset() { + w.writeSGR(reset) +} + +type sgr interface { + // sgr returns the combined escape sequence for the Select Graphic Rendition. + sgr() string +} + +// writeSGR takes the appropriate integer SGR parameters +// and writes out the ANIS escape code. +func (w *Writer) writeSGR(value sgr) { + if w.noColor { + return + } + fmt.Fprint(w, value.sgr()) +} |