mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-17 04:30:56 +01:00
added -L flag to highligh lines in alternating bg color
This commit is contained in:
@@ -22,7 +22,6 @@ import (
|
||||
"os"
|
||||
"regexp"
|
||||
|
||||
|
||||
"github.com/glycerine/zygomys/zygo"
|
||||
"github.com/gookit/color"
|
||||
)
|
||||
@@ -46,6 +45,7 @@ type Config struct {
|
||||
Pattern string
|
||||
PatternR *regexp.Regexp
|
||||
UseFuzzySearch bool
|
||||
UseHighlight bool
|
||||
|
||||
SortMode string
|
||||
SortDescending bool
|
||||
@@ -56,6 +56,7 @@ type Config struct {
|
||||
see https://github.com/gookit/color.
|
||||
*/
|
||||
ColorStyle color.Style
|
||||
HighlightStyle color.Style
|
||||
|
||||
NoColor bool
|
||||
|
||||
@@ -104,13 +105,16 @@ func Colors() map[color.Level]map[string]color.Color {
|
||||
return map[color.Level]map[string]color.Color{
|
||||
color.Level16: {
|
||||
"bg": color.BgGreen, "fg": color.FgBlack,
|
||||
"hlbg": color.BgGray, "hlfg": color.FgWhite,
|
||||
},
|
||||
color.Level256: {
|
||||
"bg": color.BgLightGreen, "fg": color.FgBlack,
|
||||
"hlbg": color.BgGray, "hlfg": color.FgWhite,
|
||||
},
|
||||
color.LevelRgb: {
|
||||
// FIXME: maybe use something nicer
|
||||
"bg": color.BgLightGreen, "fg": color.FgBlack,
|
||||
"hlbg": color.BgGray, "hlfg": color.FgWhite,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -123,6 +127,7 @@ func (c *Config) DetermineColormode() {
|
||||
level := color.TermColorLevel()
|
||||
colors := Colors()
|
||||
c.ColorStyle = color.New(colors[level]["bg"], colors[level]["fg"])
|
||||
c.HighlightStyle = color.New(colors[level]["hlbg"], colors[level]["hlfg"])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -118,6 +118,7 @@ func Execute() {
|
||||
rootCmd.PersistentFlags().BoolVarP(&conf.InvertMatch, "invert-match", "v", false, "select non-matching rows")
|
||||
rootCmd.PersistentFlags().BoolVarP(&ShowManual, "man", "m", false, "Display manual page")
|
||||
rootCmd.PersistentFlags().BoolVarP(&conf.UseFuzzySearch, "fuzzy", "z", false, "Use fuzzy searching")
|
||||
rootCmd.PersistentFlags().BoolVarP(&conf.UseHighlight, "highlight-lines", "L", false, "Use alternating background colors")
|
||||
rootCmd.PersistentFlags().StringVarP(&ShowCompletion, "completion", "", "", "Display completion code")
|
||||
rootCmd.PersistentFlags().StringVarP(&conf.Separator, "separator", "s", cfg.DefaultSeparator, "Custom field separator")
|
||||
rootCmd.PersistentFlags().StringVarP(&conf.Columns, "columns", "c", "", "Only show the speficied columns (separated by ,)")
|
||||
|
||||
@@ -22,10 +22,11 @@ SYNOPSIS
|
||||
-X, --extended Enable extended output
|
||||
-M, --markdown Enable markdown table output
|
||||
-O, --orgtbl Enable org-mode table output
|
||||
-S, --shell Enable shell evaluable ouput
|
||||
-S, --shell Enable shell evaluable output
|
||||
-Y, --yaml Enable yaml output
|
||||
-C, --csv Enable CSV output
|
||||
-A, --ascii Default output mode, ascii tabular
|
||||
-L, --hightlight-lines Use alternating background colors for tables
|
||||
|
||||
Sort Mode Flags (mutually exclusive):
|
||||
-a, --sort-age sort according to age (duration) string
|
||||
@@ -38,7 +39,7 @@ SYNOPSIS
|
||||
-d, --debug Enable debugging
|
||||
-h, --help help for tablizer
|
||||
-m, --man Display manual page
|
||||
-v, --version Print program version
|
||||
-V, --version Print program version
|
||||
|
||||
DESCRIPTION
|
||||
Many programs generate tabular output. But sometimes you need to
|
||||
@@ -313,10 +314,11 @@ Output Flags (mutually exclusive):
|
||||
-X, --extended Enable extended output
|
||||
-M, --markdown Enable markdown table output
|
||||
-O, --orgtbl Enable org-mode table output
|
||||
-S, --shell Enable shell evaluable ouput
|
||||
-S, --shell Enable shell evaluable output
|
||||
-Y, --yaml Enable yaml output
|
||||
-C, --csv Enable CSV output
|
||||
-A, --ascii Default output mode, ascii tabular
|
||||
-L, --hightlight-lines Use alternating background colors for tables
|
||||
|
||||
Sort Mode Flags (mutually exclusive):
|
||||
-a, --sort-age sort according to age (duration) string
|
||||
@@ -326,12 +328,10 @@ Sort Mode Flags (mutually exclusive):
|
||||
|
||||
Other Flags:
|
||||
--completion <shell> Generate the autocompletion script for <shell>
|
||||
-l --load-path <path> Where to search for lisp plugins. Maybe a file or
|
||||
a directory containing files with *.zy extension
|
||||
-d, --debug Enable debugging
|
||||
-h, --help help for tablizer
|
||||
-m, --man Display manual page
|
||||
-v, --version Print program version
|
||||
-V, --version Print program version
|
||||
|
||||
|
||||
`
|
||||
|
||||
@@ -20,13 +20,14 @@ package lib
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gookit/color"
|
||||
"github.com/tlinden/tablizer/cfg"
|
||||
"os"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gookit/color"
|
||||
"github.com/tlinden/tablizer/cfg"
|
||||
)
|
||||
|
||||
func contains(s []int, e int) bool {
|
||||
@@ -155,9 +156,25 @@ func trimRow(row []string) []string {
|
||||
func colorizeData(c cfg.Config, output string) string {
|
||||
if len(c.Pattern) > 0 && !c.NoColor && color.IsConsole(os.Stdout) {
|
||||
r := regexp.MustCompile("(" + c.Pattern + ")")
|
||||
return r.ReplaceAllStringFunc(output, func(in string) string {
|
||||
highlight := true
|
||||
colorized := ""
|
||||
|
||||
for _, line := range strings.Split(output, "\n") {
|
||||
if c.UseHighlight {
|
||||
if highlight {
|
||||
line = c.HighlightStyle.Sprint(line)
|
||||
}
|
||||
highlight = !highlight
|
||||
} else {
|
||||
line = r.ReplaceAllStringFunc(line, func(in string) string {
|
||||
return c.ColorStyle.Sprint(in)
|
||||
})
|
||||
}
|
||||
|
||||
colorized += line + "\n"
|
||||
}
|
||||
|
||||
return colorized
|
||||
} else {
|
||||
return output
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@
|
||||
.\" ========================================================================
|
||||
.\"
|
||||
.IX Title "TABLIZER 1"
|
||||
.TH TABLIZER 1 "2023-05-06" "1" "User Commands"
|
||||
.TH TABLIZER 1 "2023-11-21" "1" "User Commands"
|
||||
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
||||
.\" way too many mistakes in technical documents.
|
||||
.if n .ad l
|
||||
@@ -160,10 +160,11 @@ tablizer \- Manipulate tabular output of other programs
|
||||
\& \-X, \-\-extended Enable extended output
|
||||
\& \-M, \-\-markdown Enable markdown table output
|
||||
\& \-O, \-\-orgtbl Enable org\-mode table output
|
||||
\& \-S, \-\-shell Enable shell evaluable ouput
|
||||
\& \-S, \-\-shell Enable shell evaluable output
|
||||
\& \-Y, \-\-yaml Enable yaml output
|
||||
\& \-C, \-\-csv Enable CSV output
|
||||
\& \-A, \-\-ascii Default output mode, ascii tabular
|
||||
\& \-L, \-\-hightlight\-lines Use alternating background colors for tables
|
||||
\&
|
||||
\& Sort Mode Flags (mutually exclusive):
|
||||
\& \-a, \-\-sort\-age sort according to age (duration) string
|
||||
@@ -176,7 +177,7 @@ tablizer \- Manipulate tabular output of other programs
|
||||
\& \-d, \-\-debug Enable debugging
|
||||
\& \-h, \-\-help help for tablizer
|
||||
\& \-m, \-\-man Display manual page
|
||||
\& \-v, \-\-version Print program version
|
||||
\& \-V, \-\-version Print program version
|
||||
.Ve
|
||||
.SH "DESCRIPTION"
|
||||
.IX Header "DESCRIPTION"
|
||||
|
||||
@@ -21,10 +21,11 @@ tablizer - Manipulate tabular output of other programs
|
||||
-X, --extended Enable extended output
|
||||
-M, --markdown Enable markdown table output
|
||||
-O, --orgtbl Enable org-mode table output
|
||||
-S, --shell Enable shell evaluable ouput
|
||||
-S, --shell Enable shell evaluable output
|
||||
-Y, --yaml Enable yaml output
|
||||
-C, --csv Enable CSV output
|
||||
-A, --ascii Default output mode, ascii tabular
|
||||
-L, --hightlight-lines Use alternating background colors for tables
|
||||
|
||||
Sort Mode Flags (mutually exclusive):
|
||||
-a, --sort-age sort according to age (duration) string
|
||||
@@ -37,7 +38,7 @@ tablizer - Manipulate tabular output of other programs
|
||||
-d, --debug Enable debugging
|
||||
-h, --help help for tablizer
|
||||
-m, --man Display manual page
|
||||
-v, --version Print program version
|
||||
-V, --version Print program version
|
||||
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Reference in New Issue
Block a user