mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-17 04:30:56 +01:00
added pattern highlighting support
This commit is contained in:
@@ -20,6 +20,8 @@ package lib
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gookit/color"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -130,3 +132,21 @@ func trimRow(row []string) []string {
|
||||
|
||||
return fixedrow
|
||||
}
|
||||
|
||||
func colorizeData(output string) string {
|
||||
if len(Pattern) > 0 && !NoColor && color.IsConsole(os.Stdout) {
|
||||
r := regexp.MustCompile("(" + Pattern + ")")
|
||||
return r.ReplaceAllString(output, "<bg="+MatchBG+";fg="+MatchFG+">$1</>")
|
||||
} else {
|
||||
return output
|
||||
}
|
||||
}
|
||||
|
||||
func isTerminal(f *os.File) bool {
|
||||
o, _ := f.Stat()
|
||||
if (o.Mode() & os.ModeCharDevice) == os.ModeCharDevice {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user