mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-13 01:08:41 -09:00
Add dark-bg color scheme + enable colors by default if !NO_COLOR
Same thing as commit 376aad0d35 in the C
version.
This commit is contained in:
parent
1de70064e7
commit
f448e8ea67
3 changed files with 80 additions and 56 deletions
9
ncdu.pod
9
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
|
||||
|
||||
|
|
|
|||
|
|
@ -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});
|
||||
}
|
||||
|
|
|
|||
121
src/ui.zig
121
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: {
|
||||
|
|
|
|||
Loading…
Reference in a new issue