mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-18 21:11:03 +01:00
optimize ascii tables, use custom style instead of tab inserters (#53)
* optimize ascii tables, use custom style instead of tab inserters
This commit is contained in:
@@ -28,7 +28,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const DefaultSeparator string = `(\s\s+|\t)`
|
const DefaultSeparator string = `(\s\s+|\t)`
|
||||||
const Version string = "v1.4.2"
|
const Version string = "v1.4.3"
|
||||||
const MAXPARTS = 2
|
const MAXPARTS = 2
|
||||||
|
|
||||||
var DefaultConfigfile = os.Getenv("HOME") + "/.config/tablizer/config"
|
var DefaultConfigfile = os.Getenv("HOME") + "/.config/tablizer/config"
|
||||||
|
|||||||
@@ -34,39 +34,3 @@ func (data *Tabdata) CloneEmpty() Tabdata {
|
|||||||
|
|
||||||
return newdata
|
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
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -196,13 +196,15 @@ Simple ASCII table without any borders etc, just like the input we expect
|
|||||||
func printASCIIData(writer io.Writer, conf cfg.Config, data *Tabdata) {
|
func printASCIIData(writer io.Writer, conf cfg.Config, data *Tabdata) {
|
||||||
tableString := &strings.Builder{}
|
tableString := &strings.Builder{}
|
||||||
|
|
||||||
|
styleTSV := tw.NewSymbolCustom("space").WithColumn("\t")
|
||||||
|
|
||||||
table := tablewriter.NewTable(tableString,
|
table := tablewriter.NewTable(tableString,
|
||||||
tablewriter.WithRenderer(
|
tablewriter.WithRenderer(
|
||||||
renderer.NewBlueprint(tw.Rendition{
|
renderer.NewBlueprint(tw.Rendition{
|
||||||
Borders: tw.BorderNone,
|
Borders: tw.BorderNone,
|
||||||
Symbols: tw.NewSymbols(tw.StyleASCII),
|
Symbols: styleTSV,
|
||||||
Settings: tw.Settings{
|
Settings: tw.Settings{
|
||||||
Separators: tw.Separators{BetweenRows: tw.Off, BetweenColumns: tw.Off},
|
Separators: tw.Separators{BetweenRows: tw.Off, BetweenColumns: tw.On},
|
||||||
Lines: tw.Lines{ShowFooterLine: tw.Off, ShowHeaderLine: tw.Off},
|
Lines: tw.Lines{ShowFooterLine: tw.Off, ShowHeaderLine: tw.Off},
|
||||||
},
|
},
|
||||||
})),
|
})),
|
||||||
@@ -231,10 +233,10 @@ func printASCIIData(writer io.Writer, conf cfg.Config, data *Tabdata) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if !conf.NoHeaders {
|
if !conf.NoHeaders {
|
||||||
table.Header(data.TabHeaders())
|
table.Header(data.headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := table.Bulk(data.TabEntries()); err != nil {
|
if err := table.Bulk(data.entries); err != nil {
|
||||||
log.Fatalf("Failed to add data to table renderer: %s", err)
|
log.Fatalf("Failed to add data to table renderer: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user