mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-16 20:20:57 +01:00
Update to tableWriter 1.0.6 (#50)
This commit is contained in:
@@ -28,7 +28,7 @@ import (
|
||||
)
|
||||
|
||||
const DefaultSeparator string = `(\s\s+|\t)`
|
||||
const Version string = "v1.4.0"
|
||||
const Version string = "v1.4.2"
|
||||
const MAXPARTS = 2
|
||||
|
||||
var DefaultConfigfile = os.Getenv("HOME") + "/.config/tablizer/config"
|
||||
|
||||
13
go.mod
13
go.mod
@@ -1,6 +1,6 @@
|
||||
module github.com/tlinden/tablizer
|
||||
|
||||
go 1.23
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.5
|
||||
|
||||
@@ -10,7 +10,7 @@ require (
|
||||
github.com/gookit/color v1.5.4
|
||||
github.com/hashicorp/hcl/v2 v2.23.0
|
||||
github.com/lithammer/fuzzysearch v1.1.8
|
||||
github.com/olekukonko/tablewriter v0.0.5
|
||||
github.com/olekukonko/tablewriter v1.0.6
|
||||
github.com/rogpeppe/go-internal v1.14.1
|
||||
github.com/spf13/cobra v1.9.1
|
||||
github.com/tiagomelo/go-clipboard v0.1.2
|
||||
@@ -21,18 +21,23 @@ require (
|
||||
github.com/agext/levenshtein v1.2.3 // indirect
|
||||
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
|
||||
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
|
||||
github.com/fatih/color v1.18.0 // indirect
|
||||
github.com/google/go-cmp v0.6.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
|
||||
github.com/olekukonko/errors v1.1.0 // indirect
|
||||
github.com/olekukonko/ll v0.0.8 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/spf13/pflag v1.0.6 // indirect
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
||||
github.com/zclconf/go-cty v1.13.3 // indirect
|
||||
golang.org/x/mod v0.21.0 // indirect
|
||||
golang.org/x/sync v0.8.0 // indirect
|
||||
golang.org/x/sys v0.26.0 // indirect
|
||||
golang.org/x/sys v0.33.0 // indirect
|
||||
golang.org/x/text v0.11.0 // indirect
|
||||
golang.org/x/tools v0.26.0 // indirect
|
||||
)
|
||||
|
||||
33
go.sum
33
go.sum
@@ -12,6 +12,10 @@ github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6N
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
|
||||
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
|
||||
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
|
||||
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
|
||||
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
|
||||
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
@@ -24,14 +28,37 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4=
|
||||
github.com/lithammer/fuzzysearch v1.1.8/go.mod h1:IdqeyBClc3FFqSzYq/MXESsS4S0FsZ5ajtkr5xPLts4=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
||||
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
||||
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM=
|
||||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
|
||||
github.com/olekukonko/errors v0.0.0-20250405072817-4e6d85265da6 h1:r3FaAI0NZK3hSmtTDrBVREhKULp8oUeqLT5Eyl2mSPo=
|
||||
github.com/olekukonko/errors v0.0.0-20250405072817-4e6d85265da6/go.mod h1:ppzxA5jBKcO1vIpCXQ9ZqgDh8iwODz6OXIGKU8r5m4Y=
|
||||
github.com/olekukonko/errors v1.1.0 h1:RNuGIh15QdDenh+hNvKrJkmxxjV4hcS50Db478Ou5sM=
|
||||
github.com/olekukonko/errors v1.1.0/go.mod h1:ppzxA5jBKcO1vIpCXQ9ZqgDh8iwODz6OXIGKU8r5m4Y=
|
||||
github.com/olekukonko/ll v0.0.6-0.20250511102614-9564773e9d27 h1:LgDwLQDELPB6wMOx1x4DSXnH2pjQNDKFgqv2inJuiAU=
|
||||
github.com/olekukonko/ll v0.0.6-0.20250511102614-9564773e9d27/go.mod h1:En+sEW0JNETl26+K8eZ6/W4UQ7CYSrrgg/EdIYT2H8g=
|
||||
github.com/olekukonko/ll v0.0.8 h1:sbGZ1Fx4QxJXEqL/6IG8GEFnYojUSQ45dJVwN2FH2fc=
|
||||
github.com/olekukonko/ll v0.0.8/go.mod h1:En+sEW0JNETl26+K8eZ6/W4UQ7CYSrrgg/EdIYT2H8g=
|
||||
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
||||
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
||||
github.com/olekukonko/tablewriter v1.0.2 h1:nxz/j28kPYQUuc4veIv3Ymmef7gHKn8rhr42aauENnk=
|
||||
github.com/olekukonko/tablewriter v1.0.2/go.mod h1:eUa4ArVhHJYomS27xrJB/GyLtnzKKVkZeLM6/MNO+pA=
|
||||
github.com/olekukonko/tablewriter v1.0.4 h1:Lnz32TW+q/MQhA4qwhIyLA+j5hZ3dcNpZrcpPC+4iaM=
|
||||
github.com/olekukonko/tablewriter v1.0.4/go.mod h1:eUa4ArVhHJYomS27xrJB/GyLtnzKKVkZeLM6/MNO+pA=
|
||||
github.com/olekukonko/tablewriter v1.0.6 h1:/T45mIHc5hcEvibgzBzvMy7ruT+RjgoQRvkHbnl6OWA=
|
||||
github.com/olekukonko/tablewriter v1.0.6/go.mod h1:SJ0MV1aHb/89fLcsBMXMp30Xg3g5eGoOUu0RptEk4AU=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
@@ -39,6 +66,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
|
||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
|
||||
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
@@ -82,9 +111,13 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
||||
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
|
||||
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
|
||||
@@ -34,3 +34,39 @@ func (data *Tabdata) CloneEmpty() Tabdata {
|
||||
|
||||
return newdata
|
||||
}
|
||||
|
||||
// add a TAB (\t) in front of every cell, but not the first
|
||||
func (data *Tabdata) TabEntries() [][]string {
|
||||
newentries := make([][]string, len(data.entries))
|
||||
|
||||
for rowidx, row := range data.entries {
|
||||
newentries[rowidx] = make([]string, len(row))
|
||||
|
||||
for colidx, cell := range row {
|
||||
switch colidx {
|
||||
case 0:
|
||||
newentries[rowidx][colidx] = cell
|
||||
default:
|
||||
newentries[rowidx][colidx] = "\t" + cell
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return newentries
|
||||
}
|
||||
|
||||
// add a TAB (\t) in front of every header, but not the first
|
||||
func (data *Tabdata) TabHeaders() []string {
|
||||
newheaders := make([]string, len(data.headers))
|
||||
|
||||
for colidx, cell := range data.headers {
|
||||
switch colidx {
|
||||
case 0:
|
||||
newheaders[colidx] = cell
|
||||
default:
|
||||
newheaders[colidx] = "\t" + cell
|
||||
}
|
||||
}
|
||||
|
||||
return newheaders
|
||||
}
|
||||
|
||||
@@ -254,17 +254,6 @@ func reduceColumns(conf cfg.Config, data *Tabdata) {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: remove this when we only use Tablewriter and strip in ParseFile()!
|
||||
func trimRow(row []string) []string {
|
||||
var fixedrow = make([]string, len(row))
|
||||
|
||||
for idx, cell := range row {
|
||||
fixedrow[idx] = strings.TrimSpace(cell)
|
||||
}
|
||||
|
||||
return fixedrow
|
||||
}
|
||||
|
||||
// FIXME: refactor this beast!
|
||||
func colorizeData(conf cfg.Config, output string) string {
|
||||
switch {
|
||||
|
||||
184
lib/printer.go
184
lib/printer.go
@@ -22,12 +22,13 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gookit/color"
|
||||
"github.com/olekukonko/tablewriter"
|
||||
"github.com/olekukonko/tablewriter/renderer"
|
||||
"github.com/olekukonko/tablewriter/tw"
|
||||
"github.com/tlinden/tablizer/cfg"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
@@ -76,36 +77,58 @@ Emacs org-mode compatible table (also orgtbl-mode)
|
||||
*/
|
||||
func printOrgmodeData(writer io.Writer, conf cfg.Config, data *Tabdata) {
|
||||
tableString := &strings.Builder{}
|
||||
table := tablewriter.NewWriter(tableString)
|
||||
|
||||
table := tablewriter.NewTable(tableString,
|
||||
tablewriter.WithRenderer(
|
||||
renderer.NewBlueprint(
|
||||
tw.Rendition{
|
||||
Borders: tw.Border{
|
||||
Left: tw.On,
|
||||
Right: tw.On,
|
||||
Top: tw.On,
|
||||
Bottom: tw.On,
|
||||
},
|
||||
Settings: tw.Settings{
|
||||
Separators: tw.Separators{
|
||||
ShowHeader: tw.On,
|
||||
ShowFooter: tw.Off,
|
||||
BetweenRows: tw.Off,
|
||||
BetweenColumns: 0,
|
||||
},
|
||||
},
|
||||
Symbols: tw.NewSymbols(tw.StyleASCII),
|
||||
})),
|
||||
|
||||
tablewriter.WithConfig(
|
||||
tablewriter.Config{
|
||||
Header: tw.CellConfig{
|
||||
Formatting: tw.CellFormatting{
|
||||
Alignment: tw.AlignLeft,
|
||||
AutoFormat: tw.Off,
|
||||
},
|
||||
},
|
||||
Row: tw.CellConfig{
|
||||
Formatting: tw.CellFormatting{
|
||||
Alignment: tw.AlignLeft,
|
||||
},
|
||||
},
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
if !conf.NoHeaders {
|
||||
table.SetHeader(data.headers)
|
||||
table.Header(data.headers)
|
||||
}
|
||||
|
||||
for _, row := range data.entries {
|
||||
table.Append(trimRow(row))
|
||||
if err := table.Bulk(data.entries); err != nil {
|
||||
log.Fatalf("Failed to add data to table renderer: %s", err)
|
||||
}
|
||||
|
||||
table.Render()
|
||||
if err := table.Render(); err != nil {
|
||||
log.Fatalf("Failed to render table: %s", err)
|
||||
}
|
||||
|
||||
/* fix output for org-mode (orgtbl)
|
||||
tableWriter output:
|
||||
+------+------+
|
||||
| cell | cell |
|
||||
+------+------+
|
||||
|
||||
Needed for org-mode compatibility:
|
||||
|------+------|
|
||||
| cell | cell |
|
||||
|------+------|
|
||||
*/
|
||||
leftR := regexp.MustCompile(`(?m)^\\+`)
|
||||
rightR := regexp.MustCompile(`\\+(?m)$`)
|
||||
|
||||
output(writer, color.Sprint(
|
||||
colorizeData(conf,
|
||||
rightR.ReplaceAllString(
|
||||
leftR.ReplaceAllString(tableString.String(), "|"), "|"))))
|
||||
output(writer, color.Sprint(colorizeData(conf, tableString.String())))
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -113,20 +136,57 @@ Markdown table
|
||||
*/
|
||||
func printMarkdownData(writer io.Writer, conf cfg.Config, data *Tabdata) {
|
||||
tableString := &strings.Builder{}
|
||||
table := tablewriter.NewWriter(tableString)
|
||||
|
||||
table := tablewriter.NewTable(tableString,
|
||||
tablewriter.WithRenderer(
|
||||
renderer.NewBlueprint(
|
||||
tw.Rendition{
|
||||
Borders: tw.Border{
|
||||
Left: tw.On,
|
||||
Right: tw.On,
|
||||
Top: tw.Off,
|
||||
Bottom: tw.Off,
|
||||
},
|
||||
Settings: tw.Settings{
|
||||
Separators: tw.Separators{
|
||||
ShowHeader: tw.On,
|
||||
ShowFooter: tw.Off,
|
||||
BetweenRows: tw.Off,
|
||||
BetweenColumns: 0,
|
||||
},
|
||||
},
|
||||
Symbols: tw.NewSymbols(tw.StyleMarkdown),
|
||||
})),
|
||||
|
||||
tablewriter.WithConfig(
|
||||
tablewriter.Config{
|
||||
Header: tw.CellConfig{
|
||||
Formatting: tw.CellFormatting{
|
||||
Alignment: tw.AlignLeft,
|
||||
AutoFormat: tw.Off,
|
||||
},
|
||||
},
|
||||
Row: tw.CellConfig{
|
||||
Formatting: tw.CellFormatting{
|
||||
Alignment: tw.AlignLeft,
|
||||
},
|
||||
},
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
if !conf.NoHeaders {
|
||||
table.SetHeader(data.headers)
|
||||
table.Header(data.headers)
|
||||
}
|
||||
|
||||
for _, row := range data.entries {
|
||||
table.Append(trimRow(row))
|
||||
if err := table.Bulk(data.entries); err != nil {
|
||||
log.Fatalf("Failed to add data to table renderer: %s", err)
|
||||
}
|
||||
|
||||
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
|
||||
table.SetCenterSeparator("|")
|
||||
if err := table.Render(); err != nil {
|
||||
log.Fatalf("Failed to render table: %s", err)
|
||||
}
|
||||
|
||||
table.Render()
|
||||
output(writer, color.Sprint(colorizeData(conf, tableString.String())))
|
||||
}
|
||||
|
||||
@@ -135,33 +195,53 @@ Simple ASCII table without any borders etc, just like the input we expect
|
||||
*/
|
||||
func printASCIIData(writer io.Writer, conf cfg.Config, data *Tabdata) {
|
||||
tableString := &strings.Builder{}
|
||||
table := tablewriter.NewWriter(tableString)
|
||||
|
||||
table := tablewriter.NewTable(tableString,
|
||||
tablewriter.WithRenderer(
|
||||
renderer.NewBlueprint(tw.Rendition{
|
||||
Borders: tw.BorderNone,
|
||||
Symbols: tw.NewSymbols(tw.StyleASCII),
|
||||
Settings: tw.Settings{
|
||||
Separators: tw.Separators{BetweenRows: tw.Off, BetweenColumns: tw.Off},
|
||||
Lines: tw.Lines{ShowFooterLine: tw.Off, ShowHeaderLine: tw.Off},
|
||||
},
|
||||
})),
|
||||
tablewriter.WithConfig(tablewriter.Config{
|
||||
Header: tw.CellConfig{
|
||||
Formatting: tw.CellFormatting{
|
||||
AutoFormat: tw.Off,
|
||||
},
|
||||
Padding: tw.CellPadding{
|
||||
Global: tw.Padding{Left: "", Right: ""},
|
||||
},
|
||||
},
|
||||
Row: tw.CellConfig{
|
||||
Formatting: tw.CellFormatting{
|
||||
AutoWrap: tw.WrapNone,
|
||||
Alignment: tw.AlignLeft,
|
||||
},
|
||||
Padding: tw.CellPadding{
|
||||
Global: tw.Padding{Left: "", Right: ""},
|
||||
},
|
||||
},
|
||||
|
||||
Debug: true,
|
||||
}),
|
||||
tablewriter.WithPadding(tw.PaddingNone),
|
||||
)
|
||||
|
||||
if !conf.NoHeaders {
|
||||
table.SetHeader(data.headers)
|
||||
table.Header(data.TabHeaders())
|
||||
}
|
||||
|
||||
table.AppendBulk(data.entries)
|
||||
|
||||
table.SetAutoWrapText(false)
|
||||
table.SetAutoFormatHeaders(true)
|
||||
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
|
||||
table.SetAlignment(tablewriter.ALIGN_LEFT)
|
||||
table.SetCenterSeparator("")
|
||||
table.SetColumnSeparator("")
|
||||
table.SetRowSeparator("")
|
||||
table.SetHeaderLine(false)
|
||||
table.SetBorder(false)
|
||||
table.SetNoWhiteSpace(true)
|
||||
|
||||
if !conf.UseHighlight {
|
||||
// the tabs destroy the highlighting
|
||||
table.SetTablePadding("\t") // pad with tabs
|
||||
} else {
|
||||
table.SetTablePadding(" ")
|
||||
if err := table.Bulk(data.TabEntries()); err != nil {
|
||||
log.Fatalf("Failed to add data to table renderer: %s", err)
|
||||
}
|
||||
|
||||
if err := table.Render(); err != nil {
|
||||
log.Fatalf("Failed to render table: %s", err)
|
||||
}
|
||||
|
||||
table.Render()
|
||||
output(writer, color.Sprint(colorizeData(conf, tableString.String())))
|
||||
}
|
||||
|
||||
|
||||
@@ -77,9 +77,9 @@ var tests = []struct {
|
||||
numberize: true,
|
||||
name: "default",
|
||||
expect: `
|
||||
NAME(1) DURATION(2) COUNT(3) WHEN(4)
|
||||
beta 1d10h5m1s 33 3/1/2014
|
||||
alpha 4h35m 170 2013-Feb-03
|
||||
NAME(1) DURATION(2) COUNT(3) WHEN(4)
|
||||
beta 1d10h5m1s 33 3/1/2014
|
||||
alpha 4h35m 170 2013-Feb-03
|
||||
ceta 33d12h 9 06/Jan/2008 15:04:05 -0700`,
|
||||
},
|
||||
{
|
||||
@@ -98,11 +98,11 @@ ceta,33d12h,9,06/Jan/2008 15:04:05 -0700`,
|
||||
mode: cfg.Orgtbl,
|
||||
expect: `
|
||||
+---------+-------------+----------+----------------------------+
|
||||
| NAME(1) | DURATION(2) | COUNT(3) | WHEN(4) |
|
||||
| NAME(1) | DURATION(2) | COUNT(3) | WHEN(4) |
|
||||
+---------+-------------+----------+----------------------------+
|
||||
| beta | 1d10h5m1s | 33 | 3/1/2014 |
|
||||
| alpha | 4h35m | 170 | 2013-Feb-03 |
|
||||
| ceta | 33d12h | 9 | 06/Jan/2008 15:04:05 -0700 |
|
||||
| beta | 1d10h5m1s | 33 | 3/1/2014 |
|
||||
| alpha | 4h35m | 170 | 2013-Feb-03 |
|
||||
| ceta | 33d12h | 9 | 06/Jan/2008 15:04:05 -0700 |
|
||||
+---------+-------------+----------+----------------------------+`,
|
||||
},
|
||||
{
|
||||
@@ -110,11 +110,11 @@ ceta,33d12h,9,06/Jan/2008 15:04:05 -0700`,
|
||||
mode: cfg.Markdown,
|
||||
numberize: true,
|
||||
expect: `
|
||||
| NAME(1) | DURATION(2) | COUNT(3) | WHEN(4) |
|
||||
| NAME(1) | DURATION(2) | COUNT(3) | WHEN(4) |
|
||||
|---------|-------------|----------|----------------------------|
|
||||
| beta | 1d10h5m1s | 33 | 3/1/2014 |
|
||||
| alpha | 4h35m | 170 | 2013-Feb-03 |
|
||||
| ceta | 33d12h | 9 | 06/Jan/2008 15:04:05 -0700 |`,
|
||||
| beta | 1d10h5m1s | 33 | 3/1/2014 |
|
||||
| alpha | 4h35m | 170 | 2013-Feb-03 |
|
||||
| ceta | 33d12h | 9 | 06/Jan/2008 15:04:05 -0700 |`,
|
||||
},
|
||||
{
|
||||
name: "shell",
|
||||
@@ -173,9 +173,9 @@ DURATION(2): 33d12h
|
||||
numberize: true,
|
||||
desc: false,
|
||||
expect: `
|
||||
NAME(1) DURATION(2) COUNT(3) WHEN(4)
|
||||
ceta 33d12h 9 06/Jan/2008 15:04:05 -0700
|
||||
beta 1d10h5m1s 33 3/1/2014
|
||||
NAME(1) DURATION(2) COUNT(3) WHEN(4)
|
||||
ceta 33d12h 9 06/Jan/2008 15:04:05 -0700
|
||||
beta 1d10h5m1s 33 3/1/2014
|
||||
alpha 4h35m 170 2013-Feb-03`,
|
||||
},
|
||||
{
|
||||
@@ -185,9 +185,9 @@ alpha 4h35m 170 2013-Feb-03`,
|
||||
desc: false,
|
||||
numberize: true,
|
||||
expect: `
|
||||
NAME(1) DURATION(2) COUNT(3) WHEN(4)
|
||||
ceta 33d12h 9 06/Jan/2008 15:04:05 -0700
|
||||
alpha 4h35m 170 2013-Feb-03
|
||||
NAME(1) DURATION(2) COUNT(3) WHEN(4)
|
||||
ceta 33d12h 9 06/Jan/2008 15:04:05 -0700
|
||||
alpha 4h35m 170 2013-Feb-03
|
||||
beta 1d10h5m1s 33 3/1/2014`,
|
||||
},
|
||||
{
|
||||
@@ -197,9 +197,9 @@ beta 1d10h5m1s 33 3/1/2014`,
|
||||
numberize: true,
|
||||
desc: false,
|
||||
expect: `
|
||||
NAME(1) DURATION(2) COUNT(3) WHEN(4)
|
||||
alpha 4h35m 170 2013-Feb-03
|
||||
beta 1d10h5m1s 33 3/1/2014
|
||||
NAME(1) DURATION(2) COUNT(3) WHEN(4)
|
||||
alpha 4h35m 170 2013-Feb-03
|
||||
beta 1d10h5m1s 33 3/1/2014
|
||||
ceta 33d12h 9 06/Jan/2008 15:04:05 -0700`,
|
||||
},
|
||||
|
||||
@@ -210,9 +210,9 @@ ceta 33d12h 9 06/Jan/2008 15:04:05 -0700`,
|
||||
numberize: true,
|
||||
usecolstr: "1,4",
|
||||
expect: `
|
||||
NAME(1) WHEN(4)
|
||||
beta 3/1/2014
|
||||
alpha 2013-Feb-03
|
||||
NAME(1) WHEN(4)
|
||||
beta 3/1/2014
|
||||
alpha 2013-Feb-03
|
||||
ceta 06/Jan/2008 15:04:05 -0700`,
|
||||
},
|
||||
{
|
||||
@@ -221,9 +221,9 @@ ceta 06/Jan/2008 15:04:05 -0700`,
|
||||
numberize: true,
|
||||
usecolstr: "2",
|
||||
expect: `
|
||||
DURATION(2)
|
||||
1d10h5m1s
|
||||
4h35m
|
||||
DURATION(2)
|
||||
1d10h5m1s
|
||||
4h35m
|
||||
33d12h`,
|
||||
},
|
||||
{
|
||||
@@ -232,9 +232,9 @@ DURATION(2)
|
||||
numberize: true,
|
||||
usecolstr: "3",
|
||||
expect: `
|
||||
COUNT(3)
|
||||
33
|
||||
170
|
||||
COUNT(3)
|
||||
33
|
||||
170
|
||||
9`,
|
||||
},
|
||||
{
|
||||
@@ -244,9 +244,9 @@ COUNT(3)
|
||||
numberize: true,
|
||||
usecolstr: "1,3",
|
||||
expect: `
|
||||
NAME(1) COUNT(3)
|
||||
beta 33
|
||||
alpha 170
|
||||
NAME(1) COUNT(3)
|
||||
beta 33
|
||||
alpha 170
|
||||
ceta 9`,
|
||||
},
|
||||
{
|
||||
@@ -255,9 +255,9 @@ ceta 9`,
|
||||
numberize: true,
|
||||
usecolstr: "2,4",
|
||||
expect: `
|
||||
DURATION(2) WHEN(4)
|
||||
1d10h5m1s 3/1/2014
|
||||
4h35m 2013-Feb-03
|
||||
DURATION(2) WHEN(4)
|
||||
1d10h5m1s 3/1/2014
|
||||
4h35m 2013-Feb-03
|
||||
33d12h 06/Jan/2008 15:04:05 -0700`,
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user