summaryrefslogtreecommitdiff
path: root/internal/color
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2021-10-09 21:10:29 +0300
committerPaul Buetow <paul@buetow.org>2021-10-10 13:36:41 +0300
commit97747ea0f3178f7f5890512d483fdccaa82846b0 (patch)
tree9ff1335ca26afc90e55fd6de416457e252d75a35 /internal/color
parent7a7169791a64190e1002e38bc9c04ad0d5c1ce1f (diff)
vetting and linting and some code restyling
Diffstat (limited to 'internal/color')
-rw-r--r--internal/color/brush/brush.go8
-rw-r--r--internal/color/color.go11
-rw-r--r--internal/color/paint.go19
-rw-r--r--internal/color/table.go19
4 files changed, 40 insertions, 17 deletions
diff --git a/internal/color/brush/brush.go b/internal/color/brush/brush.go
index 82fa410..63d63d8 100644
--- a/internal/color/brush/brush.go
+++ b/internal/color/brush/brush.go
@@ -32,7 +32,6 @@ func paintSeverity(sb *strings.Builder, text string) bool {
default:
return false
}
-
return true
}
@@ -87,9 +86,9 @@ func paintRemote(sb *strings.Builder, line string) {
config.Client.TermColors.Remote.DelimiterAttr)
color.PaintWithAttr(sb, splitted[4],
- config.Client.TermColors.Remote.IdFg,
- config.Client.TermColors.Remote.IdBg,
- config.Client.TermColors.Remote.IdAttr)
+ config.Client.TermColors.Remote.IDFg,
+ config.Client.TermColors.Remote.IDBg,
+ config.Client.TermColors.Remote.IDAttr)
color.PaintWithAttr(sb, protocol.FieldDelimiter,
config.Client.TermColors.Remote.DelimiterFg,
config.Client.TermColors.Remote.DelimiterBg,
@@ -191,6 +190,5 @@ func Colorfy(line string) string {
color.BgDefault,
color.AttrNone)
}
-
return sb.String()
}
diff --git a/internal/color/color.go b/internal/color/color.go
index 5c25855..9d0bc2e 100644
--- a/internal/color/color.go
+++ b/internal/color/color.go
@@ -52,15 +52,19 @@ const (
AttrHidden Attribute = escape + "[8m"
)
+// ColorNames is the list of all supported terminal colors.
var ColorNames = []string{
"Black", "Red", "Green", "Yellow", "Blue", "Magenta", "Cyan", "White", "Default",
}
+// AttributeNames is the list of all supported terminal text attributes.
var AttributeNames = []string{
- "Bold", "Dim", "Italic", "Underline", "Blink", "SlowBlink", "RapidBlink", "Reverse", "Hidden", "None",
+ "Bold", "Dim", "Italic", "Underline", "Blink", "SlowBlink", "RapidBlink",
+ "Reverse", "Hidden", "None",
}
-// ToFgColor converts a given string (e.g. from a config file) into a foreground color code.
+// ToFgColor converts a given string (e.g. from a config file) into a foreground
+// color code.
func ToFgColor(s string) (FgColor, error) {
switch strings.ToLower(s) {
case "black":
@@ -86,7 +90,8 @@ func ToFgColor(s string) (FgColor, error) {
}
}
-// ToBgColor converts a given string (e.g. from a config file) into a background color code.
+// ToBgColor converts a given string (e.g. from a config file) into a background
+// color code.
func ToBgColor(s string) (BgColor, error) {
switch strings.ToLower(s) {
case "black":
diff --git a/internal/color/paint.go b/internal/color/paint.go
index 53c9abb..7735d87 100644
--- a/internal/color/paint.go
+++ b/internal/color/paint.go
@@ -10,12 +10,14 @@ func PaintStr(text string, fg FgColor, bg BgColor) string {
return fmt.Sprintf("%s%s%s%s%s", fg, bg, text, BgDefault, FgDefault)
}
-// PaintStrWithAttr paints a given text in a given foreground/background/attribute combination
+// PaintStrWithAttr paints a given text in a given foreground/background/attribute
+// combination
func PaintStrWithAttr(text string, fg FgColor, bg BgColor, attr Attribute) string {
if attr == AttrNone {
return PaintStr(text, fg, bg)
}
- return fmt.Sprintf("%s%s%s%s%s%s%s", fg, bg, attr, text, AttrReset, BgDefault, FgDefault)
+ return fmt.Sprintf("%s%s%s%s%s%s%s", fg, bg, attr, text, AttrReset,
+ BgDefault, FgDefault)
}
// PaintStrFg paints a given text in a given foreground color.
@@ -48,8 +50,11 @@ func Reset(sb *strings.Builder) {
sb.WriteString(string(FgDefault))
}
-// PaintWithAttr starts painting a given text in a given foreground/background/attribute combination.
-func PaintWithAttr(sb *strings.Builder, text string, fg FgColor, bg BgColor, attr Attribute) {
+// PaintWithAttr starts painting a given text in a given foreground/background/
+// attribute combination.
+func PaintWithAttr(sb *strings.Builder, text string, fg FgColor, bg BgColor,
+ attr Attribute) {
+
if attr == AttrNone {
Paint(sb, text, fg, bg)
return
@@ -63,8 +68,10 @@ func PaintWithAttr(sb *strings.Builder, text string, fg FgColor, bg BgColor, att
sb.WriteString(string(FgDefault))
}
-// PaintWithAttrs is similar to PaintWithAttr, but it takes multiple text attributes.
-func PaintWithAttrs(sb *strings.Builder, text string, fg FgColor, bg BgColor, attrs []Attribute) {
+// PaintWithAttrs is similar to PaintWithAttr, but it takes multiple attributes.
+func PaintWithAttrs(sb *strings.Builder, text string, fg FgColor, bg BgColor,
+ attrs []Attribute) {
+
sb.WriteString(string(fg))
sb.WriteString(string(bg))
for _, attr := range attrs {
diff --git a/internal/color/table.go b/internal/color/table.go
index 2115edf..e0e4946 100644
--- a/internal/color/table.go
+++ b/internal/color/table.go
@@ -5,8 +5,19 @@ import (
"os"
)
-const sampleParagraph string = "Mimecast is Making Email Safer for Business. We believe that securely operating a business in the cloud requires new levels of IT preparedness, centered around cyber resilience. This is why we unify the delivery and management of security, continuity and data protection for email via one, simple-to-use cloud platform. Thousands of organizations trust us to increase their cyber resilience preparedness, streamline compliance, reduce IT complexity and keep their business running. We give employees fast and secure access to sensitive business information, and ensure email keeps flowing in the event of an outage. Mimecast will remain committed to protecting your IT assets through constant innovation and focus on your success."
+const sampleParagraph string = "Mimecast is Making Email Safer for Business. " +
+ "We believe that securely operating a business in the cloud requires new " +
+ "levels of IT preparedness, centered around cyber resilience. This is why " +
+ "we unify the delivery and management of security, continuity and data " +
+ "protection for email via one, simple-to-use cloud platform. Thousands of " +
+ "organizations trust us to increase their cyber resilience preparedness, " +
+ "streamline compliance, reduce IT complexity and keep their business running. " +
+ "We give employees fast and secure access to sensitive business information, " +
+ "and ensure email keeps flowing in the event of an outage. Mimecast will " +
+ "remain committed to protecting your IT assets through constant innovation " +
+ "and focus on your success."
+// TablePrintAndExit prints the color table and then exits the process.
func TablePrintAndExit(displaySampleParagraph bool) {
for _, attr := range AttributeNames {
if attr == "Hidden" || attr == "SlowBlink" {
@@ -24,11 +35,13 @@ func printColorTable(attr string, displaySampleParagraph bool) {
if fg == bg {
continue
}
+
bgColor, _ := ToBgColor(bg)
attribute, _ := ToAttribute(attr)
-
- text := fmt.Sprintf(" Foreground:%10s | Background:%10s | Attribute:%10s ", fg, bg, attr)
+ text := fmt.Sprintf(" Foreground:%10s | Background:%10s | Attribute:%10s ",
+ fg, bg, attr)
fmt.Print(PaintStrWithAttr(text, fgColor, bgColor, attribute))
+
if displaySampleParagraph {
fmt.Print("\n")
fmt.Print(PaintStrWithAttr(sampleParagraph, fgColor, bgColor, attribute))