Compare commits

..

2 Commits

Author SHA1 Message Date
7eea960910 fix #52: get rid of excess newline on ascii tables 2026-03-06 11:43:29 +01:00
T. von Dein
e3b3cb3f70 fix-ascii-spacing (#51)
fix #50: remove excess spaces in normal ascii table output mode
2026-02-19 13:55:04 +01:00
3 changed files with 40 additions and 31 deletions

View File

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

View File

@@ -255,7 +255,16 @@ 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, conf, color.Sprint(colorizeData(conf, tableString.String()))) // we need to trim our output here, because tablewriter appends
// excess whitespace to our rows.
cleanedString := &strings.Builder{}
for _, row := range strings.Split(strings.TrimSpace(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 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,8 +23,8 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/stretchr/testify/assert"
"codeberg.org/scip/tablizer/cfg" "codeberg.org/scip/tablizer/cfg"
"github.com/stretchr/testify/assert"
) )
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`,
}, },
} }