Make background text red

Color the background text red instead of white.
This commit is contained in:
Felix Niederwanger 2022-11-10 21:06:26 +01:00
parent dac2410df9
commit 4a7b621986
Signed by: phoenix
GPG key ID: 6E77A590E3F6D71C

View file

@ -8,6 +8,10 @@ import (
"time"
)
const ANSI_RED = "\u001b[31m"
const ANSI_GREEN = "\u001b[32m"
const ANSI_RESET = "\u001b[0m"
// Replace occurences of repl with their uppercase in str
func replace(str string, repl []string, prefix string, suffix string) string {
ret := str
@ -72,15 +76,22 @@ func woordklok(tsp time.Time, color bool) string {
}
hour := hours[hh] + " uur"
ret := ""
// and replace the matching text with the uppercase
prefix := ""
suffix := ""
if color {
// Add color definitions
prefix = "\u001b[32m" // ANSI green
suffix = "\u001b[0m" // ANSI reset
prefix = ANSI_GREEN
suffix = ANSI_RED
ret = ANSI_RED
}
return fmt.Sprintf("%s%s", replace(klok1, strings.Split(m, " "), prefix, suffix), replace(klok2, strings.Split(hour, " "), prefix, suffix))
ret += fmt.Sprintf("%s%s", replace(klok1, strings.Split(m, " "), prefix, suffix), replace(klok2, strings.Split(hour, " "), prefix, suffix))
if color {
ret += ANSI_RESET
}
return ret
}
func IsTTY() bool {
@ -96,7 +107,6 @@ func main() {
batch := flag.Bool("b", false, "Batch mode (no colors)")
flag.Parse()
// Determine color mode
colors := *color
if !colors {
colors = IsTTY()