mirror of
https://codeberg.org/scip/tablizer.git
synced 2026-02-04 10:20:59 +01:00
colorize-output using regexes, refactor line colorization (#49)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright © 2022-2025 Thomas von Dein
|
||||
Copyright © 2022-2026 Thomas von Dein
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -28,7 +28,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
Version = "v1.5.12"
|
||||
Version = "v1.6.0"
|
||||
MAXPARTS = 2
|
||||
)
|
||||
|
||||
@@ -102,15 +102,15 @@ type Config struct {
|
||||
SortByColumn string // 1,2
|
||||
UseSortByColumn []int // []int{1,2}
|
||||
|
||||
TransposeColumns string // 1,2
|
||||
UseTransposeColumns []int // []int{1,2}
|
||||
Transposers []string // []string{"/ /-/", "/foo/bar/"}
|
||||
UseTransposers []Transposer // {Search: re, Replace: string}
|
||||
TransposeColumns string // 1,2
|
||||
UseTransposeColumns []int // []int{1,2}
|
||||
|
||||
Transposers []string // []string{"/ /-/", "/foo/bar/"}
|
||||
UseTransposers []Transposer // {Search: re, Replace: string}
|
||||
|
||||
Colorizers []string // []string{"/ /-/", "/foo/fg[:bg]/"}
|
||||
UseColorizers []Transposer // {Search: re, Replace: color}
|
||||
|
||||
/*
|
||||
FIXME: make configurable somehow, config file or ENV
|
||||
see https://github.com/gookit/color.
|
||||
*/
|
||||
ColorStyle color.Style
|
||||
HighlightStyle color.Style
|
||||
NoHighlightStyle color.Style
|
||||
@@ -357,6 +357,23 @@ func (conf *Config) PrepareTransposers() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (conf *Config) PrepareColorizers() error {
|
||||
for _, colorizer := range conf.Colorizers {
|
||||
parts := strings.Split(colorizer, string(colorizer[0]))
|
||||
if len(parts) != 4 {
|
||||
return fmt.Errorf("colorizer function must have the format /regexp/foreground-color[:background-color]/")
|
||||
}
|
||||
|
||||
conf.UseColorizers = append(conf.UseColorizers,
|
||||
Transposer{
|
||||
Search: *regexp.MustCompile(parts[1]),
|
||||
Replace: parts[2]},
|
||||
)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (conf *Config) CheckEnv() {
|
||||
// check for environment vars, command line flags have precedence,
|
||||
// NO_COLOR is being checked by the color module itself.
|
||||
|
||||
Reference in New Issue
Block a user