Skip to content

Commit f726dea

Browse files
rossdeanemuesli
authored andcommitted
added style flag
1 parent 08bab25 commit f726dea

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

main.go

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"strings"
99

10+
"github.com/jedib0t/go-pretty/v6/table"
1011
"github.com/muesli/termenv"
1112
"golang.org/x/crypto/ssh/terminal"
1213
)
@@ -28,13 +29,14 @@ var (
2829
sortBy = flag.String("sort", "mountpoint", "sort output by: "+strings.Join(columnIDs(), ", "))
2930
width = flag.Uint("width", 0, "max output width")
3031
themeOpt = flag.String("theme", defaultThemeName(), "color themes: dark, light")
32+
styleOpt = flag.String("style", "unicode", "style: unicode, ascii")
3133

3234
inodes = flag.Bool("inodes", false, "list inode information instead of block usage")
3335
jsonOutput = flag.Bool("json", false, "output all devices in JSON format")
3436
)
3537

3638
// renderTables renders all tables.
37-
func renderTables(m []Mount, columns []int, sortCol int) error {
39+
func renderTables(m []Mount, columns []int, sortCol int, style table.Style) error {
3840
var local, network, fuse, special []Mount
3941
hideFsMap := parseHideFs(*hideFs)
4042

@@ -83,16 +85,16 @@ func renderTables(m []Mount, columns []int, sortCol int) error {
8385

8486
// print tables
8587
if !*hideLocal || *all {
86-
printTable("local", local, sortCol, columns)
88+
printTable("local", local, sortCol, columns, style)
8789
}
8890
if !*hideNetwork || *all {
89-
printTable("network", network, sortCol, columns)
91+
printTable("network", network, sortCol, columns, style)
9092
}
9193
if !*hideFuse || *all {
92-
printTable("FUSE", fuse, sortCol, columns)
94+
printTable("FUSE", fuse, sortCol, columns, style)
9395
}
9496
if !*hideSpecial || *all {
95-
printTable("special", special, sortCol, columns)
97+
printTable("special", special, sortCol, columns, style)
9698
}
9799
return nil
98100
}
@@ -130,6 +132,18 @@ func parseColumns(cols string) ([]int, error) {
130132
return i, nil
131133
}
132134

135+
// parseStyle converts user-provided style option into a table.Style.
136+
func parseStyle(styleOpt string) (table.Style, error) {
137+
switch styleOpt {
138+
case "unicode":
139+
return table.StyleRounded, nil
140+
case "ascii":
141+
return table.StyleDefault, nil
142+
default:
143+
return table.Style{}, fmt.Errorf("Unknown style option: %s", styleOpt)
144+
}
145+
}
146+
133147
// parseHideFs parses the supplied hide-fs flag into a map of fs types which should be skipped.
134148
func parseHideFs(hideFs string) map[string]struct{} {
135149
hideMap := make(map[string]struct{})
@@ -154,6 +168,12 @@ func main() {
154168
os.Exit(1)
155169
}
156170

171+
style, err := parseStyle(*styleOpt)
172+
if err != nil {
173+
fmt.Fprintln(os.Stderr, err)
174+
os.Exit(1)
175+
}
176+
157177
columns, err := parseColumns(*output)
158178
if err != nil {
159179
fmt.Fprintln(os.Stderr, err)
@@ -209,7 +229,7 @@ func main() {
209229
}
210230

211231
// print tables
212-
err = renderTables(m, columns, sortCol)
232+
err = renderTables(m, columns, sortCol, style)
213233
if err != nil {
214234
fmt.Fprintln(os.Stderr, err)
215235
}

table.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ var (
3636
)
3737

3838
// printTable prints an individual table of mounts.
39-
func printTable(title string, m []Mount, sortBy int, cols []int) {
39+
func printTable(title string, m []Mount, sortBy int, cols []int, style table.Style) {
4040
tab := table.NewWriter()
4141
tab.SetAllowedRowLength(int(*width))
4242
tab.SetOutputMirror(os.Stdout)
43-
tab.SetStyle(table.StyleRounded)
4443
tab.Style().Options.SeparateColumns = true
44+
tab.SetStyle(style)
4545

4646
if barWidth() > 0 {
4747
columns[4].Width = barWidth() + 7

0 commit comments

Comments
 (0)