summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/dtail/main.go8
-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
6 files changed, 65 insertions, 19 deletions
diff --git a/cmd/dtail/main.go b/cmd/dtail/main.go
index 178ea52..869a536 100644
--- a/cmd/dtail/main.go
+++ b/cmd/dtail/main.go
@@ -11,6 +11,7 @@ import (
"time"
"github.com/mimecast/dtail/internal/clients"
+ "github.com/mimecast/dtail/internal/color"
"github.com/mimecast/dtail/internal/config"
"github.com/mimecast/dtail/internal/io/logger"
"github.com/mimecast/dtail/internal/io/signal"
@@ -25,6 +26,7 @@ func main() {
var cfgFile string
var checkHealth bool
var debugEnable bool
+ var displayColorTable bool
var displayVersion bool
var grep string
var noColor bool
@@ -35,13 +37,14 @@ func main() {
userName := user.Name()
+ flag.BoolVar(&args.Quiet, "quiet", false, "Quiet output mode")
flag.BoolVar(&args.RegexInvert, "invert", false, "Invert regex")
flag.BoolVar(&args.TrustAllHosts, "trustAllHosts", false, "Auto trust all unknown host keys")
flag.BoolVar(&checkHealth, "checkHealth", false, "Only check for server health")
flag.BoolVar(&debugEnable, "debug", false, "Activate debug messages")
+ flag.BoolVar(&displayColorTable, "colorTable", false, "Show color table")
flag.BoolVar(&displayVersion, "version", false, "Display version")
flag.BoolVar(&noColor, "noColor", false, "Disable ANSII terminal colors")
- flag.BoolVar(&args.Quiet, "quiet", false, "Quiet output mode")
flag.IntVar(&args.ConnectionsPerCPU, "cpc", 10, "How many connections established per CPU core concurrently")
flag.IntVar(&args.Timeout, "timeout", 0, "Max time dtail server will collect data until disconnection")
flag.IntVar(&pprof, "pprof", -1, "Start PProf server this port")
@@ -71,6 +74,9 @@ func main() {
if displayVersion {
version.PrintAndExit()
}
+ if displayColorTable {
+ color.TablePrintAndExit()
+ }
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
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),