summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2021-08-16 16:33:21 +0200
committerYorhel <git@yorhel.nl>2021-08-16 16:33:23 +0200
commitf448e8ea6744ed936166ff7e88647aa7553614b6 (patch)
tree2f7d16629c32d8570998716756579642a0a93ca5
parent1de70064e7525d7c79e225cb1d4ca39d739f63e6 (diff)
Add dark-bg color scheme + enable colors by default if !NO_COLORzig
Same thing as commit 376aad0d350657d959a3ac1713a4a86b20ae30d1 in the C version.
-rw-r--r--ncdu.pod9
-rw-r--r--src/main.zig6
-rw-r--r--src/ui.zig121
3 files changed, 80 insertions, 56 deletions
diff --git a/ncdu.pod b/ncdu.pod
index caa9812..0a6df97 100644
--- a/ncdu.pod
+++ b/ncdu.pod
@@ -139,9 +139,12 @@ accidentally press 'q' during or after a very long scan.
=item --color I<SCHEME>
-Select a color scheme. Currently only two schemes are recognized: I<off> to
-disable colors (the default) and I<dark> for a color scheme intended for dark
-backgrounds.
+Select a color scheme. The following schemes are recognized: I<off> to disable
+colors, I<dark> for a color scheme intended for dark backgrounds and I<dark-bg>
+for a variation of the I<dark> color scheme that also works in terminals with a
+light background.
+
+The default is I<dark-bg> unless the C<NO_COLOR> environment variable is set.
=back
diff --git a/src/main.zig b/src/main.zig
index 3e14f7e..46564a9 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -52,7 +52,7 @@ pub const config = struct {
pub var scan_ui: enum { none, line, full } = .full;
pub var si: bool = false;
pub var nc_tty: bool = false;
- pub var ui_color: enum { off, dark } = .off;
+ pub var ui_color: enum { off, dark, darkbg } = .off;
pub var thousands_sep: []const u8 = ",";
pub var show_hidden: bool = true;
@@ -175,7 +175,7 @@ fn help() noreturn {
++ " --exclude-caches Exclude directories containing CACHEDIR.TAG\n"
++ " --exclude-kernfs Exclude Linux pseudo filesystems (procfs,sysfs,cgroup,...)\n"
++ " --confirm-quit Confirm quitting ncdu\n"
- ++ " --color SCHEME Set color scheme (off/dark)\n"
+ ++ " --color SCHEME Set color scheme (off/dark/dark-bg)\n"
) catch {};
std.process.exit(0);
}
@@ -259,6 +259,7 @@ pub fn main() void {
config.thousands_sep = span;
}
}
+ if (std.os.getenvZ("NO_COLOR") == null) config.ui_color = .darkbg;
var args = Args(std.process.ArgIteratorPosix).init(std.process.ArgIteratorPosix.init());
var scan_dir: ?[]const u8 = null;
@@ -300,6 +301,7 @@ pub fn main() void {
const val = args.arg();
if (std.mem.eql(u8, val, "off")) config.ui_color = .off
else if (std.mem.eql(u8, val, "dark")) config.ui_color = .dark
+ else if (std.mem.eql(u8, val, "dark-bg")) config.ui_color = .darkbg
else ui.die("Unknown --color option: {s}.\n", .{val});
} else ui.die("Unrecognized option '{s}'.\n", .{opt.val});
}
diff --git a/src/ui.zig b/src/ui.zig
index d9a7d74..08fbdea 100644
--- a/src/ui.zig
+++ b/src/ui.zig
@@ -201,66 +201,85 @@ const StyleDef = struct {
name: []const u8,
off: StyleAttr,
dark: StyleAttr,
+ darkbg: StyleAttr,
fn style(self: *const @This()) StyleAttr {
return switch (main.config.ui_color) {
.off => self.off,
.dark => self.dark,
+ .darkbg => self.darkbg,
};
}
};
const styles = [_]StyleDef{
- .{ .name = "default",
- .off = .{ .fg = -1, .bg = -1, .attr = 0 },
- .dark = .{ .fg = -1, .bg = -1, .attr = 0 } },
- .{ .name = "bold",
- .off = .{ .fg = -1, .bg = -1, .attr = c.A_BOLD },
- .dark = .{ .fg = -1, .bg = -1, .attr = c.A_BOLD } },
- .{ .name = "bold_hd",
- .off = .{ .fg = -1, .bg = -1, .attr = c.A_BOLD|c.A_REVERSE },
- .dark = .{ .fg = c.COLOR_BLACK, .bg = c.COLOR_CYAN, .attr = c.A_BOLD } },
- .{ .name = "box_title",
- .off = .{ .fg = -1, .bg = -1, .attr = c.A_BOLD },
- .dark = .{ .fg = c.COLOR_BLUE, .bg = -1, .attr = c.A_BOLD } },
- .{ .name = "hd", // header + footer
- .off = .{ .fg = -1, .bg = -1, .attr = c.A_REVERSE },
- .dark = .{ .fg = c.COLOR_BLACK, .bg = c.COLOR_CYAN, .attr = 0 } },
- .{ .name = "sel",
- .off = .{ .fg = -1, .bg = -1, .attr = c.A_REVERSE },
- .dark = .{ .fg = c.COLOR_WHITE, .bg = c.COLOR_GREEN, .attr = c.A_BOLD } },
- .{ .name = "num",
- .off = .{ .fg = -1, .bg = -1, .attr = 0 },
- .dark = .{ .fg = c.COLOR_YELLOW, .bg = -1, .attr = c.A_BOLD } },
- .{ .name = "num_hd",
- .off = .{ .fg = -1, .bg = -1, .attr = c.A_REVERSE },
- .dark = .{ .fg = c.COLOR_YELLOW, .bg = c.COLOR_CYAN, .attr = c.A_BOLD } },
- .{ .name = "num_sel",
- .off = .{ .fg = -1, .bg = -1, .attr = c.A_REVERSE },
- .dark = .{ .fg = c.COLOR_YELLOW, .bg = c.COLOR_GREEN, .attr = c.A_BOLD } },
- .{ .name = "key",
- .off = .{ .fg = -1, .bg = -1, .attr = c.A_BOLD },
- .dark = .{ .fg = c.COLOR_YELLOW, .bg = -1, .attr = c.A_BOLD } },
- .{ .name = "key_hd",
- .off = .{ .fg = -1, .bg = -1, .attr = c.A_BOLD|c.A_REVERSE },
- .dark = .{ .fg = c.COLOR_YELLOW, .bg = c.COLOR_CYAN, .attr = c.A_BOLD } },
- .{ .name = "dir",
- .off = .{ .fg = -1, .bg = -1, .attr = 0 },
- .dark = .{ .fg = c.COLOR_BLUE, .bg = -1, .attr = c.A_BOLD } },
- .{ .name = "dir_sel",
- .off = .{ .fg = -1, .bg = -1, .attr = c.A_REVERSE },
- .dark = .{ .fg = c.COLOR_BLUE, .bg = c.COLOR_GREEN, .attr = c.A_BOLD } },
- .{ .name = "flag",
- .off = .{ .fg = -1, .bg = -1, .attr = 0 },
- .dark = .{ .fg = c.COLOR_RED, .bg = -1, .attr = 0 } },
- .{ .name = "flag_sel",
- .off = .{ .fg = -1, .bg = -1, .attr = c.A_REVERSE },
- .dark = .{ .fg = c.COLOR_RED, .bg = c.COLOR_GREEN, .attr = 0 } },
- .{ .name = "graph",
- .off = .{ .fg = -1, .bg = -1, .attr = 0 },
- .dark = .{ .fg = c.COLOR_MAGENTA, .bg = -1, .attr = 0 } },
- .{ .name = "graph_sel",
- .off = .{ .fg = -1, .bg = -1, .attr = c.A_REVERSE },
- .dark = .{ .fg = c.COLOR_MAGENTA, .bg = c.COLOR_GREEN, .attr = 0 } },
+ .{ .name = "default",
+ .off = .{ .fg = -1, .bg = -1, .attr = 0 },
+ .dark = .{ .fg = -1, .bg = -1, .attr = 0 },
+ .darkbg = .{ .fg = c.COLOR_WHITE, .bg = c.COLOR_BLACK, .attr = 0 } },
+ .{ .name = "bold",
+ .off = .{ .fg = -1, .bg = -1, .attr = c.A_BOLD },
+ .dark = .{ .fg = -1, .bg = -1, .attr = c.A_BOLD },
+ .darkbg = .{ .fg = c.COLOR_WHITE, .bg = c.COLOR_BLACK, .attr = c.A_BOLD } },
+ .{ .name = "bold_hd",
+ .off = .{ .fg = -1, .bg = -1, .attr = c.A_BOLD|c.A_REVERSE },
+ .dark = .{ .fg = c.COLOR_BLACK, .bg = c.COLOR_CYAN, .attr = c.A_BOLD },
+ .darkbg = .{ .fg = c.COLOR_BLACK, .bg = c.COLOR_CYAN, .attr = c.A_BOLD } },
+ .{ .name = "box_title",
+ .off = .{ .fg = -1, .bg = -1, .attr = c.A_BOLD },
+ .dark = .{ .fg = c.COLOR_BLUE, .bg = -1, .attr = c.A_BOLD },
+ .darkbg = .{ .fg = c.COLOR_BLUE, .bg = c.COLOR_BLACK, .attr = c.A_BOLD } },
+ .{ .name = "hd", // header + footer
+ .off = .{ .fg = -1, .bg = -1, .attr = c.A_REVERSE },
+ .dark = .{ .fg = c.COLOR_BLACK, .bg = c.COLOR_CYAN, .attr = 0 },
+ .darkbg = .{ .fg = c.COLOR_BLACK, .bg = c.COLOR_CYAN, .attr = 0 } },
+ .{ .name = "sel",
+ .off = .{ .fg = -1, .bg = -1, .attr = c.A_REVERSE },
+ .dark = .{ .fg = c.COLOR_WHITE, .bg = c.COLOR_GREEN, .attr = c.A_BOLD },
+ .darkbg = .{ .fg = c.COLOR_WHITE, .bg = c.COLOR_GREEN, .attr = c.A_BOLD } },
+ .{ .name = "num",
+ .off = .{ .fg = -1, .bg = -1, .attr = 0 },
+ .dark = .{ .fg = c.COLOR_YELLOW, .bg = -1, .attr = c.A_BOLD },
+ .darkbg = .{ .fg = c.COLOR_YELLOW, .bg = c.COLOR_BLACK, .attr = c.A_BOLD } },
+ .{ .name = "num_hd",
+ .off = .{ .fg = -1, .bg = -1, .attr = c.A_REVERSE },
+ .dark = .{ .fg = c.COLOR_YELLOW, .bg = c.COLOR_CYAN, .attr = c.A_BOLD },
+ .darkbg = .{ .fg = c.COLOR_YELLOW, .bg = c.COLOR_CYAN, .attr = c.A_BOLD } },
+ .{ .name = "num_sel",
+ .off = .{ .fg = -1, .bg = -1, .attr = c.A_REVERSE },
+ .dark = .{ .fg = c.COLOR_YELLOW, .bg = c.COLOR_GREEN, .attr = c.A_BOLD },
+ .darkbg = .{ .fg = c.COLOR_YELLOW, .bg = c.COLOR_GREEN, .attr = c.A_BOLD } },
+ .{ .name = "key",
+ .off = .{ .fg = -1, .bg = -1, .attr = c.A_BOLD },
+ .dark = .{ .fg = c.COLOR_YELLOW, .bg = -1, .attr = c.A_BOLD },
+ .darkbg = .{ .fg = c.COLOR_YELLOW, .bg = c.COLOR_BLACK, .attr = c.A_BOLD } },
+ .{ .name = "key_hd",
+ .off = .{ .fg = -1, .bg = -1, .attr = c.A_BOLD|c.A_REVERSE },
+ .dark = .{ .fg = c.COLOR_YELLOW, .bg = c.COLOR_CYAN, .attr = c.A_BOLD },
+ .darkbg = .{ .fg = c.COLOR_YELLOW, .bg = c.COLOR_CYAN, .attr = c.A_BOLD } },
+ .{ .name = "dir",
+ .off = .{ .fg = -1, .bg = -1, .attr = 0 },
+ .dark = .{ .fg = c.COLOR_BLUE, .bg = -1, .attr = c.A_BOLD },
+ .darkbg = .{ .fg = c.COLOR_BLUE, .bg = c.COLOR_BLACK, .attr = c.A_BOLD } },
+ .{ .name = "dir_sel",
+ .off = .{ .fg = -1, .bg = -1, .attr = c.A_REVERSE },
+ .dark = .{ .fg = c.COLOR_BLUE, .bg = c.COLOR_GREEN, .attr = c.A_BOLD },
+ .darkbg = .{ .fg = c.COLOR_BLUE, .bg = c.COLOR_GREEN, .attr = c.A_BOLD } },
+ .{ .name = "flag",
+ .off = .{ .fg = -1, .bg = -1, .attr = 0 },
+ .dark = .{ .fg = c.COLOR_RED, .bg = -1, .attr = 0 },
+ .darkbg = .{ .fg = c.COLOR_RED, .bg = c.COLOR_BLACK, .attr = 0 } },
+ .{ .name = "flag_sel",
+ .off = .{ .fg = -1, .bg = -1, .attr = c.A_REVERSE },
+ .dark = .{ .fg = c.COLOR_RED, .bg = c.COLOR_GREEN, .attr = 0 },
+ .darkbg = .{ .fg = c.COLOR_RED, .bg = c.COLOR_GREEN, .attr = 0 } },
+ .{ .name = "graph",
+ .off = .{ .fg = -1, .bg = -1, .attr = 0 },
+ .dark = .{ .fg = c.COLOR_MAGENTA, .bg = -1, .attr = 0 },
+ .darkbg = .{ .fg = c.COLOR_MAGENTA, .bg = c.COLOR_BLACK, .attr = 0 } },
+ .{ .name = "graph_sel",
+ .off = .{ .fg = -1, .bg = -1, .attr = c.A_REVERSE },
+ .dark = .{ .fg = c.COLOR_MAGENTA, .bg = c.COLOR_GREEN, .attr = 0 },
+ .darkbg = .{ .fg = c.COLOR_MAGENTA, .bg = c.COLOR_GREEN, .attr = 0 } },
};
pub const Style = lbl: {