Compare commits

..

7 Commits

Author SHA1 Message Date
1f35389ed9 remove recursive Sprintf() 2026-01-19 14:02:01 +01:00
cc59586cee bump version 2026-01-19 13:57:55 +01:00
dcf17238a6 oops :) 2026-01-19 13:57:30 +01:00
cebd778872 adjust short help text 2026-01-19 13:55:43 +01:00
473a009a86 refactored line colorizer 2026-01-19 13:54:05 +01:00
bba477f56d updated documentation 2026-01-19 13:53:57 +01:00
cb3921458a add output colorization support using regexes 2026-01-19 13:38:37 +01:00
8 changed files with 37 additions and 50 deletions

View File

@@ -18,9 +18,6 @@ builds:
- windows - windows
- darwin - darwin
- freebsd - freebsd
goarch:
- amd64
- arm64
archives: archives:
- formats: [tar.gz] - formats: [tar.gz]

View File

@@ -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 (maybe char, string or :class:) -s, --separator <string> Custom field separator
-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
-g, --auto-headers Generate headers if there are none present in input --auto-headers Generate headers if there are none present in input
-x, --custom-headers a,b,... Use custom headers, separated by comma --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,14 +63,12 @@ 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
@@ -178,7 +176,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 `-I`, where There's also an interactive mode, invoked with the option B<-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" />

View File

@@ -28,7 +28,7 @@ import (
) )
const ( const (
Version = "v1.6.1" Version = "v1.6.0"
MAXPARTS = 2 MAXPARTS = 2
) )

View File

@@ -255,15 +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)
} }
// we need to trim our output here, because tablewriter appends output(writer, conf, color.Sprint(colorizeData(conf, tableString.String())))
// excess whitespace to our rows.
cleanedString := &strings.Builder{}
for _, row := range strings.Split(tableString.String(), "\n") {
cleanedString.WriteString(strings.TrimSpace(row))
cleanedString.WriteString("\n")
}
output(writer, conf, color.Sprint(colorizeData(conf, cleanedString.String())))
} }
/* /*

View File

@@ -1,5 +1,5 @@
/* /*
Copyright © 2022-2026 Thomas von Dein Copyright © 2022 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,8 +23,8 @@ import (
"strings" "strings"
"testing" "testing"
"codeberg.org/scip/tablizer/cfg"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"codeberg.org/scip/tablizer/cfg"
) )
func newData() Tabdata { func newData() Tabdata {
@@ -78,9 +78,9 @@ var tests = []struct {
numberize: true, numberize: true,
name: "default", name: "default",
expect: ` expect: `
NAME(1) DURATION(2) COUNT(3) WHEN(4) NAME(1) DURATION(2) COUNT(3) WHEN(4)
beta 1d10h5m1s 33 3/1/2014 beta 1d10h5m1s 33 3/1/2014
alpha 4h35m 170 2013-Feb-03 alpha 4h35m 170 2013-Feb-03
ceta 33d12h 9 06/Jan/2008 15:04:05 -0700`, ceta 33d12h 9 06/Jan/2008 15:04:05 -0700`,
}, },
{ {
@@ -199,9 +199,9 @@ DURATION(2): 33d12h
numberize: true, numberize: true,
desc: false, desc: false,
expect: ` expect: `
NAME(1) DURATION(2) COUNT(3) WHEN(4) NAME(1) DURATION(2) COUNT(3) WHEN(4)
ceta 33d12h 9 06/Jan/2008 15:04:05 -0700 ceta 33d12h 9 06/Jan/2008 15:04:05 -0700
beta 1d10h5m1s 33 3/1/2014 beta 1d10h5m1s 33 3/1/2014
alpha 4h35m 170 2013-Feb-03`, alpha 4h35m 170 2013-Feb-03`,
}, },
{ {
@@ -211,9 +211,9 @@ alpha 4h35m 170 2013-Feb-03`,
desc: false, desc: false,
numberize: true, numberize: true,
expect: ` expect: `
NAME(1) DURATION(2) COUNT(3) WHEN(4) NAME(1) DURATION(2) COUNT(3) WHEN(4)
ceta 33d12h 9 06/Jan/2008 15:04:05 -0700 ceta 33d12h 9 06/Jan/2008 15:04:05 -0700
alpha 4h35m 170 2013-Feb-03 alpha 4h35m 170 2013-Feb-03
beta 1d10h5m1s 33 3/1/2014`, beta 1d10h5m1s 33 3/1/2014`,
}, },
{ {
@@ -223,9 +223,9 @@ beta 1d10h5m1s 33 3/1/2014`,
numberize: true, numberize: true,
desc: false, desc: false,
expect: ` expect: `
NAME(1) DURATION(2) COUNT(3) WHEN(4) NAME(1) DURATION(2) COUNT(3) WHEN(4)
alpha 4h35m 170 2013-Feb-03 alpha 4h35m 170 2013-Feb-03
beta 1d10h5m1s 33 3/1/2014 beta 1d10h5m1s 33 3/1/2014
ceta 33d12h 9 06/Jan/2008 15:04:05 -0700`, ceta 33d12h 9 06/Jan/2008 15:04:05 -0700`,
}, },
@@ -236,9 +236,9 @@ ceta 33d12h 9 06/Jan/2008 15:04:05 -0700`,
numberize: true, numberize: true,
usecolstr: "1,4", usecolstr: "1,4",
expect: ` expect: `
NAME(1) WHEN(4) NAME(1) WHEN(4)
beta 3/1/2014 beta 3/1/2014
alpha 2013-Feb-03 alpha 2013-Feb-03
ceta 06/Jan/2008 15:04:05 -0700`, ceta 06/Jan/2008 15:04:05 -0700`,
}, },
{ {
@@ -247,9 +247,9 @@ ceta 06/Jan/2008 15:04:05 -0700`,
numberize: true, numberize: true,
usecolstr: "2", usecolstr: "2",
expect: ` expect: `
DURATION(2) DURATION(2)
1d10h5m1s 1d10h5m1s
4h35m 4h35m
33d12h`, 33d12h`,
}, },
{ {
@@ -258,9 +258,9 @@ DURATION(2)
numberize: true, numberize: true,
usecolstr: "3", usecolstr: "3",
expect: ` expect: `
COUNT(3) COUNT(3)
33 33
170 170
9`, 9`,
}, },
{ {
@@ -270,9 +270,9 @@ COUNT(3)
numberize: true, numberize: true,
usecolstr: "1,3", usecolstr: "1,3",
expect: ` expect: `
NAME(1) COUNT(3) NAME(1) COUNT(3)
beta 33 beta 33
alpha 170 alpha 170
ceta 9`, ceta 9`,
}, },
{ {
@@ -281,9 +281,9 @@ ceta 9`,
numberize: true, numberize: true,
usecolstr: "2,4", usecolstr: "2,4",
expect: ` expect: `
DURATION(2) WHEN(4) DURATION(2) WHEN(4)
1d10h5m1s 3/1/2014 1d10h5m1s 3/1/2014
4h35m 2013-Feb-03 4h35m 2013-Feb-03
33d12h 06/Jan/2008 15:04:05 -0700`, 33d12h 06/Jan/2008 15:04:05 -0700`,
}, },
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB