Skip to content

Commit 067de43

Browse files
committed
Add 'ansi' theme that uses the terminal's native 4-bit ANSI colors
1 parent c8418ac commit 067de43

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var (
3535
output = flag.String("output", "", "output fields: "+strings.Join(columnIDs(), ", "))
3636
sortBy = flag.String("sort", "mountpoint", "sort output by: "+strings.Join(columnIDs(), ", "))
3737
width = flag.Uint("width", 0, "max output width")
38-
themeOpt = flag.String("theme", defaultThemeName(), "color themes: dark, light")
38+
themeOpt = flag.String("theme", defaultThemeName(), "color themes: dark, light, ansi")
3939
styleOpt = flag.String("style", defaultStyleName(), "style: unicode, ascii")
4040

4141
availThreshold = flag.String("avail-threshold", "10G,1G", "specifies the coloring threshold (yellow, red) of the avail column, must be integer with optional SI prefixes")
@@ -180,6 +180,14 @@ func main() {
180180
fmt.Fprintln(os.Stderr, err)
181181
os.Exit(1)
182182
}
183+
if term == termenv.ANSI {
184+
// enforce ANSI theme for limited color support
185+
theme, err = loadTheme("ansi")
186+
if err != nil {
187+
fmt.Fprintln(os.Stderr, err)
188+
os.Exit(1)
189+
}
190+
}
183191

184192
// validate style
185193
style, err := parseStyle(*styleOpt)

themes.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ func loadTheme(theme string) (Theme, error) {
4646
colorCyan: term.Color("#0087FF"),
4747
}
4848

49+
themes["ansi"] = Theme{
50+
colorRed: term.Color("9"),
51+
colorYellow: term.Color("11"),
52+
colorGreen: term.Color("10"),
53+
colorBlue: term.Color("12"),
54+
colorGray: term.Color("7"),
55+
colorMagenta: term.Color("13"),
56+
colorCyan: term.Color("8"),
57+
}
58+
4959
if _, ok := themes[theme]; !ok {
5060
return Theme{}, fmt.Errorf("Unknown theme: %s", theme)
5161
}

0 commit comments

Comments
 (0)