mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-17 12:31:06 +01:00
use pointer of Tabdata, so there's only 1 copy around
This commit is contained in:
@@ -76,3 +76,13 @@ func PrepareModeFlags() error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func trimRow(row []string) []string {
|
||||||
|
// FIXME: remove this when we only use Tablewriter and strip in ParseFile()!
|
||||||
|
var fixedrow []string
|
||||||
|
for _, cell := range row {
|
||||||
|
fixedrow = append(fixedrow, strings.TrimSpace(cell))
|
||||||
|
}
|
||||||
|
|
||||||
|
return fixedrow
|
||||||
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ func ProcessFiles(args []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
printData(data)
|
printData(&data)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -25,14 +25,15 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func printData(data Tabdata) {
|
func printData(data *Tabdata) {
|
||||||
// prepare headers
|
// prepare headers: add numbers to headers
|
||||||
// FIXME: maybe do this already in parseFile()?
|
|
||||||
if !NoNumbering {
|
if !NoNumbering {
|
||||||
numberedHeaders := []string{}
|
numberedHeaders := []string{}
|
||||||
for i, head := range data.headers {
|
for i, head := range data.headers {
|
||||||
if len(Columns) > 0 {
|
if len(Columns) > 0 {
|
||||||
|
// -c specified
|
||||||
if !contains(UseColumns, i+1) {
|
if !contains(UseColumns, i+1) {
|
||||||
|
// ignore this one
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,20 +74,10 @@ func printData(data Tabdata) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func trimRow(row []string) []string {
|
|
||||||
// FIXME: remove this when we only use Tablewriter and strip in ParseFile()!
|
|
||||||
var fixedrow []string
|
|
||||||
for _, cell := range row {
|
|
||||||
fixedrow = append(fixedrow, strings.TrimSpace(cell))
|
|
||||||
}
|
|
||||||
|
|
||||||
return fixedrow
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Emacs org-mode compatible table (also orgtbl-mode)
|
Emacs org-mode compatible table (also orgtbl-mode)
|
||||||
*/
|
*/
|
||||||
func printOrgmodeData(data Tabdata) {
|
func printOrgmodeData(data *Tabdata) {
|
||||||
tableString := &strings.Builder{}
|
tableString := &strings.Builder{}
|
||||||
table := tablewriter.NewWriter(tableString)
|
table := tablewriter.NewWriter(tableString)
|
||||||
|
|
||||||
@@ -118,7 +109,7 @@ func printOrgmodeData(data Tabdata) {
|
|||||||
/*
|
/*
|
||||||
Markdown table
|
Markdown table
|
||||||
*/
|
*/
|
||||||
func printMarkdownData(data Tabdata) {
|
func printMarkdownData(data *Tabdata) {
|
||||||
table := tablewriter.NewWriter(os.Stdout)
|
table := tablewriter.NewWriter(os.Stdout)
|
||||||
|
|
||||||
table.SetHeader(data.headers)
|
table.SetHeader(data.headers)
|
||||||
@@ -136,7 +127,7 @@ func printMarkdownData(data Tabdata) {
|
|||||||
/*
|
/*
|
||||||
Simple ASCII table without any borders etc, just like the input we expect
|
Simple ASCII table without any borders etc, just like the input we expect
|
||||||
*/
|
*/
|
||||||
func printAsciiData(data Tabdata) {
|
func printAsciiData(data *Tabdata) {
|
||||||
table := tablewriter.NewWriter(os.Stdout)
|
table := tablewriter.NewWriter(os.Stdout)
|
||||||
|
|
||||||
table.SetHeader(data.headers)
|
table.SetHeader(data.headers)
|
||||||
@@ -164,7 +155,7 @@ func printAsciiData(data Tabdata) {
|
|||||||
/*
|
/*
|
||||||
We simulate the \x command of psql (the PostgreSQL client)
|
We simulate the \x command of psql (the PostgreSQL client)
|
||||||
*/
|
*/
|
||||||
func printExtendedData(data Tabdata) {
|
func printExtendedData(data *Tabdata) {
|
||||||
// needed for data output
|
// needed for data output
|
||||||
format := fmt.Sprintf("%%%ds: %%s\n", data.maxwidthHeader) // FIXME: re-calculate if -c has been set
|
format := fmt.Sprintf("%%%ds: %%s\n", data.maxwidthHeader) // FIXME: re-calculate if -c has been set
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ asd igig cxxxncnc
|
|||||||
t.Errorf("Parser returned error: %s\nData processed so far: %+v", err, data)
|
t.Errorf("Parser returned error: %s\nData processed so far: %+v", err, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
printData(data)
|
printData(&data)
|
||||||
|
|
||||||
buf := make([]byte, 1024)
|
buf := make([]byte, 1024)
|
||||||
n, err := r.Read(buf)
|
n, err := r.Read(buf)
|
||||||
|
|||||||
Reference in New Issue
Block a user