Skip to content

Commit

Permalink
added --no-headers flag to disable header display in tabular modes
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas von Dein committed Apr 21, 2023
1 parent 195f685 commit 1acbdbc
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 14 deletions.
3 changes: 2 additions & 1 deletion cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions cmd/tablizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 14 additions & 12 deletions lib/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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 := ""
Expand Down
8 changes: 7 additions & 1 deletion tablizer.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
\&
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tablizer.pod
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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<pattern> has been speficied, matches will be
highlighted. You can disable this behavior with the B<-N> option.

Expand Down

0 comments on commit 1acbdbc

Please sign in to comment.