mirror of
https://codeberg.org/scip/tablizer.git
synced 2026-02-04 18:30:58 +01:00
Compare commits
10 Commits
templates
...
2122805301
| Author | SHA1 | Date | |
|---|---|---|---|
| 2122805301 | |||
| 935f5cc28f | |||
| 6e7b6c1a20 | |||
| e4ce325d98 | |||
| 1e9c23d5fa | |||
| 6d92d70ea2 | |||
|
|
834892e302 | ||
|
|
46fde289f5 | ||
| d331f0b2e6 | |||
|
|
fc0352efa9 |
@@ -18,6 +18,9 @@ builds:
|
|||||||
- windows
|
- windows
|
||||||
- darwin
|
- darwin
|
||||||
- freebsd
|
- freebsd
|
||||||
|
goarch:
|
||||||
|
- amd64
|
||||||
|
- arm64
|
||||||
|
|
||||||
archives:
|
archives:
|
||||||
- formats: [tar.gz]
|
- formats: [tar.gz]
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
# https://woodpecker-ci.org/plugins/docker-buildx
|
|
||||||
# enable Package unit and go to /scip/-/packages after building to link to proj
|
|
||||||
|
|
||||||
variables:
|
|
||||||
- &repo codeberg.org/${CI_REPO_OWNER}/tablizer
|
|
||||||
|
|
||||||
steps:
|
|
||||||
dryrun:
|
|
||||||
image: docker.io/woodpeckerci/plugin-docker-buildx:latest
|
|
||||||
settings:
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
platforms: linux/amd64
|
|
||||||
dry_run: true
|
|
||||||
repo: *repo
|
|
||||||
tags: latest
|
|
||||||
when:
|
|
||||||
event: [pull_request]
|
|
||||||
|
|
||||||
publish:
|
|
||||||
image: docker.io/woodpeckerci/plugin-docker-buildx:latest
|
|
||||||
settings:
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
platforms: linux/amd64
|
|
||||||
repo: *repo
|
|
||||||
registry: codeberg.org
|
|
||||||
tags: latest,${CI_COMMIT_SHA:0:8},${CI_COMMIT_TAG}
|
|
||||||
username: ${CI_REPO_OWNER}
|
|
||||||
password:
|
|
||||||
from_secret: REGISTRY_TOKEN
|
|
||||||
when:
|
|
||||||
event: [tag]
|
|
||||||
branch: main
|
|
||||||
14
README.md
14
README.md
@@ -45,17 +45,17 @@ Operational Flags:
|
|||||||
-n, --numbering Enable header numbering
|
-n, --numbering Enable header numbering
|
||||||
-N, --no-color Disable pattern highlighting
|
-N, --no-color Disable pattern highlighting
|
||||||
-H, --no-headers Disable headers display
|
-H, --no-headers Disable headers display
|
||||||
-s, --separator <string> Custom field separator
|
-s, --separator <string> Custom field separator (maybe char, string or :class:)
|
||||||
-k, --sort-by <int|name> Sort by column (default: 1)
|
-k, --sort-by <int|name> Sort by column (default: 1)
|
||||||
-z, --fuzzy Use fuzzy search [experimental]
|
-z, --fuzzy Use fuzzy search [experimental]
|
||||||
-F, --filter <field[!]=reg> Filter given field with regex, can be used multiple times
|
-F, --filter <field[!]=reg> Filter given field with regex, can be used multiple times
|
||||||
-T, --transpose-columns string Transpose the speficied columns (separated by ,)
|
-T, --transpose-columns string Transpose the speficied columns (separated by ,)
|
||||||
-R, --regex-transposer </from/to/> Apply /search/replace/ regexp to fields given in -T
|
-R, --regex-transposer </from/to/> Apply /search/replace/ regexp to fields given in -T
|
||||||
|
-K --regex-colorizer /from/color/ colorize pattern of output (color: fg[:bg])
|
||||||
-j, --json Read JSON input (must be array of hashes)
|
-j, --json Read JSON input (must be array of hashes)
|
||||||
-I, --interactive Interactively filter and select rows
|
-I, --interactive Interactively filter and select rows
|
||||||
--auto-headers Generate headers if there are none present in input
|
-g, --auto-headers Generate headers if there are none present in input
|
||||||
--custom-headers a,b,... Use custom headers, separated by comma
|
-x, --custom-headers a,b,... Use custom headers, separated by comma
|
||||||
|
|
||||||
|
|
||||||
Output Flags (mutually exclusive):
|
Output Flags (mutually exclusive):
|
||||||
-X, --extended Enable extended output
|
-X, --extended Enable extended output
|
||||||
@@ -63,12 +63,14 @@ Output Flags (mutually exclusive):
|
|||||||
-O, --orgtbl Enable org-mode table output
|
-O, --orgtbl Enable org-mode table output
|
||||||
-S, --shell Enable shell evaluable output
|
-S, --shell Enable shell evaluable output
|
||||||
-Y, --yaml Enable yaml output
|
-Y, --yaml Enable yaml output
|
||||||
|
-J, --jsonout Enable JSON 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
|
||||||
|
-P, --template <tpl> Enable template mode with template <tpl>
|
||||||
-L, --hightlight-lines Use alternating background colors for tables
|
-L, --hightlight-lines Use alternating background colors for tables
|
||||||
|
-o, --ofs <char> Output field separator, used by -A and -C.
|
||||||
-y, --yank-columns Yank specified columns (separated by ,) to clipboard,
|
-y, --yank-columns Yank specified columns (separated by ,) to clipboard,
|
||||||
space separated
|
space separated
|
||||||
--ofs <char> Output field separator, used by -A and -C.
|
|
||||||
|
|
||||||
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 +178,7 @@ Here, we modified the 4th column (`-T4`) by replacing every space with
|
|||||||
a dash. If you need to work with `/` characters, you can also use any
|
a dash. If you need to work with `/` characters, you can also use any
|
||||||
other separator, for instance: `-R '| |-|'`.
|
other separator, for instance: `-R '| |-|'`.
|
||||||
|
|
||||||
There's also an interactive mode, invoked with the option B<-I>, where
|
There's also an interactive mode, invoked with the option `-I`, where
|
||||||
you can interactively filter and select rows:
|
you can interactively filter and select rows:
|
||||||
|
|
||||||
<img width="937" height="293" alt="interactive" src="https://github.com/user-attachments/assets/0d4d65e2-d156-43ed-8021-39047c7939ed" />
|
<img width="937" height="293" alt="interactive" src="https://github.com/user-attachments/assets/0d4d65e2-d156-43ed-8021-39047c7939ed" />
|
||||||
|
|||||||
@@ -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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -28,7 +28,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = "v1.5.12"
|
Version = "v1.6.0"
|
||||||
MAXPARTS = 2
|
MAXPARTS = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -104,13 +104,13 @@ type Config struct {
|
|||||||
|
|
||||||
TransposeColumns string // 1,2
|
TransposeColumns string // 1,2
|
||||||
UseTransposeColumns []int // []int{1,2}
|
UseTransposeColumns []int // []int{1,2}
|
||||||
|
|
||||||
Transposers []string // []string{"/ /-/", "/foo/bar/"}
|
Transposers []string // []string{"/ /-/", "/foo/bar/"}
|
||||||
UseTransposers []Transposer // {Search: re, Replace: string}
|
UseTransposers []Transposer // {Search: re, Replace: string}
|
||||||
|
|
||||||
/*
|
Colorizers []string // []string{"/ /-/", "/foo/fg[:bg]/"}
|
||||||
FIXME: make configurable somehow, config file or ENV
|
UseColorizers []Transposer // {Search: re, Replace: color}
|
||||||
see https://github.com/gookit/color.
|
|
||||||
*/
|
|
||||||
ColorStyle color.Style
|
ColorStyle color.Style
|
||||||
HighlightStyle color.Style
|
HighlightStyle color.Style
|
||||||
NoHighlightStyle color.Style
|
NoHighlightStyle color.Style
|
||||||
@@ -357,6 +357,23 @@ func (conf *Config) PrepareTransposers() error {
|
|||||||
return nil
|
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() {
|
func (conf *Config) CheckEnv() {
|
||||||
// check for environment vars, command line flags have precedence,
|
// check for environment vars, command line flags have precedence,
|
||||||
// NO_COLOR is being checked by the color module itself.
|
// NO_COLOR is being checked by the color module itself.
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ func TestPrepareModeFlags(t *testing.T) {
|
|||||||
{Modeflag{}, ASCII},
|
{Modeflag{}, ASCII},
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: use a map for easier printing
|
|
||||||
for _, testdata := range tests {
|
for _, testdata := range tests {
|
||||||
testname := fmt.Sprintf("PrepareModeFlags-expect-%d", testdata.expect)
|
testname := fmt.Sprintf("PrepareModeFlags-expect-%d", testdata.expect)
|
||||||
t.Run(testname, func(t *testing.T) {
|
t.Run(testname, func(t *testing.T) {
|
||||||
|
|||||||
@@ -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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -95,6 +95,7 @@ func Execute() {
|
|||||||
conf.PrepareCustomHeaders(headers)
|
conf.PrepareCustomHeaders(headers)
|
||||||
|
|
||||||
wrapE(conf.PrepareFilters())
|
wrapE(conf.PrepareFilters())
|
||||||
|
wrapE(conf.PrepareColorizers())
|
||||||
|
|
||||||
conf.DetermineColormode()
|
conf.DetermineColormode()
|
||||||
conf.ApplyDefaults()
|
conf.ApplyDefaults()
|
||||||
@@ -191,6 +192,8 @@ func Execute() {
|
|||||||
"filter", "F", nil, "Filter by field (field=regexp || field!=regexp)")
|
"filter", "F", nil, "Filter by field (field=regexp || field!=regexp)")
|
||||||
rootCmd.PersistentFlags().StringArrayVarP(&conf.Transposers,
|
rootCmd.PersistentFlags().StringArrayVarP(&conf.Transposers,
|
||||||
"regex-transposer", "R", nil, "apply /search/replace/ regexp to fields given in -T")
|
"regex-transposer", "R", nil, "apply /search/replace/ regexp to fields given in -T")
|
||||||
|
rootCmd.PersistentFlags().StringArrayVarP(&conf.Colorizers,
|
||||||
|
"regex-colorizer", "K", nil, "apply /search/color[:background]/ to the whole output")
|
||||||
|
|
||||||
// input
|
// input
|
||||||
rootCmd.PersistentFlags().StringVarP(&conf.InputFile, "read-file", "r", "",
|
rootCmd.PersistentFlags().StringVarP(&conf.InputFile, "read-file", "r", "",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
const shortusage = `tablizer [regex,...] [-r file] [flags]
|
const shortusage = `tablizer [regex,...] [-r file] [flags]
|
||||||
-c col,... show specified columns -L highlight matching lines
|
-c col,... show specified columns -L colorize rows
|
||||||
-k col,... sort by specified columns -j read JSON input
|
-k col,... sort by specified columns -j read JSON input
|
||||||
-F col=reg filter field with regexp -v invert match
|
-F col=reg filter field with regexp -v invert match
|
||||||
-T col,... transpose specified columns -n numberize columns
|
-T col,... transpose specified columns -n numberize columns
|
||||||
@@ -13,6 +13,7 @@ const shortusage = `tablizer [regex,...] [-r file] [flags]
|
|||||||
-x col,... use custom headers -d debug
|
-x col,... use custom headers -d debug
|
||||||
-o char use char as output separator -g auto generate headers
|
-o char use char as output separator -g auto generate headers
|
||||||
|
|
||||||
|
-K /pattern/foreground[:background]/ colorize pattern of output
|
||||||
-O org -C CSV -M md -X ext -S shell -Y yaml -J json -P template
|
-O org -C CSV -M md -X ext -S shell -Y yaml -J json -P template
|
||||||
-a sort by age -i sort numerically -t sort by time -D sort descending order
|
-a sort by age -i sort numerically -t sort by time -D sort descending order
|
||||||
-m show manual -v show version --help show detailed help`
|
-m show manual -v show version --help show detailed help`
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ SYNOPSIS
|
|||||||
-F, --filter <field[!]=reg> Filter given field with regex, can be used multiple times
|
-F, --filter <field[!]=reg> Filter given field with regex, can be used multiple times
|
||||||
-T, --transpose-columns string Transpose the speficied columns (separated by ,)
|
-T, --transpose-columns string Transpose the speficied columns (separated by ,)
|
||||||
-R, --regex-transposer </from/to/> Apply /search/replace/ regexp to fields given in -T
|
-R, --regex-transposer </from/to/> Apply /search/replace/ regexp to fields given in -T
|
||||||
|
-K --regex-colorizer /from/color/ colorize pattern of output (color: fg[:bg])
|
||||||
-j, --json Read JSON input (must be array of hashes)
|
-j, --json Read JSON input (must be array of hashes)
|
||||||
-I, --interactive Interactively filter and select rows
|
-I, --interactive Interactively filter and select rows
|
||||||
-g, --auto-headers Generate headers if there are none present in input
|
-g, --auto-headers Generate headers if there are none present in input
|
||||||
@@ -467,9 +468,20 @@ CONFIGURATION AND COLORS
|
|||||||
lightGreen, lightMagenta, lightRed, lightWhite, lightYellow, magenta,
|
lightGreen, lightMagenta, lightRed, lightWhite, lightYellow, magenta,
|
||||||
red, white, yellow
|
red, white, yellow
|
||||||
|
|
||||||
The Variables FG and BG are being used to highlight matches. The other
|
but you may also use HTML color codes without the hash sign.
|
||||||
*FG and *BG variables are for colored table output (enabled with the
|
|
||||||
"-L" parameter).
|
The Variables FG and BG are being used to highlight matching rows. The
|
||||||
|
other *FG and *BG variables are for colored table output (enabled with
|
||||||
|
the "-L" parameter).
|
||||||
|
|
||||||
|
You can also use the option "-K" to colorize particular patterns, not
|
||||||
|
whole lines. The option can be given multiple times and expects the
|
||||||
|
following parameter:
|
||||||
|
|
||||||
|
-K '/regex/foreground[:background]/
|
||||||
|
|
||||||
|
that is, background color is optional. This colorization will applied on
|
||||||
|
top of any previous colorizations, if any.
|
||||||
|
|
||||||
Colorization can be turned off completely either by setting the
|
Colorization can be turned off completely either by setting the
|
||||||
parameter "-N" or the environment variable NO_COLOR to a true value.
|
parameter "-N" or the environment variable NO_COLOR to a true value.
|
||||||
@@ -531,6 +543,7 @@ Operational Flags:
|
|||||||
-F, --filter <field[!]=reg> Filter given field with regex, can be used multiple times
|
-F, --filter <field[!]=reg> Filter given field with regex, can be used multiple times
|
||||||
-T, --transpose-columns string Transpose the speficied columns (separated by ,)
|
-T, --transpose-columns string Transpose the speficied columns (separated by ,)
|
||||||
-R, --regex-transposer </from/to/> Apply /search/replace/ regexp to fields given in -T
|
-R, --regex-transposer </from/to/> Apply /search/replace/ regexp to fields given in -T
|
||||||
|
-K --regex-colorizer /from/color/ colorize pattern of output (color: fg[:bg])
|
||||||
-j, --json Read JSON input (must be array of hashes)
|
-j, --json Read JSON input (must be array of hashes)
|
||||||
-I, --interactive Interactively filter and select rows
|
-I, --interactive Interactively filter and select rows
|
||||||
-g, --auto-headers Generate headers if there are none present in input
|
-g, --auto-headers Generate headers if there are none present in input
|
||||||
|
|||||||
@@ -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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -22,8 +22,8 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/lithammer/fuzzysearch/fuzzy"
|
|
||||||
"codeberg.org/scip/tablizer/cfg"
|
"codeberg.org/scip/tablizer/cfg"
|
||||||
|
"github.com/lithammer/fuzzysearch/fuzzy"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright © 2022 Thomas von Dein
|
Copyright © 2022-2026 Thomas von Dein
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -26,8 +26,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gookit/color"
|
|
||||||
"codeberg.org/scip/tablizer/cfg"
|
"codeberg.org/scip/tablizer/cfg"
|
||||||
|
"github.com/gookit/color"
|
||||||
)
|
)
|
||||||
|
|
||||||
func findindex(s []int, e int) (int, bool) {
|
func findindex(s []int, e int) (int, bool) {
|
||||||
@@ -245,35 +245,33 @@ func reduceColumns(conf cfg.Config, data *Tabdata) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: refactor this beast!
|
|
||||||
func colorizeData(conf cfg.Config, output string) string {
|
func colorizeData(conf cfg.Config, output string) string {
|
||||||
|
if !conf.NoColor && !color.IsConsole(os.Stdout) {
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case conf.UseHighlight && color.IsConsole(os.Stdout):
|
case conf.UseHighlight:
|
||||||
highlight := true
|
highlight := true
|
||||||
colorized := ""
|
colorized := ""
|
||||||
first := true
|
style := color.Style{}
|
||||||
|
|
||||||
for _, line := range strings.Split(output, "\n") {
|
for idx, line := range strings.Split(output, "\n") {
|
||||||
if highlight {
|
if idx == 0 {
|
||||||
if first {
|
style = conf.HighlightHdrStyle
|
||||||
// we need to add two spaces to the header line
|
|
||||||
// because tablewriter omits them for some reason
|
|
||||||
// in pprint mode. This doesn't matter as long as
|
|
||||||
// we don't use colorization. But with colors the
|
|
||||||
// missing spaces can be seen.
|
|
||||||
if conf.OutputMode == cfg.ASCII {
|
|
||||||
line += " "
|
|
||||||
}
|
}
|
||||||
|
|
||||||
line = conf.HighlightHdrStyle.Sprint(line)
|
switch highlight {
|
||||||
first = false
|
case true:
|
||||||
} else {
|
if idx > 0 {
|
||||||
line = conf.HighlightStyle.Sprint(line)
|
style = conf.HighlightStyle
|
||||||
}
|
}
|
||||||
} else {
|
case false:
|
||||||
line = conf.NoHighlightStyle.Sprint(line)
|
style = conf.NoHighlightStyle
|
||||||
}
|
}
|
||||||
|
|
||||||
|
line = style.Sprint(line)
|
||||||
|
|
||||||
highlight = !highlight
|
highlight = !highlight
|
||||||
|
|
||||||
colorized += line + "\n"
|
colorized += line + "\n"
|
||||||
@@ -281,7 +279,7 @@ func colorizeData(conf cfg.Config, output string) string {
|
|||||||
|
|
||||||
return colorized
|
return colorized
|
||||||
|
|
||||||
case len(conf.Patterns) > 0 && !conf.NoColor && color.IsConsole(os.Stdout):
|
case len(conf.Patterns) > 0:
|
||||||
out := output
|
out := output
|
||||||
|
|
||||||
for _, re := range conf.Patterns {
|
for _, re := range conf.Patterns {
|
||||||
|
|||||||
@@ -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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -23,6 +23,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
@@ -75,8 +76,8 @@ func printData(writer io.Writer, conf cfg.Config, data *Tabdata) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func output(writer io.Writer, str string) {
|
func output(writer io.Writer, conf cfg.Config, str string) {
|
||||||
_, err := fmt.Fprint(writer, str)
|
_, err := fmt.Fprint(writer, colorizeOutput(conf, str))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to print output: %s", err)
|
log.Fatalf("failed to print output: %s", err)
|
||||||
}
|
}
|
||||||
@@ -138,7 +139,7 @@ func printOrgmodeData(writer io.Writer, conf cfg.Config, data *Tabdata) {
|
|||||||
log.Fatalf("Failed to render table: %s", err)
|
log.Fatalf("Failed to render table: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
output(writer, color.Sprint(colorizeData(conf, tableString.String())))
|
output(writer, conf, color.Sprint(colorizeData(conf, tableString.String())))
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -197,7 +198,7 @@ func printMarkdownData(writer io.Writer, conf cfg.Config, data *Tabdata) {
|
|||||||
log.Fatalf("Failed to render table: %s", err)
|
log.Fatalf("Failed to render table: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
output(writer, color.Sprint(colorizeData(conf, tableString.String())))
|
output(writer, conf, color.Sprint(colorizeData(conf, tableString.String())))
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -254,7 +255,7 @@ func printASCIIData(writer io.Writer, conf cfg.Config, data *Tabdata) {
|
|||||||
log.Fatalf("Failed to render table: %s", err)
|
log.Fatalf("Failed to render table: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
output(writer, color.Sprint(colorizeData(conf, tableString.String())))
|
output(writer, conf, color.Sprint(colorizeData(conf, tableString.String())))
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -275,7 +276,7 @@ func printExtendedData(writer io.Writer, conf cfg.Config, data *Tabdata) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
output(writer, colorizeData(conf, out))
|
output(writer, conf, colorizeData(conf, out))
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -298,7 +299,7 @@ func printShellData(writer io.Writer, data *Tabdata) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// no colorization here
|
// no colorization here
|
||||||
output(writer, out)
|
output(writer, cfg.Config{}, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
func printJsonData(writer io.Writer, data *Tabdata) {
|
func printJsonData(writer io.Writer, data *Tabdata) {
|
||||||
@@ -327,7 +328,7 @@ func printJsonData(writer io.Writer, data *Tabdata) {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
output(writer, string(jsonstr))
|
output(writer, cfg.Config{}, string(jsonstr))
|
||||||
}
|
}
|
||||||
|
|
||||||
func printYamlData(writer io.Writer, data *Tabdata) {
|
func printYamlData(writer io.Writer, data *Tabdata) {
|
||||||
@@ -364,7 +365,7 @@ func printYamlData(writer io.Writer, data *Tabdata) {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
output(writer, string(yamlstr))
|
output(writer, cfg.Config{}, string(yamlstr))
|
||||||
}
|
}
|
||||||
|
|
||||||
func printCSVData(writer io.Writer, conf cfg.Config, data *Tabdata) {
|
func printCSVData(writer io.Writer, conf cfg.Config, data *Tabdata) {
|
||||||
@@ -414,3 +415,23 @@ func printTemplateData(writer io.Writer, conf cfg.Config, data *Tabdata) {
|
|||||||
log.Fatalf("failed to print output: %s", err)
|
log.Fatalf("failed to print output: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func colorizeOutput(conf cfg.Config, input string) string {
|
||||||
|
if len(conf.UseColorizers) > 0 && !conf.NoColor && color.IsConsole(os.Stdout) {
|
||||||
|
for _, colorizer := range conf.UseColorizers {
|
||||||
|
// colorize matching parts of the whole output with given color, if the terminal supports it
|
||||||
|
// color may contain fg:bg or just fg. Color definitions see https://github.com/gookit/color
|
||||||
|
input = colorizer.Search.ReplaceAllStringFunc(input, func(in string) string {
|
||||||
|
col := colorizer.Replace
|
||||||
|
if strings.Contains(col, ":") {
|
||||||
|
parts := strings.Split(col, ":")
|
||||||
|
return color.Sprintf("<fg=%s;bg=%s>%s</>", parts[0], parts[1], in)
|
||||||
|
}
|
||||||
|
|
||||||
|
return color.Sprintf("<fg=%s>%s</>", col, in)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return input
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/araddon/dateparse"
|
|
||||||
"codeberg.org/scip/tablizer/cfg"
|
"codeberg.org/scip/tablizer/cfg"
|
||||||
|
"github.com/araddon/dateparse"
|
||||||
)
|
)
|
||||||
|
|
||||||
func sortTable(conf cfg.Config, data *Tabdata) {
|
func sortTable(conf cfg.Config, data *Tabdata) {
|
||||||
@@ -38,6 +38,12 @@ func sortTable(conf cfg.Config, data *Tabdata) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, column := range conf.UseSortByColumn {
|
||||||
|
if column > len(data.headers) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// actual sorting
|
// actual sorting
|
||||||
sort.SliceStable(data.entries, func(i, j int) bool {
|
sort.SliceStable(data.entries, func(i, j int) bool {
|
||||||
// holds the result of a sort of one column
|
// holds the result of a sort of one column
|
||||||
|
|||||||
BIN
screenshot-highlight-by-pattern.png
Normal file
BIN
screenshot-highlight-by-pattern.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
BIN
screenshot-highlight-lines.png
Normal file
BIN
screenshot-highlight-lines.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 49 KiB |
BIN
screenshot-interactive-mode.png
Normal file
BIN
screenshot-interactive-mode.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 41 KiB |
5
t/testtable6.csv
Normal file
5
t/testtable6.csv
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
Date,Account Number,Subject,Amount
|
||||||
|
20250101,968723487,Dogs Medication Invoice 9919292,-450.00
|
||||||
|
20250103,172747812,Tax return tax id HHD813D/12564H,+912.14
|
||||||
|
20250105,987122711,Car repair order 020123,-299.45
|
||||||
|
20250108,731217273,Rent - 12234 Sunset Blvd,-2960.00
|
||||||
|
22
tablizer.1
22
tablizer.1
@@ -133,7 +133,7 @@
|
|||||||
.\" ========================================================================
|
.\" ========================================================================
|
||||||
.\"
|
.\"
|
||||||
.IX Title "TABLIZER 1"
|
.IX Title "TABLIZER 1"
|
||||||
.TH TABLIZER 1 "2025-12-08" "1" "User Commands"
|
.TH TABLIZER 1 "2026-01-19" "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
|
||||||
@@ -158,6 +158,7 @@ tablizer \- Manipulate tabular output of other programs
|
|||||||
\& \-F, \-\-filter <field[!]=reg> Filter given field with regex, can be used multiple times
|
\& \-F, \-\-filter <field[!]=reg> Filter given field with regex, can be used multiple times
|
||||||
\& \-T, \-\-transpose\-columns string Transpose the speficied columns (separated by ,)
|
\& \-T, \-\-transpose\-columns string Transpose the speficied columns (separated by ,)
|
||||||
\& \-R, \-\-regex\-transposer </from/to/> Apply /search/replace/ regexp to fields given in \-T
|
\& \-R, \-\-regex\-transposer </from/to/> Apply /search/replace/ regexp to fields given in \-T
|
||||||
|
\& \-K \-\-regex\-colorizer /from/color/ colorize pattern of output (color: fg[:bg])
|
||||||
\& \-j, \-\-json Read JSON input (must be array of hashes)
|
\& \-j, \-\-json Read JSON input (must be array of hashes)
|
||||||
\& \-I, \-\-interactive Interactively filter and select rows
|
\& \-I, \-\-interactive Interactively filter and select rows
|
||||||
\& \-g, \-\-auto\-headers Generate headers if there are none present in input
|
\& \-g, \-\-auto\-headers Generate headers if there are none present in input
|
||||||
@@ -682,9 +683,22 @@ black, blue, cyan, darkGray, default, green, lightBlue, lightCyan,
|
|||||||
lightGreen, lightMagenta, lightRed, lightWhite, lightYellow,
|
lightGreen, lightMagenta, lightRed, lightWhite, lightYellow,
|
||||||
magenta, red, white, yellow
|
magenta, red, white, yellow
|
||||||
.PP
|
.PP
|
||||||
The Variables \fB\s-1FG\s0\fR and \fB\s-1BG\s0\fR are being used to highlight matches. The
|
but you may also use \s-1HTML\s0 color codes without the hash sign.
|
||||||
other *FG and *BG variables are for colored table output (enabled with
|
.PP
|
||||||
the \f(CW\*(C`\-L\*(C'\fR parameter).
|
The Variables \fB\s-1FG\s0\fR and \fB\s-1BG\s0\fR are being used to highlight matching
|
||||||
|
rows. The other *FG and *BG variables are for colored table output
|
||||||
|
(enabled with the \f(CW\*(C`\-L\*(C'\fR parameter).
|
||||||
|
.PP
|
||||||
|
You can also use the option \f(CW\*(C`\-K\*(C'\fR to colorize particular patterns, not
|
||||||
|
whole lines. The option can be given multiple times and expects the
|
||||||
|
following parameter:
|
||||||
|
.PP
|
||||||
|
.Vb 1
|
||||||
|
\& \-K \*(Aq/regex/foreground[:background]/
|
||||||
|
.Ve
|
||||||
|
.PP
|
||||||
|
that is, background color is optional. This colorization will applied
|
||||||
|
on top of any previous colorizations, if any.
|
||||||
.PP
|
.PP
|
||||||
Colorization can be turned off completely either by setting the
|
Colorization can be turned off completely either by setting the
|
||||||
parameter \f(CW\*(C`\-N\*(C'\fR or the environment variable \fB\s-1NO_COLOR\s0\fR to a true value.
|
parameter \f(CW\*(C`\-N\*(C'\fR or the environment variable \fB\s-1NO_COLOR\s0\fR to a true value.
|
||||||
|
|||||||
18
tablizer.pod
18
tablizer.pod
@@ -19,6 +19,7 @@ tablizer - Manipulate tabular output of other programs
|
|||||||
-F, --filter <field[!]=reg> Filter given field with regex, can be used multiple times
|
-F, --filter <field[!]=reg> Filter given field with regex, can be used multiple times
|
||||||
-T, --transpose-columns string Transpose the speficied columns (separated by ,)
|
-T, --transpose-columns string Transpose the speficied columns (separated by ,)
|
||||||
-R, --regex-transposer </from/to/> Apply /search/replace/ regexp to fields given in -T
|
-R, --regex-transposer </from/to/> Apply /search/replace/ regexp to fields given in -T
|
||||||
|
-K --regex-colorizer /from/color/ colorize pattern of output (color: fg[:bg])
|
||||||
-j, --json Read JSON input (must be array of hashes)
|
-j, --json Read JSON input (must be array of hashes)
|
||||||
-I, --interactive Interactively filter and select rows
|
-I, --interactive Interactively filter and select rows
|
||||||
-g, --auto-headers Generate headers if there are none present in input
|
-g, --auto-headers Generate headers if there are none present in input
|
||||||
@@ -514,9 +515,20 @@ black, blue, cyan, darkGray, default, green, lightBlue, lightCyan,
|
|||||||
lightGreen, lightMagenta, lightRed, lightWhite, lightYellow,
|
lightGreen, lightMagenta, lightRed, lightWhite, lightYellow,
|
||||||
magenta, red, white, yellow
|
magenta, red, white, yellow
|
||||||
|
|
||||||
The Variables B<FG> and B<BG> are being used to highlight matches. The
|
but you may also use HTML color codes without the hash sign.
|
||||||
other *FG and *BG variables are for colored table output (enabled with
|
|
||||||
the C<-L> parameter).
|
The Variables B<FG> and B<BG> are being used to highlight matching
|
||||||
|
rows. The other *FG and *BG variables are for colored table output
|
||||||
|
(enabled with the C<-L> parameter).
|
||||||
|
|
||||||
|
You can also use the option C<-K> to colorize particular patterns, not
|
||||||
|
whole lines. The option can be given multiple times and expects the
|
||||||
|
following parameter:
|
||||||
|
|
||||||
|
-K '/regex/foreground[:background]/
|
||||||
|
|
||||||
|
that is, background color is optional. This colorization will applied
|
||||||
|
on top of any previous colorizations, if any.
|
||||||
|
|
||||||
Colorization can be turned off completely either by setting the
|
Colorization can be turned off completely either by setting the
|
||||||
parameter C<-N> or the environment variable B<NO_COLOR> to a true value.
|
parameter C<-N> or the environment variable B<NO_COLOR> to a true value.
|
||||||
|
|||||||
Reference in New Issue
Block a user