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"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
|
|
||||||
"github.com/glycerine/zygomys/zygo"
|
"github.com/glycerine/zygomys/zygo"
|
||||||
"github.com/gookit/color"
|
"github.com/gookit/color"
|
||||||
)
|
)
|
||||||
@@ -46,6 +45,7 @@ type Config struct {
|
|||||||
Pattern string
|
Pattern string
|
||||||
PatternR *regexp.Regexp
|
PatternR *regexp.Regexp
|
||||||
UseFuzzySearch bool
|
UseFuzzySearch bool
|
||||||
|
UseHighlight bool
|
||||||
|
|
||||||
SortMode string
|
SortMode string
|
||||||
SortDescending bool
|
SortDescending bool
|
||||||
@@ -55,7 +55,8 @@ type Config struct {
|
|||||||
FIXME: make configurable somehow, config file or ENV
|
FIXME: make configurable somehow, config file or ENV
|
||||||
see https://github.com/gookit/color.
|
see https://github.com/gookit/color.
|
||||||
*/
|
*/
|
||||||
ColorStyle color.Style
|
ColorStyle color.Style
|
||||||
|
HighlightStyle color.Style
|
||||||
|
|
||||||
NoColor bool
|
NoColor bool
|
||||||
|
|
||||||
@@ -104,13 +105,16 @@ 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.FgBlack,
|
||||||
|
"hlbg": color.BgGray, "hlfg": color.FgWhite,
|
||||||
},
|
},
|
||||||
color.Level256: {
|
color.Level256: {
|
||||||
"bg": color.BgLightGreen, "fg": color.FgBlack,
|
"bg": color.BgLightGreen, "fg": color.FgBlack,
|
||||||
|
"hlbg": color.BgGray, "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.FgBlack,
|
||||||
|
"hlbg": color.BgGray, "hlfg": color.FgWhite,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,6 +127,7 @@ func (c *Config) DetermineColormode() {
|
|||||||
level := color.TermColorLevel()
|
level := color.TermColorLevel()
|
||||||
colors := Colors()
|
colors := Colors()
|
||||||
c.ColorStyle = color.New(colors[level]["bg"], colors[level]["fg"])
|
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(&conf.InvertMatch, "invert-match", "v", false, "select non-matching rows")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&ShowManual, "man", "m", false, "Display manual page")
|
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.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(&ShowCompletion, "completion", "", "", "Display completion code")
|
||||||
rootCmd.PersistentFlags().StringVarP(&conf.Separator, "separator", "s", cfg.DefaultSeparator, "Custom field separator")
|
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 ,)")
|
rootCmd.PersistentFlags().StringVarP(&conf.Columns, "columns", "c", "", "Only show the speficied columns (separated by ,)")
|
||||||
|
|||||||
@@ -22,10 +22,11 @@ SYNOPSIS
|
|||||||
-X, --extended Enable extended output
|
-X, --extended Enable extended output
|
||||||
-M, --markdown Enable markdown table output
|
-M, --markdown Enable markdown table output
|
||||||
-O, --orgtbl Enable org-mode 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
|
-Y, --yaml Enable yaml output
|
||||||
-C, --csv Enable CSV output
|
-C, --csv Enable CSV output
|
||||||
-A, --ascii Default output mode, ascii tabular
|
-A, --ascii Default output mode, ascii tabular
|
||||||
|
-L, --hightlight-lines Use alternating background colors for tables
|
||||||
|
|
||||||
Sort Mode Flags (mutually exclusive):
|
Sort Mode Flags (mutually exclusive):
|
||||||
-a, --sort-age sort according to age (duration) string
|
-a, --sort-age sort according to age (duration) string
|
||||||
@@ -38,7 +39,7 @@ SYNOPSIS
|
|||||||
-d, --debug Enable debugging
|
-d, --debug Enable debugging
|
||||||
-h, --help help for tablizer
|
-h, --help help for tablizer
|
||||||
-m, --man Display manual page
|
-m, --man Display manual page
|
||||||
-v, --version Print program version
|
-V, --version Print program version
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
Many programs generate tabular output. But sometimes you need to
|
Many programs generate tabular output. But sometimes you need to
|
||||||
@@ -313,10 +314,11 @@ Output Flags (mutually exclusive):
|
|||||||
-X, --extended Enable extended output
|
-X, --extended Enable extended output
|
||||||
-M, --markdown Enable markdown table output
|
-M, --markdown Enable markdown table output
|
||||||
-O, --orgtbl Enable org-mode 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
|
-Y, --yaml Enable yaml output
|
||||||
-C, --csv Enable CSV output
|
-C, --csv Enable CSV output
|
||||||
-A, --ascii Default output mode, ascii tabular
|
-A, --ascii Default output mode, ascii tabular
|
||||||
|
-L, --hightlight-lines Use alternating background colors for tables
|
||||||
|
|
||||||
Sort Mode Flags (mutually exclusive):
|
Sort Mode Flags (mutually exclusive):
|
||||||
-a, --sort-age sort according to age (duration) string
|
-a, --sort-age sort according to age (duration) string
|
||||||
@@ -326,12 +328,10 @@ Sort Mode Flags (mutually exclusive):
|
|||||||
|
|
||||||
Other Flags:
|
Other Flags:
|
||||||
--completion <shell> Generate the autocompletion script for <shell>
|
--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
|
-d, --debug Enable debugging
|
||||||
-h, --help help for tablizer
|
-h, --help help for tablizer
|
||||||
-m, --man Display manual page
|
-m, --man Display manual page
|
||||||
-v, --version Print program version
|
-V, --version Print program version
|
||||||
|
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -20,13 +20,14 @@ package lib
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gookit/color"
|
|
||||||
"github.com/tlinden/tablizer/cfg"
|
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gookit/color"
|
||||||
|
"github.com/tlinden/tablizer/cfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
func contains(s []int, e int) bool {
|
func contains(s []int, e int) bool {
|
||||||
@@ -155,9 +156,25 @@ 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 {
|
highlight := true
|
||||||
return c.ColorStyle.Sprint(in)
|
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 {
|
} else {
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,7 +133,7 @@
|
|||||||
.\" ========================================================================
|
.\" ========================================================================
|
||||||
.\"
|
.\"
|
||||||
.IX Title "TABLIZER 1"
|
.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
|
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
||||||
.\" way too many mistakes in technical documents.
|
.\" way too many mistakes in technical documents.
|
||||||
.if n .ad l
|
.if n .ad l
|
||||||
@@ -160,10 +160,11 @@ tablizer \- Manipulate tabular output of other programs
|
|||||||
\& \-X, \-\-extended Enable extended output
|
\& \-X, \-\-extended Enable extended output
|
||||||
\& \-M, \-\-markdown Enable markdown table output
|
\& \-M, \-\-markdown Enable markdown table output
|
||||||
\& \-O, \-\-orgtbl Enable org\-mode 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
|
\& \-Y, \-\-yaml Enable yaml output
|
||||||
\& \-C, \-\-csv Enable CSV output
|
\& \-C, \-\-csv Enable CSV output
|
||||||
\& \-A, \-\-ascii Default output mode, ascii tabular
|
\& \-A, \-\-ascii Default output mode, ascii tabular
|
||||||
|
\& \-L, \-\-hightlight\-lines Use alternating background colors for tables
|
||||||
\&
|
\&
|
||||||
\& Sort Mode Flags (mutually exclusive):
|
\& Sort Mode Flags (mutually exclusive):
|
||||||
\& \-a, \-\-sort\-age sort according to age (duration) string
|
\& \-a, \-\-sort\-age sort according to age (duration) string
|
||||||
@@ -176,7 +177,7 @@ tablizer \- Manipulate tabular output of other programs
|
|||||||
\& \-d, \-\-debug Enable debugging
|
\& \-d, \-\-debug Enable debugging
|
||||||
\& \-h, \-\-help help for tablizer
|
\& \-h, \-\-help help for tablizer
|
||||||
\& \-m, \-\-man Display manual page
|
\& \-m, \-\-man Display manual page
|
||||||
\& \-v, \-\-version Print program version
|
\& \-V, \-\-version Print program version
|
||||||
.Ve
|
.Ve
|
||||||
.SH "DESCRIPTION"
|
.SH "DESCRIPTION"
|
||||||
.IX Header "DESCRIPTION"
|
.IX Header "DESCRIPTION"
|
||||||
|
|||||||
@@ -21,10 +21,11 @@ tablizer - Manipulate tabular output of other programs
|
|||||||
-X, --extended Enable extended output
|
-X, --extended Enable extended output
|
||||||
-M, --markdown Enable markdown table output
|
-M, --markdown Enable markdown table output
|
||||||
-O, --orgtbl Enable org-mode 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
|
-Y, --yaml Enable yaml output
|
||||||
-C, --csv Enable CSV output
|
-C, --csv Enable CSV output
|
||||||
-A, --ascii Default output mode, ascii tabular
|
-A, --ascii Default output mode, ascii tabular
|
||||||
|
-L, --hightlight-lines Use alternating background colors for tables
|
||||||
|
|
||||||
Sort Mode Flags (mutually exclusive):
|
Sort Mode Flags (mutually exclusive):
|
||||||
-a, --sort-age sort according to age (duration) string
|
-a, --sort-age sort according to age (duration) string
|
||||||
@@ -37,7 +38,7 @@ tablizer - Manipulate tabular output of other programs
|
|||||||
-d, --debug Enable debugging
|
-d, --debug Enable debugging
|
||||||
-h, --help help for tablizer
|
-h, --help help for tablizer
|
||||||
-m, --man Display manual page
|
-m, --man Display manual page
|
||||||
-v, --version Print program version
|
-V, --version Print program version
|
||||||
|
|
||||||
|
|
||||||
=head1 DESCRIPTION
|
=head1 DESCRIPTION
|
||||||
|
|||||||
Reference in New Issue
Block a user