Compare commits

...

2 commits

2 changed files with 31 additions and 4 deletions

View file

@ -83,6 +83,8 @@ pub fn main() anyerror!void {
.literal = "Disable :LINE and +LINE syntax", .literal = "Disable :LINE and +LINE syntax",
.scratch = "Open a scratch (temporary) buffer on start", .scratch = "Open a scratch (temporary) buffer on start",
.new_file = "Create a new untitled file on start", .new_file = "Create a new untitled file on start",
.dark = "Use dark color scheme",
.light = "Use light color scheme",
.version = "Show build version and exit", .version = "Show build version and exit",
}; };
@ -121,6 +123,8 @@ pub fn main() anyerror!void {
literal: bool, literal: bool,
scratch: bool, scratch: bool,
new_file: bool, new_file: bool,
dark: bool,
light: bool,
version: bool, version: bool,
positional: struct { positional: struct {
@ -346,6 +350,11 @@ pub fn main() anyerror!void {
try tui_proc.send(.{ "cmd", "create_scratch_buffer", .{} }); try tui_proc.send(.{ "cmd", "create_scratch_buffer", .{} });
} }
if (args.dark)
try tui_proc.send(.{ "cmd", "force_color_scheme", .{"dark"} })
else if (args.light)
try tui_proc.send(.{ "cmd", "force_color_scheme", .{"light"} });
if (args.exec) |exec_str| { if (args.exec) |exec_str| {
var cmds = std.mem.splitScalar(u8, exec_str, ';'); var cmds = std.mem.splitScalar(u8, exec_str, ';');
while (cmds.next()) |cmd| { while (cmds.next()) |cmd| {

View file

@ -68,6 +68,7 @@ query_cache_: *syntax.QueryCache,
frames_rendered_: usize = 0, frames_rendered_: usize = 0,
clipboard: ?[]const u8 = null, clipboard: ?[]const u8 = null,
color_scheme: enum { dark, light } = .dark, color_scheme: enum { dark, light } = .dark,
color_scheme_locked: bool = false,
const keepalive = std.time.us_per_day * 365; // one year const keepalive = std.time.us_per_day * 365; // one year
const idle_frames = 0; const idle_frames = 0;
@ -786,7 +787,14 @@ fn set_theme_by_name(self: *Self, name: []const u8, action: enum { none, store }
} }
} }
fn force_color_scheme(self: *Self, color_scheme: @TypeOf(self.color_scheme)) void {
self.color_scheme = color_scheme;
self.color_scheme_locked = true;
self.logger.print("color scheme: {s} ({s})", .{ @tagName(self.color_scheme), self.current_theme().name });
}
fn set_color_scheme(self: *Self, color_scheme: @TypeOf(self.color_scheme)) void { fn set_color_scheme(self: *Self, color_scheme: @TypeOf(self.color_scheme)) void {
if (self.color_scheme_locked) return;
self.color_scheme = color_scheme; self.color_scheme = color_scheme;
self.logger.print("color scheme: {s} ({s})", .{ @tagName(self.color_scheme), self.current_theme().name }); self.logger.print("color scheme: {s} ({s})", .{ @tagName(self.color_scheme), self.current_theme().name });
} }
@ -913,18 +921,28 @@ const cmds = struct {
} }
pub const toggle_highlight_columns_meta: Meta = .{ .description = "Toggle highlight columns" }; pub const toggle_highlight_columns_meta: Meta = .{ .description = "Toggle highlight columns" };
pub fn set_color_scheme(self: *Self, ctx: Ctx) Result { pub fn force_color_scheme(self: *Self, ctx: Ctx) Result {
self.set_color_scheme(if (try ctx.args.match(.{"dark"})) self.force_color_scheme(if (try ctx.args.match(.{"dark"}))
.dark .dark
else if (try ctx.args.match(.{"light"})) else if (try ctx.args.match(.{"light"}))
.light .light
else else
.dark); .dark);
} }
pub const set_color_scheme_meta: Meta = .{ .description = "Toggle dark/light color scheme" }; pub const force_color_scheme_meta: Meta = .{ .arguments = &.{.string} };
pub fn set_color_scheme(self: *Self, ctx: Ctx) Result {
self.force_color_scheme(if (try ctx.args.match(.{"dark"}))
.dark
else if (try ctx.args.match(.{"light"}))
.light
else
.dark);
}
pub const set_color_scheme_meta: Meta = .{ .arguments = &.{.string} };
pub fn toggle_color_scheme(self: *Self, _: Ctx) Result { pub fn toggle_color_scheme(self: *Self, _: Ctx) Result {
self.set_color_scheme(switch (self.color_scheme) { self.force_color_scheme(switch (self.color_scheme) {
.dark => .light, .dark => .light,
.light => .dark, .light => .dark,
}); });