works but is ugly :(

This commit is contained in:
2023-11-21 17:41:04 +01:00
parent a8c9ede77e
commit 3c910ca08f
2 changed files with 12 additions and 15 deletions

View File

@@ -104,17 +104,17 @@ var ValidHooks []string
func Colors() map[color.Level]map[string]color.Color { func Colors() map[color.Level]map[string]color.Color {
return map[color.Level]map[string]color.Color{ return map[color.Level]map[string]color.Color{
color.Level16: { color.Level16: {
"bg": color.BgGreen, "fg": color.FgBlack, "bg": color.BgGreen, "fg": color.FgWhite,
"hlbg": color.BgGray, "hlfg": color.FgWhite, "hlbg": color.BgGray, "hlfg": color.FgWhite,
}, },
color.Level256: { color.Level256: {
"bg": color.BgLightGreen, "fg": color.FgBlack, "bg": color.BgLightGreen, "fg": color.FgWhite,
"hlbg": color.BgGray, "hlfg": color.FgWhite, "hlbg": color.BgLightBlue, "hlfg": color.FgWhite,
}, },
color.LevelRgb: { color.LevelRgb: {
// FIXME: maybe use something nicer // FIXME: maybe use something nicer
"bg": color.BgLightGreen, "fg": color.FgBlack, "bg": color.BgLightGreen, "fg": color.FgWhite,
"hlbg": color.BgGray, "hlfg": color.FgWhite, "hlbg": color.BgBlue, "hlfg": color.FgWhite,
}, },
} }
} }

View File

@@ -156,21 +156,18 @@ func trimRow(row []string) []string {
func colorizeData(c cfg.Config, output string) string { func colorizeData(c cfg.Config, output string) string {
if len(c.Pattern) > 0 && !c.NoColor && color.IsConsole(os.Stdout) { if len(c.Pattern) > 0 && !c.NoColor && color.IsConsole(os.Stdout) {
r := regexp.MustCompile("(" + c.Pattern + ")") r := regexp.MustCompile("(" + c.Pattern + ")")
return r.ReplaceAllStringFunc(output, func(in string) string {
return c.ColorStyle.Sprint(in)
})
} else if c.UseHighlight && color.IsConsole(os.Stdout) {
highlight := true highlight := true
colorized := "" colorized := ""
for _, line := range strings.Split(output, "\n") { for _, line := range strings.Split(output, "\n") {
if c.UseHighlight {
if highlight { if highlight {
line = c.HighlightStyle.Sprint(line) line = c.HighlightStyle.Sprint(line)
} }
highlight = !highlight highlight = !highlight
} else {
line = r.ReplaceAllStringFunc(line, func(in string) string {
return c.ColorStyle.Sprint(in)
})
}
colorized += line + "\n" colorized += line + "\n"
} }