Skip to content

Commit 23dc68b

Browse files
committed
feat: --wide uses terminal width
1 parent bae70bb commit 23dc68b

File tree

6 files changed

+15
-14
lines changed

6 files changed

+15
-14
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ require (
1717
github.com/pelletier/go-toml v1.9.4
1818
github.com/shopspring/decimal v1.3.1
1919
github.com/spf13/cobra v1.4.0
20+
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467
2021
golang.org/x/time v0.3.0
2122
)
2223

@@ -38,5 +39,4 @@ require (
3839
github.com/rivo/uniseg v0.2.0 // indirect
3940
github.com/spf13/pflag v1.0.5 // indirect
4041
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c // indirect
41-
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect
4242
)

ledger/cmd/add.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,6 @@ var addCmd = &cobra.Command{
135135
mw = io.MultiWriter(f, os.Stdout)
136136
}
137137

138-
if columnWide {
139-
columnWidth = 132
140-
}
141-
142138
for _, t := range trans {
143139
WriteTransaction(mw, t, columnWidth)
144140
}
@@ -150,5 +146,4 @@ func init() {
150146

151147
addCmd.Flags().BoolVarP(&addDryRun, "dry-run", "n", false, "Do not add to ledger file. Display only.")
152148
addCmd.Flags().IntVar(&columnWidth, "columns", 80, "Set a column width for output.")
153-
addCmd.Flags().BoolVar(&columnWide, "wide", false, "Wide output (same as --columns=132).")
154149
}

ledger/cmd/print.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/howeyc/ledger/decimal"
1818
date "github.com/joyt/godate"
1919
"github.com/spf13/cobra"
20+
"golang.org/x/term"
2021
)
2122

2223
const (
@@ -33,6 +34,13 @@ var payeeFilter string
3334
func cliTransactions() ([]*ledger.Transaction, error) {
3435
if columnWidth == 80 && columnWide {
3536
columnWidth = 132
37+
fd := int(os.Stdout.Fd())
38+
if term.IsTerminal(fd) {
39+
tw, _, err := term.GetSize(fd)
40+
if err == nil {
41+
columnWidth = tw
42+
}
43+
}
3644
}
3745

3846
parsedStartDate, tstartErr := date.Parse(startString)
@@ -97,7 +105,7 @@ func init() {
97105
printCmd.Flags().StringVarP(&endString, "end-date", "e", endDate.Format(transactionDateFormat), "End date of transaction processing.")
98106
printCmd.Flags().StringVar(&payeeFilter, "payee", "", "Filter output to payees that contain this string.")
99107
printCmd.Flags().IntVar(&columnWidth, "columns", 80, "Set a column width for output.")
100-
printCmd.Flags().BoolVar(&columnWide, "wide", false, "Wide output (same as --columns=132).")
108+
printCmd.Flags().BoolVar(&columnWide, "wide", false, "Wide output (use terminal width).")
101109
}
102110

103111
// PrintBalances prints out account balances formatted to a window set to a width of columns.

ledger/cmd/printBalance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func init() {
5353
balanceCmd.Flags().StringVarP(&endString, "end-date", "e", endDate.Format(transactionDateFormat), "End date of transaction processing.")
5454
balanceCmd.Flags().StringVar(&payeeFilter, "payee", "", "Filter output to payees that contain this string.")
5555
balanceCmd.Flags().IntVar(&columnWidth, "columns", 80, "Set a column width for output.")
56-
balanceCmd.Flags().BoolVar(&columnWide, "wide", false, "Wide output (same as --columns=132).")
56+
balanceCmd.Flags().BoolVar(&columnWide, "wide", false, "Wide output (use terminal width).")
5757

5858
balanceCmd.Flags().StringVar(&period, "period", "", "Split output into periods (Monthly,Quarterly,SemiYearly,Yearly).")
5959
balanceCmd.Flags().BoolVar(&showEmptyAccounts, "empty", false, "Show empty (zero balance) accounts.")

ledger/cmd/printRegister.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func init() {
5151
registerCmd.Flags().StringVarP(&endString, "end-date", "e", endDate.Format(transactionDateFormat), "End date of transaction processing.")
5252
registerCmd.Flags().StringVar(&payeeFilter, "payee", "", "Filter output to payees that contain this string.")
5353
registerCmd.Flags().IntVar(&columnWidth, "columns", 80, "Set a column width for output.")
54-
registerCmd.Flags().BoolVar(&columnWide, "wide", false, "Wide output (same as --columns=132).")
54+
registerCmd.Flags().BoolVar(&columnWide, "wide", false, "Wide output (use terminal width).")
5555

5656
registerCmd.Flags().StringVar(&period, "period", "", "Split output into periods (Monthly,Quarterly,SemiYearly,Yearly).")
5757
}

ledger/man/ledger.1

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Split output into multiple results based on specified period. Valid options are:
8585
.Sy SemiYearly ,
8686
.Sy Yearly
8787
.It Fl \-wide
88-
Alias for --columns=132
88+
Use terminal width
8989
.El
9090
.Pp
9191
The alias
@@ -123,7 +123,7 @@ End date of transactions to include in processing.
123123
.It Fl \-payee Ar STR
124124
Filter transactions used in processing to payees that contain this string.
125125
.It Fl \-wide
126-
Alias for --columns=132
126+
Use terminal width
127127
.El
128128
.It Ic register Oo Ar account-filter Oc
129129
List all postings matching the
@@ -146,7 +146,7 @@ Split output into multiple results based on specified period. Valid options are:
146146
.Sy SemiYearly ,
147147
.Sy Yearly
148148
.It Fl \-wide
149-
Alias for --columns=132
149+
Use terminal width
150150
.El
151151
.Pp
152152
The alias
@@ -185,8 +185,6 @@ Add a transaction using prompts.
185185
Width of output in characters.
186186
.It Fl \-dry-run ( Fl n )
187187
Do not alter ledger file. Display only.
188-
.It Fl \-wide
189-
Alias for --columns=132
190188
.El
191189
.El
192190
.Sh IMPORT TRANSACTIONS

0 commit comments

Comments
 (0)