aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2017-05-07 23:05:20 +0200
committerStefan Majewsky <majewsky@gmx.net>2017-05-07 23:05:20 +0200
commit2f93c6ca308a15c5d3e280274bd698604276143c (patch)
tree65a4421a580100cf873b63fae30d5c8b294a205a /pkg
parent36b903423828b2e35c9c1fde3fdc898fe2ed23ca (diff)
downloadgofu-2f93c6ca308a15c5d3e280274bd698604276143c.tar.gz
YAGNI
Diffstat (limited to 'pkg')
-rw-r--r--pkg/cli/interface.go18
-rw-r--r--pkg/cli/query.go2
-rw-r--r--pkg/cli/ui.go107
3 files changed, 6 insertions, 121 deletions
diff --git a/pkg/cli/interface.go b/pkg/cli/interface.go
index 7ebde9d..3192d32 100644
--- a/pkg/cli/interface.go
+++ b/pkg/cli/interface.go
@@ -21,6 +21,7 @@ package cli
import (
"bufio"
"bytes"
+ "fmt"
"io"
"os"
"sort"
@@ -128,26 +129,17 @@ func (i *Interface) ShowResultsSorted(strs []string) {
//ShowProgress displays a progress message on stderr.
func (i *Interface) ShowProgress(str string) {
- i.stderr.Write(StyledText{
- Styled(">> ", AnsiNormal, AnsiBold, AnsiCyan),
- Styled(strings.TrimSpace(str)+"\n", AnsiCyan),
- }.DisplayString(true))
+ fmt.Fprintf(i.stderr, "\x1B[0;1;36m>>\x1B[0;36m %s\x1B[0m", strings.TrimSpace(str))
}
//ShowWarning displays a warning message on stderr.
func (i *Interface) ShowWarning(str string) {
- i.stderr.Write(StyledText{
- Styled("!! ", AnsiNormal, AnsiBold, AnsiYellow),
- Styled(strings.TrimSpace(str)+"\n", AnsiYellow),
- }.DisplayString(true))
+ fmt.Fprintf(i.stderr, "\x1B[0;1;33m!!\x1B[0;36m %s\x1B[0m", strings.TrimSpace(str))
}
//ShowError displays an error message on stderr.
-func (i *Interface) ShowError(err string) {
- i.stderr.Write(StyledText{
- Styled("!! ", AnsiNormal, AnsiBold, AnsiRed),
- Styled(strings.TrimSpace(err)+"\n", AnsiRed),
- }.DisplayString(true))
+func (i *Interface) ShowError(str string) {
+ fmt.Fprintf(i.stderr, "\x1B[0;1;31m!!\x1B[0;36m %s\x1B[0m", strings.TrimSpace(str))
}
//ShowUsage displays a usage synopsis on stderr.
diff --git a/pkg/cli/query.go b/pkg/cli/query.go
index 1f5d16c..2a6a5bc 100644
--- a/pkg/cli/query.go
+++ b/pkg/cli/query.go
@@ -170,7 +170,7 @@ func displayChoices(out io.Writer, choices []Choice, selectedIndex int) {
}
if idx == selectedIndex {
- out.Write(Styled(text, AnsiInverse).DisplayString(true))
+ fmt.Fprintf(out, "\x1B[0;7m%s\x1B[0m", text)
} else {
out.Write([]byte(text))
}
diff --git a/pkg/cli/ui.go b/pkg/cli/ui.go
deleted file mode 100644
index 60ae553..0000000
--- a/pkg/cli/ui.go
+++ /dev/null
@@ -1,107 +0,0 @@
-/*******************************************************************************
-*
-* Copyright 2017 Stefan Majewsky <majewsky@gmx.net>
-*
-* This program is free software: you can redistribute it and/or modify it under
-* the terms of the GNU General Public License as published by the Free Software
-* Foundation, either version 3 of the License, or (at your option) any later
-* version.
-*
-* This program is distributed in the hope that it will be useful, but WITHOUT ANY
-* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License along with
-* this program. If not, see <http://www.gnu.org/licenses/>.
-*
-*******************************************************************************/
-
-package cli
-
-import (
- "bytes"
- "strings"
-)
-
-//AnsiStyle offers a set of styles for the VT100 SGR (Select Graphic Recognition) command.
-type AnsiStyle string
-
-const (
- //AnsiNormal reverts all styles to default.
- AnsiNormal AnsiStyle = "0"
- //AnsiBold makes the text bold.
- AnsiBold AnsiStyle = "1"
- //AnsiInverse swaps foreground and background color.
- AnsiInverse AnsiStyle = "7"
- //AnsiBlack is a foreground color.
- AnsiBlack AnsiStyle = "30"
- //AnsiRed is a foreground color.
- AnsiRed AnsiStyle = "31"
- //AnsiGreen is a foreground color.
- AnsiGreen AnsiStyle = "32"
- //AnsiYellow is a foreground color.
- AnsiYellow AnsiStyle = "33"
- //AnsiBlue is a foreground color.
- AnsiBlue AnsiStyle = "34"
- //AnsiMagenta is a foreground color.
- AnsiMagenta AnsiStyle = "35"
- //AnsiCyan is a foreground color.
- AnsiCyan AnsiStyle = "36"
- //AnsiWhite is a foreground color.
- AnsiWhite AnsiStyle = "37"
- //AnsiOnBlack is a background color.
- AnsiOnBlack AnsiStyle = "40"
- //AnsiOnRed is a background color.
- AnsiOnRed AnsiStyle = "41"
- //AnsiOnGreen is a background color.
- AnsiOnGreen AnsiStyle = "42"
- //AnsiOnYellow is a background color.
- AnsiOnYellow AnsiStyle = "43"
- //AnsiOnBlue is a background color.
- AnsiOnBlue AnsiStyle = "44"
- //AnsiOnMagenta is a background color.
- AnsiOnMagenta AnsiStyle = "45"
- //AnsiOnCyan is a background color.
- AnsiOnCyan AnsiStyle = "46"
- //AnsiOnWhite is a background color.
- AnsiOnWhite AnsiStyle = "47"
-)
-
-//StyledString is a string with attached style information for displaying on a terminal.
-type StyledString struct {
- Text string
- Styles []AnsiStyle
-}
-
-//Styled is syntactic sugar for a StyledString instance.
-func Styled(text string, styles ...AnsiStyle) StyledString {
- return StyledString{text, styles}
-}
-
-//DisplayString returns the string for writing on a terminal emulator.
-func (s StyledString) DisplayString(withReset bool) []byte {
- strs := make([]string, len(s.Styles))
- for idx, s := range s.Styles {
- strs[idx] = string(s)
- }
- str := "\x1B[" + strings.Join(strs, ";") + "m" + s.Text
- if withReset {
- str += "\x1B[0m"
- }
- return []byte(str)
-}
-
-//StyledText is a sequence of styled strings.
-type StyledText []StyledString
-
-//DisplayString returns the string for writing on a terminal emulator.
-func (t StyledText) DisplayString(withReset bool) []byte {
- var buf bytes.Buffer
- for _, s := range t {
- buf.Write(s.DisplayString(false))
- }
- if withReset {
- buf.Write([]byte("\x1B[0m"))
- }
- return buf.Bytes()
-}