From 1acbdbc67466ab641a17fa0a1c0066f2be1708d8 Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Fri, 21 Apr 2023 09:52:05 +0200 Subject: [PATCH] added --no-headers flag to disable header display in tabular modes --- cfg/config.go | 3 ++- cmd/root.go | 1 + cmd/tablizer.go | 7 +++++++ lib/printer.go | 26 ++++++++++++++------------ tablizer.1 | 8 +++++++- tablizer.pod | 6 ++++++ 6 files changed, 37 insertions(+), 14 deletions(-) diff --git a/cfg/config.go b/cfg/config.go index 3707578..82ef423 100644 --- a/cfg/config.go +++ b/cfg/config.go @@ -25,13 +25,14 @@ import ( ) const DefaultSeparator string = `(\s\s+|\t)` -const Version string = "v1.0.14" +const Version string = "v1.0.15" var VERSION string // maintained by -x type Config struct { Debug bool NoNumbering bool + NoHeaders bool Columns string UseColumns []int Separator string diff --git a/cmd/root.go b/cmd/root.go index 8b430da..9a68deb 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -105,6 +105,7 @@ func Execute() { // options rootCmd.PersistentFlags().BoolVarP(&conf.Debug, "debug", "d", false, "Enable debugging") rootCmd.PersistentFlags().BoolVarP(&conf.NoNumbering, "no-numbering", "n", false, "Disable header numbering") + rootCmd.PersistentFlags().BoolVarP(&conf.NoHeaders, "no-headers", "", false, "Disable header display") rootCmd.PersistentFlags().BoolVarP(&conf.NoColor, "no-color", "N", false, "Disable pattern highlighting") rootCmd.PersistentFlags().BoolVarP(&ShowVersion, "version", "V", false, "Print program version") rootCmd.PersistentFlags().BoolVarP(&conf.InvertMatch, "invert-match", "v", false, "select non-matching rows") diff --git a/cmd/tablizer.go b/cmd/tablizer.go index 21b95ab..210e620 100644 --- a/cmd/tablizer.go +++ b/cmd/tablizer.go @@ -13,6 +13,7 @@ SYNOPSIS -v, --invert-match select non-matching rows -n, --no-numbering Disable header numbering -N, --no-color Disable pattern highlighting + --no-headers Disable headers display -s, --separator string Custom field separator -k, --sort-by int Sort by column (default: 1) @@ -87,6 +88,11 @@ DESCRIPTION The numbering can be suppressed by using the -n option. + By default tablizer shows a header containing the names of each column. + This can be disabled using the --no-headers option. Be aware that this + only affects tabular output modes. Shell, Extended, Yaml and CSV output + modes always use the column names. + By default, if a pattern has been speficied, matches will be highlighted. You can disable this behavior with the -N option. @@ -293,6 +299,7 @@ Operational Flags: -v, --invert-match select non-matching rows -n, --no-numbering Disable header numbering -N, --no-color Disable pattern highlighting + --no-headers Disable headers display -s, --separator string Custom field separator -k, --sort-by int Sort by column (default: 1) diff --git a/lib/printer.go b/lib/printer.go index 06a619a..1d76222 100644 --- a/lib/printer.go +++ b/lib/printer.go @@ -69,13 +69,15 @@ func output(w io.Writer, str string) { } /* - Emacs org-mode compatible table (also orgtbl-mode) +Emacs org-mode compatible table (also orgtbl-mode) */ func printOrgmodeData(w io.Writer, c cfg.Config, data *Tabdata) { tableString := &strings.Builder{} table := tablewriter.NewWriter(tableString) - table.SetHeader(data.headers) + if !c.NoHeaders { + table.SetHeader(data.headers) + } for _, row := range data.entries { table.Append(trimRow(row)) @@ -104,13 +106,15 @@ func printOrgmodeData(w io.Writer, c cfg.Config, data *Tabdata) { } /* - Markdown table +Markdown table */ func printMarkdownData(w io.Writer, c cfg.Config, data *Tabdata) { tableString := &strings.Builder{} table := tablewriter.NewWriter(tableString) - table.SetHeader(data.headers) + if !c.NoHeaders { + table.SetHeader(data.headers) + } for _, row := range data.entries { table.Append(trimRow(row)) @@ -124,19 +128,17 @@ func printMarkdownData(w io.Writer, c cfg.Config, 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(w io.Writer, c cfg.Config, data *Tabdata) { tableString := &strings.Builder{} table := tablewriter.NewWriter(tableString) - table.SetHeader(data.headers) + if !c.NoHeaders { + table.SetHeader(data.headers) + } table.AppendBulk(data.entries) - // for _, row := range data.entries { - // table.Append(trimRow(row)) - // } - table.SetAutoWrapText(false) table.SetAutoFormatHeaders(true) table.SetHeaderAlignment(tablewriter.ALIGN_LEFT) @@ -154,7 +156,7 @@ func printAsciiData(w io.Writer, c cfg.Config, data *Tabdata) { } /* - We simulate the \x command of psql (the PostgreSQL client) +We simulate the \x command of psql (the PostgreSQL client) */ func printExtendedData(w io.Writer, c cfg.Config, data *Tabdata) { // needed for data output @@ -174,7 +176,7 @@ func printExtendedData(w io.Writer, c cfg.Config, data *Tabdata) { } /* - Shell output, ready to be eval'd. Just like FreeBSD stat(1) +Shell output, ready to be eval'd. Just like FreeBSD stat(1) */ func printShellData(w io.Writer, c cfg.Config, data *Tabdata) { out := "" diff --git a/tablizer.1 b/tablizer.1 index 712547c..ff3486b 100644 --- a/tablizer.1 +++ b/tablizer.1 @@ -133,7 +133,7 @@ .\" ======================================================================== .\" .IX Title "TABLIZER 1" -.TH TABLIZER 1 "2023-01-23" "1" "User Commands" +.TH TABLIZER 1 "2023-04-21" "1" "User Commands" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -151,6 +151,7 @@ tablizer \- Manipulate tabular output of other programs \& \-v, \-\-invert\-match select non\-matching rows \& \-n, \-\-no\-numbering Disable header numbering \& \-N, \-\-no\-color Disable pattern highlighting +\& \-\-no\-headers Disable headers display \& \-s, \-\-separator string Custom field separator \& \-k, \-\-sort\-by int Sort by column (default: 1) \& @@ -234,6 +235,11 @@ the original order. .PP The numbering can be suppressed by using the \fB\-n\fR option. .PP +By default tablizer shows a header containing the names of each +column. This can be disabled using the \fB\-\-no\-headers\fR option. Be +aware that this only affects tabular output modes. Shell, Extended, +Yaml and \s-1CSV\s0 output modes always use the column names. +.PP By default, if a \fBpattern\fR has been speficied, matches will be highlighted. You can disable this behavior with the \fB\-N\fR option. .PP diff --git a/tablizer.pod b/tablizer.pod index 6ce2980..e0d9c0d 100644 --- a/tablizer.pod +++ b/tablizer.pod @@ -12,6 +12,7 @@ tablizer - Manipulate tabular output of other programs -v, --invert-match select non-matching rows -n, --no-numbering Disable header numbering -N, --no-color Disable pattern highlighting + --no-headers Disable headers display -s, --separator string Custom field separator -k, --sort-by int Sort by column (default: 1) @@ -90,6 +91,11 @@ the original order. The numbering can be suppressed by using the B<-n> option. +By default tablizer shows a header containing the names of each +column. This can be disabled using the B<--no-headers> option. Be +aware that this only affects tabular output modes. Shell, Extended, +Yaml and CSV output modes always use the column names. + By default, if a B has been speficied, matches will be highlighted. You can disable this behavior with the B<-N> option.