diff options
| author | Paul Buetow <paul@buetow.org> | 2021-09-05 15:51:26 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2021-09-05 15:51:26 +0300 |
| commit | bfcb0f159a4835cc6a0326ff46de7934e0363aed (patch) | |
| tree | 92a3f9363df0e70bf54a2a3c99928aa6a4ef861c /internal/color/paint.go | |
| parent | 23982f331c2154a66b86d596226c24454fd06be5 (diff) | |
finalize new default color schema
Diffstat (limited to 'internal/color/paint.go')
| -rw-r--r-- | internal/color/paint.go | 59 |
1 files changed, 47 insertions, 12 deletions
diff --git a/internal/color/paint.go b/internal/color/paint.go index 7862467..2798ff7 100644 --- a/internal/color/paint.go +++ b/internal/color/paint.go @@ -1,31 +1,66 @@ package color -import "fmt" +import ( + "fmt" + "strings" +) -// Paint paints a given text in a given foreground/background color combination. -func Paint(text string, fg FgColor, bg BgColor) string { +// PaintStr paints a given text in a given foreground/background color combination. +func PaintStr(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 { +// 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 Paint(text, fg, bg) + return PaintStr(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 { +// PaintStrFg paints a given text in a given foreground color. +func PaintStrFg(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 { +// PaintStrBg paints a given text in a given background color. +func PaintStrBg(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 { +// PaintStrAttr adds a given attribute to a given text, such as "bold" or "italic". +func PaintStrAttr(text string, attr Attribute) string { return fmt.Sprintf("%s%s%s", attr, text, AttrReset) } + +// Paint paints a given text in a given foreground/background color combination. +func Paint(sb *strings.Builder, text string, fg FgColor, bg BgColor) { + sb.WriteString(string(fg)) + sb.WriteString(string(bg)) + sb.WriteString(text) +} + +// Reset background and foreground colors. +func Reset(sb *strings.Builder) { + sb.WriteString(string(BgDefault)) + 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) { + if attr == AttrNone { + Paint(sb, text, fg, bg) + return + } + sb.WriteString(string(fg)) + sb.WriteString(string(bg)) + sb.WriteString(string(attr)) + sb.WriteString(text) +} + +// ResetWithAttr resets background, foreground and attributes. +func ResetWithAttr(sb *strings.Builder) { + sb.WriteString(string(AttrReset)) + sb.WriteString(string(BgDefault)) + sb.WriteString(string(FgDefault)) +} |
