mirror of https://github.com/Rudi9719/kbtui.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
228 lines
5.3 KiB
228 lines
5.3 KiB
package main |
|
|
|
import ( |
|
"fmt" |
|
"regexp" |
|
"strings" |
|
) |
|
|
|
const ( |
|
black int = iota |
|
red |
|
green |
|
yellow |
|
purple |
|
magenta |
|
cyan |
|
grey |
|
normal int = -1 |
|
) |
|
|
|
var colorMapString = map[string]int{ |
|
"black": black, |
|
"red": red, |
|
"green": green, |
|
"yellow": yellow, |
|
"purple": purple, |
|
"magenta": magenta, |
|
"cyan": cyan, |
|
"grey": grey, |
|
"normal": normal, |
|
} |
|
|
|
var colorMapInt = map[int]string{ |
|
black: "black", |
|
red: "red", |
|
green: "green", |
|
yellow: "yellow", |
|
purple: "purple", |
|
magenta: "magenta", |
|
cyan: "cyan", |
|
grey: "grey", |
|
normal: "normal", |
|
} |
|
|
|
func colorFromString(color string) int { |
|
var result int |
|
color = strings.ToLower(color) |
|
result, ok := colorMapString[color] |
|
if !ok { |
|
return normal |
|
} |
|
return result |
|
} |
|
|
|
func colorFromInt(color int) string { |
|
var result string |
|
result, ok := colorMapInt[color] |
|
if !ok { |
|
return "normal" |
|
} |
|
return result |
|
} |
|
|
|
var basicStyle = Style{ |
|
Foreground: colorMapInt[normal], |
|
Background: colorMapInt[normal], |
|
Italic: false, |
|
Bold: false, |
|
Underline: false, |
|
Strikethrough: false, |
|
Inverse: false, |
|
} |
|
|
|
func (s Style) withForeground(color int) Style { |
|
s.Foreground = colorFromInt(color) |
|
return s |
|
} |
|
func (s Style) withBackground(color int) Style { |
|
s.Background = colorFromInt(color) |
|
return s |
|
} |
|
|
|
func (s Style) withBold() Style { |
|
s.Bold = true |
|
return s |
|