summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2021-08-11 09:42:51 +0300
committerPaul Buetow <paul@buetow.org>2021-08-11 09:42:51 +0300
commit1e00c256842e125a865a6cc3f9aa70a1a498f6dc (patch)
treea7ebd3e782cf2abbb72bc06bf242363e1c6877f2
parent9bb96433be61d89f8e86f6f9ded8e35f74156a63 (diff)
add paint.go
-rw-r--r--internal/color/color.go31
-rw-r--r--internal/color/paint.go31
-rw-r--r--internal/color/table.go8
3 files changed, 35 insertions, 35 deletions
diff --git a/internal/color/color.go b/internal/color/color.go
index a2490be..692de51 100644
--- a/internal/color/color.go
+++ b/internal/color/color.go
@@ -52,35 +52,12 @@ const (
AttrHidden Attribute = escape + "[8m"
)
-// Colored DTail client output enabled.
-var Colored bool
-
-// Paint paints a given text in a given foreground/background color combination.
-func Paint(text string, fg FgColor, bg BgColor) string {
- return fmt.Sprintf("%s%s%s%s%s", fg, bg, text, BgDefault, FgDefault)
-}
-
-// PaintWithAttr paints a given text in a given foreground/background/attribute combination
-func PaintWithAttr(text string, fg FgColor, bg BgColor, attr Attribute) string {
- if attr == AttrNone {
- return Paint(text, fg, bg)
- }
- return fmt.Sprintf("%s%s%s%s%s%s%s", fg, bg, attr, text, AttrReset, BgDefault, FgDefault)
-}
-
-// PaintFg paints a given text in a given foreground color.
-func PaintFg(text string, fg FgColor) string {
- return fmt.Sprintf("%s%s%s", fg, text, FgDefault)
-}
-
-// PaintBg paints a given text in a given background color.
-func PaintBg(text string, bg BgColor) string {
- return fmt.Sprintf("%s%s%s", bg, text, BgDefault)
+var ColorNames = []string{
+ "Black", "Red", "Green", "Yellow", "Blue", "Magenta", "Cyan", "White", "Default",
}
-// PaintAttr adds a given attribute to a given text, such as "bold" or "italic".
-func PaintAttr(text string, attr Attribute) string {
- return fmt.Sprintf("%s%s%s", attr, text, AttrReset)
+var AttributeNames = []string{
+ "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.
diff --git a/internal/color/paint.go b/internal/color/paint.go
new file mode 100644
index 0000000..7862467
--- /dev/null
+++ b/internal/color/paint.go
@@ -0,0 +1,31 @@
+package color
+
+import "fmt"
+
+// Paint paints a given text in a given foreground/background color combination.
+func Paint(text string, fg FgColor, bg BgColor) string {
+ return fmt.Sprintf("%s%s%s%s%s", fg, bg, text, BgDefault, FgDefault)
+}
+
+// PaintWithAttr paints a given text in a given foreground/background/attribute combination
+func PaintWithAttr(text string, fg FgColor, bg BgColor, attr Attribute) string {
+ if attr == AttrNone {
+ return Paint(text, fg, bg)
+ }
+ return fmt.Sprintf("%s%s%s%s%s%s%s", fg, bg, attr, text, AttrReset, BgDefault, FgDefault)
+}
+
+// PaintFg paints a given text in a given foreground color.
+func PaintFg(text string, fg FgColor) string {
+ return fmt.Sprintf("%s%s%s", fg, text, FgDefault)
+}
+
+// PaintBg paints a given text in a given background color.
+func PaintBg(text string, bg BgColor) string {
+ return fmt.Sprintf("%s%s%s", bg, text, BgDefault)
+}
+
+// PaintAttr adds a given attribute to a given text, such as "bold" or "italic".
+func PaintAttr(text string, attr Attribute) string {
+ return fmt.Sprintf("%s%s%s", attr, text, AttrReset)
+}
diff --git a/internal/color/table.go b/internal/color/table.go
index 8e40a78..8c36047 100644
--- a/internal/color/table.go
+++ b/internal/color/table.go
@@ -5,14 +5,6 @@ import (
"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" {