7
7
"os"
8
8
"strings"
9
9
10
+ "github.com/jedib0t/go-pretty/v6/table"
10
11
"github.com/muesli/termenv"
11
12
"golang.org/x/crypto/ssh/terminal"
12
13
)
@@ -28,13 +29,14 @@ var (
28
29
sortBy = flag .String ("sort" , "mountpoint" , "sort output by: " + strings .Join (columnIDs (), ", " ))
29
30
width = flag .Uint ("width" , 0 , "max output width" )
30
31
themeOpt = flag .String ("theme" , defaultThemeName (), "color themes: dark, light" )
32
+ styleOpt = flag .String ("style" , "unicode" , "style: unicode, ascii" )
31
33
32
34
inodes = flag .Bool ("inodes" , false , "list inode information instead of block usage" )
33
35
jsonOutput = flag .Bool ("json" , false , "output all devices in JSON format" )
34
36
)
35
37
36
38
// 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 {
38
40
var local , network , fuse , special []Mount
39
41
hideFsMap := parseHideFs (* hideFs )
40
42
@@ -83,16 +85,16 @@ func renderTables(m []Mount, columns []int, sortCol int) error {
83
85
84
86
// print tables
85
87
if ! * hideLocal || * all {
86
- printTable ("local" , local , sortCol , columns )
88
+ printTable ("local" , local , sortCol , columns , style )
87
89
}
88
90
if ! * hideNetwork || * all {
89
- printTable ("network" , network , sortCol , columns )
91
+ printTable ("network" , network , sortCol , columns , style )
90
92
}
91
93
if ! * hideFuse || * all {
92
- printTable ("FUSE" , fuse , sortCol , columns )
94
+ printTable ("FUSE" , fuse , sortCol , columns , style )
93
95
}
94
96
if ! * hideSpecial || * all {
95
- printTable ("special" , special , sortCol , columns )
97
+ printTable ("special" , special , sortCol , columns , style )
96
98
}
97
99
return nil
98
100
}
@@ -130,6 +132,18 @@ func parseColumns(cols string) ([]int, error) {
130
132
return i , nil
131
133
}
132
134
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
+
133
147
// parseHideFs parses the supplied hide-fs flag into a map of fs types which should be skipped.
134
148
func parseHideFs (hideFs string ) map [string ]struct {} {
135
149
hideMap := make (map [string ]struct {})
@@ -154,6 +168,12 @@ func main() {
154
168
os .Exit (1 )
155
169
}
156
170
171
+ style , err := parseStyle (* styleOpt )
172
+ if err != nil {
173
+ fmt .Fprintln (os .Stderr , err )
174
+ os .Exit (1 )
175
+ }
176
+
157
177
columns , err := parseColumns (* output )
158
178
if err != nil {
159
179
fmt .Fprintln (os .Stderr , err )
@@ -209,7 +229,7 @@ func main() {
209
229
}
210
230
211
231
// print tables
212
- err = renderTables (m , columns , sortCol )
232
+ err = renderTables (m , columns , sortCol , style )
213
233
if err != nil {
214
234
fmt .Fprintln (os .Stderr , err )
215
235
}
0 commit comments