Skip to content

Commit 288945f

Browse files
rossdeanemuesli
authored andcommitted
Added theming option
1 parent 7b96c5f commit 288945f

File tree

3 files changed

+62
-22
lines changed

3 files changed

+62
-22
lines changed

main.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
var (
1515
term = termenv.ColorProfile()
16+
theme Theme
1617

1718
all = flag.Bool("all", false, "include pseudo, duplicate, inaccessible file systems")
1819
hideLocal = flag.Bool("hide-local", false, "hide local devices")
@@ -23,12 +24,13 @@ var (
2324
hideBinds = flag.Bool("hide-binds", true, "hide bind mounts")
2425
hideFs = flag.String("hide-fs", "", "hide specific filesystems, separated with commas")
2526

26-
output = flag.String("output", "", "output fields: "+strings.Join(columnIDs(), ", "))
27-
sortBy = flag.String("sort", "mountpoint", "sort output by: "+strings.Join(columnIDs(), ", "))
28-
width = flag.Uint("width", 0, "max output width")
27+
output = flag.String("output", "", "output fields: "+strings.Join(columnIDs(), ", "))
28+
sortBy = flag.String("sort", "mountpoint", "sort output by: "+strings.Join(columnIDs(), ", "))
29+
width = flag.Uint("width", 0, "max output width")
30+
themeOpt = flag.String("theme", "dark", "color themes: dark, light")
2931

30-
inodes = flag.Bool("inodes", false, "list inode information instead of block usage")
31-
jsonOutput = flag.Bool("json", false, "output all devices in JSON format")
32+
inodes = flag.Bool("inodes", false, "list inode information instead of block usage")
33+
jsonOutput = flag.Bool("json", false, "output all devices in JSON format")
3234
)
3335

3436
// renderTables renders all tables.
@@ -144,6 +146,7 @@ func parseHideFs(hideFs string) map[string]struct{} {
144146
func main() {
145147
flag.Parse()
146148

149+
theme = loadThemes(*themeOpt)
147150
// validate flags
148151
columns, err := parseColumns(*output)
149152
if err != nil {

table.go

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,6 @@ var (
3333
{ID: "type", Name: "Type", SortIndex: 10},
3434
{ID: "filesystem", Name: "Filesystem", SortIndex: 11},
3535
}
36-
37-
colorRed = term.Color("#E88388")
38-
colorYellow = term.Color("#DBAB79")
39-
colorGreen = term.Color("#A8CC8C")
40-
colorBlue = term.Color("#71BEF2")
41-
colorGray = term.Color("#B9BFCA")
42-
colorMagenta = term.Color("#D290E4")
43-
colorCyan = term.Color("#66C2CD")
4436
)
4537

4638
// printTable prints an individual table of mounts.
@@ -103,7 +95,7 @@ func printTable(title string, m []Mount, sortBy int, cols []int) {
10395
}
10496

10597
tab.AppendRow([]interface{}{
106-
termenv.String(v.Mountpoint).Foreground(colorBlue), // mounted on
98+
termenv.String(v.Mountpoint).Foreground(theme.colorBlue), // mounted on
10799
v.Total, // size
108100
v.Used, // used
109101
v.Free, // avail
@@ -112,8 +104,8 @@ func printTable(title string, m []Mount, sortBy int, cols []int) {
112104
v.InodesUsed, // inodes used
113105
v.InodesFree, // inodes avail
114106
inodeUsage, // inodes use%
115-
termenv.String(v.Fstype).Foreground(colorGray), // type
116-
termenv.String(v.Device).Foreground(colorGray), // filesystem
107+
termenv.String(v.Fstype).Foreground(theme.colorGray), // type
108+
termenv.String(v.Device).Foreground(theme.colorGray), // filesystem
117109
v.Total, // size sorting helper
118110
v.Used, // used sorting helper
119111
v.Free, // avail sorting helper
@@ -157,11 +149,11 @@ func spaceTransformer(val interface{}) string {
157149
var s = termenv.String(sizeToString(free))
158150
switch {
159151
case free < 1<<30:
160-
s = s.Foreground(colorRed)
152+
s = s.Foreground(theme.colorRed)
161153
case free < 10*1<<30:
162-
s = s.Foreground(colorYellow)
154+
s = s.Foreground(theme.colorYellow)
163155
default:
164-
s = s.Foreground(colorGreen)
156+
s = s.Foreground(theme.colorGreen)
165157
}
166158

167159
return s.String()
@@ -187,11 +179,11 @@ func barTransformer(val interface{}) string {
187179
// apply color to progress-bar
188180
switch {
189181
case usage >= 0.9:
190-
s = s.Foreground(colorRed)
182+
s = s.Foreground(theme.colorRed)
191183
case usage >= 0.5:
192-
s = s.Foreground(colorYellow)
184+
s = s.Foreground(theme.colorYellow)
193185
default:
194-
s = s.Foreground(colorGreen)
186+
s = s.Foreground(theme.colorGreen)
195187
}
196188

197189
return s.String()

themes.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package main
2+
3+
import (
4+
"github.com/muesli/termenv"
5+
)
6+
7+
type Theme struct {
8+
colorRed termenv.Color
9+
colorYellow termenv.Color
10+
colorGreen termenv.Color
11+
colorBlue termenv.Color
12+
colorGray termenv.Color
13+
colorMagenta termenv.Color
14+
colorCyan termenv.Color
15+
}
16+
17+
func loadThemes(theme string) Theme {
18+
themes := make(map[string]Theme)
19+
20+
themes["dark"] = Theme{
21+
colorRed: term.Color("#E88388"),
22+
colorYellow: term.Color("#DBAB79"),
23+
colorGreen: term.Color("#A8CC8C"),
24+
colorBlue: term.Color("#71BEF2"),
25+
colorGray: term.Color("#B9BFCA"),
26+
colorMagenta: term.Color("#D290E4"),
27+
colorCyan: term.Color("#66C2CD"),
28+
}
29+
30+
themes["light"] = Theme{
31+
colorRed: term.Color("#D70000"),
32+
colorYellow: term.Color("#FFAF00"),
33+
colorGreen: term.Color("#005F00"),
34+
colorBlue: term.Color("#000087"),
35+
colorGray: term.Color("#303030"),
36+
colorMagenta: term.Color("#AF00FF"),
37+
colorCyan: term.Color("#0087FF"),
38+
}
39+
40+
if _, ok := themes[theme]; !ok {
41+
return themes["dark"]
42+
}
43+
44+
return themes[theme]
45+
}

0 commit comments

Comments
 (0)