Skip to content

Commit

Permalink
use termenv HasDarkBackground() to determine default
Browse files Browse the repository at this point in the history
  • Loading branch information
rossdeane authored and muesli committed Oct 5, 2020
1 parent 288945f commit f1c1238
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
19 changes: 11 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

var (
term = termenv.ColorProfile()
term = termenv.ColorProfile()
theme Theme

all = flag.Bool("all", false, "include pseudo, duplicate, inaccessible file systems")
Expand All @@ -24,13 +24,13 @@ var (
hideBinds = flag.Bool("hide-binds", true, "hide bind mounts")
hideFs = flag.String("hide-fs", "", "hide specific filesystems, separated with commas")

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

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

// renderTables renders all tables.
Expand Down Expand Up @@ -146,7 +146,10 @@ func parseHideFs(hideFs string) map[string]struct{} {
func main() {
flag.Parse()

theme = loadThemes(*themeOpt)
if *themeOpt == "" {
*themeOpt = getDefaultThemeName()
}
theme = loadTheme(*themeOpt)
// validate flags
columns, err := parseColumns(*output)
if err != nil {
Expand Down
9 changes: 8 additions & 1 deletion themes.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ type Theme struct {
colorCyan termenv.Color
}

func loadThemes(theme string) Theme {
func getDefaultThemeName() string {
if !termenv.HasDarkBackground() {
return "light"
}
return "dark"
}

func loadTheme(theme string) Theme {
themes := make(map[string]Theme)

themes["dark"] = Theme{
Expand Down

0 comments on commit f1c1238

Please sign in to comment.