Make background text red
Color the background text red instead of white.
This commit is contained in:
parent
dac2410df9
commit
4a7b621986
18
woordklok.go
18
woordklok.go
|
@ -8,6 +8,10 @@ import (
|
||||||
"time"
|
"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
|
// Replace occurences of repl with their uppercase in str
|
||||||
func replace(str string, repl []string, prefix string, suffix string) string {
|
func replace(str string, repl []string, prefix string, suffix string) string {
|
||||||
ret := str
|
ret := str
|
||||||
|
@ -72,15 +76,22 @@ func woordklok(tsp time.Time, color bool) string {
|
||||||
}
|
}
|
||||||
hour := hours[hh] + " uur"
|
hour := hours[hh] + " uur"
|
||||||
|
|
||||||
|
ret := ""
|
||||||
|
|
||||||
// and replace the matching text with the uppercase
|
// and replace the matching text with the uppercase
|
||||||
prefix := ""
|
prefix := ""
|
||||||
suffix := ""
|
suffix := ""
|
||||||
if color {
|
if color {
|
||||||
// Add color definitions
|
// Add color definitions
|
||||||
prefix = "\u001b[32m" // ANSI green
|
prefix = ANSI_GREEN
|
||||||
suffix = "\u001b[0m" // ANSI reset
|
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 {
|
func IsTTY() bool {
|
||||||
|
@ -96,7 +107,6 @@ func main() {
|
||||||
batch := flag.Bool("b", false, "Batch mode (no colors)")
|
batch := flag.Bool("b", false, "Batch mode (no colors)")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// Determine color mode
|
|
||||||
colors := *color
|
colors := *color
|
||||||
if !colors {
|
if !colors {
|
||||||
colors = IsTTY()
|
colors = IsTTY()
|
||||||
|
|
Loading…
Reference in a new issue