summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2021-08-11 09:32:13 +0300
committerPaul Buetow <paul@buetow.org>2021-08-11 09:32:13 +0300
commit9bb96433be61d89f8e86f6f9ded8e35f74156a63 (patch)
treecdbcc63433955bcde584c232d3676a78b3c52ee5 /internal
parentf3e08046badcbc852a6875b5553ee0a648021552 (diff)
add colorTable option
Diffstat (limited to 'internal')
-rw-r--r--internal/color/color.go4
-rw-r--r--internal/color/color_test.go23
-rw-r--r--internal/color/table.go41
-rw-r--r--internal/config/client.go6
-rw-r--r--internal/version/version.go2
5 files changed, 58 insertions, 18 deletions
diff --git a/internal/color/color.go b/internal/color/color.go
index f444294..a2490be 100644
--- a/internal/color/color.go
+++ b/internal/color/color.go
@@ -156,6 +156,10 @@ func ToAttribute(s string) (Attribute, error) {
return AttrReverse, nil
case "hidden":
return AttrHidden, nil
+ case "none":
+ fallthrough
+ case "":
+ return AttrNone, nil
default:
return AttrReset, fmt.Errorf("unknown text attribute '" + s + "'")
}
diff --git a/internal/color/color_test.go b/internal/color/color_test.go
index 0024b7f..16b2f90 100644
--- a/internal/color/color_test.go
+++ b/internal/color/color_test.go
@@ -6,14 +6,10 @@ import (
)
func TestColors(t *testing.T) {
- colors := []string{
- "Black", "Red", "Green", "Yellow", "Blue", "Magenta", "Cyan", "White", "Default",
- }
-
text := " Mimecast "
builder := strings.Builder{}
- for _, color := range colors {
+ for _, color := range ColorNames {
fgColor, err := ToFgColor(color)
if err != nil {
t.Errorf("unable to paint foreground : %s\n%v", text, err)
@@ -27,10 +23,13 @@ func TestColors(t *testing.T) {
builder.WriteString(PaintBg(text, bgColor))
}
- for _, color := range colors {
- fgColor, _ := ToFgColor(color)
- for _, color := range colors {
- bgColor, _ := ToBgColor(color)
+ for _, fg := range ColorNames {
+ fgColor, _ := ToFgColor(fg)
+ for _, bg := range ColorNames {
+ if fg == bg {
+ continue
+ }
+ bgColor, _ := ToBgColor(bg)
builder.WriteString(Paint(text, fgColor, bgColor))
}
}
@@ -38,14 +37,10 @@ func TestColors(t *testing.T) {
t.Log(builder.String())
}
func TestAttributes(t *testing.T) {
- attributes := []string{
- "Bold", "Dim", "Italic", "Underline", "Blink", "SlowBlink", "RapidBlink", "Reverse", "hidden",
- }
-
text := " Mimecast "
builder := strings.Builder{}
- for _, attribute := range attributes {
+ for _, attribute := range AttributeNames {
att, err := ToAttribute(attribute)
if err != nil {
t.Errorf("unable to paint attribute: %s\n%v", text, err)
diff --git a/internal/color/table.go b/internal/color/table.go
new file mode 100644
index 0000000..8e40a78
--- /dev/null
+++ b/internal/color/table.go
@@ -0,0 +1,41 @@
+package color
+
+import (
+ "fmt"
+ "os"
+)
+
+var ColorNames = []string{
+ "Black", "Red", "Green", "Yellow", "Blue", "Magenta", "Cyan", "White", "Default",
+}
+
+var AttributeNames = []string{
+ "Bold", "Dim", "Italic", "Underline", "Blink", "SlowBlink", "RapidBlink", "Reverse", "Hidden", "None",
+}
+
+func TablePrintAndExit() {
+ for _, attr := range AttributeNames {
+ if attr == "Hidden" || attr == "SlowBlink" {
+ continue
+ }
+ printColorTable(attr)
+ }
+ os.Exit(0)
+}
+
+func printColorTable(attr string) {
+ for _, fg := range ColorNames {
+ fgColor, _ := ToFgColor(fg)
+ for _, bg := range ColorNames {
+ if fg == bg {
+ continue
+ }
+ bgColor, _ := ToBgColor(bg)
+ attribute, _ := ToAttribute(attr)
+
+ text := fmt.Sprintf(" Foreground:%10s | Background:%10s | Attribute:%10s ", fg, bg, attr)
+ fmt.Print(PaintWithAttr(text, fgColor, bgColor, attribute))
+ fmt.Print("\n")
+ }
+ }
+}
diff --git a/internal/config/client.go b/internal/config/client.go
index 84ad037..5386576 100644
--- a/internal/config/client.go
+++ b/internal/config/client.go
@@ -75,7 +75,7 @@ func newDefaultClientConfig() *ClientConfig {
RemoteDebugAttr: color.AttrNone,
RemoteDebugBg: color.BgGreen,
- RemoteDebugFg: color.FgWhite,
+ RemoteDebugFg: color.FgBlack,
RemoteErrorAttr: color.AttrBold,
RemoteErrorBg: color.BgRed,
@@ -83,11 +83,11 @@ func newDefaultClientConfig() *ClientConfig {
RemoteFatalAttr: color.AttrBlink,
RemoteFatalBg: color.BgRed,
- RemoteFatalFg: color.FgBlue,
+ RemoteFatalFg: color.FgWhite,
RemoteStatsOkAttr: color.AttrNone,
RemoteStatsOkBg: color.BgGreen,
- RemoteStatsOkFg: color.FgWhite,
+ RemoteStatsOkFg: color.FgBlack,
RemoteStatsWarnAttr: color.AttrNone,
RemoteStatsWarnBg: color.BgRed,
diff --git a/internal/version/version.go b/internal/version/version.go
index a513fdc..7cfe12c 100644
--- a/internal/version/version.go
+++ b/internal/version/version.go
@@ -30,7 +30,7 @@ func PaintedString() string {
return String()
}
- name := color.PaintWithAttr(Name,
+ name := color.PaintWithAttr(fmt.Sprintf(" %s ", Name),
color.FgYellow, color.BgBlue, color.AttrBold)
version := color.PaintWithAttr(fmt.Sprintf(" %s ", Version),