feat: add auto_run_commands and auto_run_time_seconds config options
This commit is contained in:
parent
de73875676
commit
921c17de3c
2 changed files with 35 additions and 0 deletions
|
|
@ -32,6 +32,9 @@ limit_auto_save_file_types: ?[]const []const u8 = null, // null means *all*
|
||||||
enable_prefix_keyhints: bool = true,
|
enable_prefix_keyhints: bool = true,
|
||||||
enable_auto_find: bool = true,
|
enable_auto_find: bool = true,
|
||||||
|
|
||||||
|
auto_run_time_seconds: usize = 360, //seconds
|
||||||
|
auto_run_commands: ?[]const []const u8 = null, // a list of simple commands
|
||||||
|
|
||||||
indent_size: usize = 4,
|
indent_size: usize = 4,
|
||||||
tab_width: usize = 8,
|
tab_width: usize = 8,
|
||||||
indent_mode: IndentMode = .auto,
|
indent_mode: IndentMode = .auto,
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,8 @@ color_scheme_locked: bool = false,
|
||||||
hint_mode: HintMode = .prefix,
|
hint_mode: HintMode = .prefix,
|
||||||
last_palette: ?LastPalette = null,
|
last_palette: ?LastPalette = null,
|
||||||
|
|
||||||
|
auto_run_timer: ?tp.Cancellable = null,
|
||||||
|
|
||||||
const HintMode = enum { none, prefix, all };
|
const HintMode = enum { none, prefix, all };
|
||||||
|
|
||||||
const LastPalette = struct {
|
const LastPalette = struct {
|
||||||
|
|
@ -257,9 +259,15 @@ fn init_delayed(self: *Self) command.Result {
|
||||||
try cmds.enter_mode(self, command.Context.fmt(.{keybind.default_mode}));
|
try cmds.enter_mode(self, command.Context.fmt(.{keybind.default_mode}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self.start_auto_run_timer();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deinit(self: *Self) void {
|
fn deinit(self: *Self) void {
|
||||||
|
if (self.auto_run_timer) |*t| {
|
||||||
|
t.cancel() catch {};
|
||||||
|
t.deinit();
|
||||||
|
self.auto_run_timer = null;
|
||||||
|
}
|
||||||
if (self.input_idle_timer) |*t| {
|
if (self.input_idle_timer) |*t| {
|
||||||
t.cancel() catch {};
|
t.cancel() catch {};
|
||||||
t.deinit();
|
t.deinit();
|
||||||
|
|
@ -346,6 +354,23 @@ fn update_mouse_idle_timer(self: *Self) void {
|
||||||
self.mouse_idle_timer = tp.self_pid().delay_send_cancellable(self.allocator, "tui.mouse_idle_timer", delay, .{"MOUSE_IDLE"}) catch return;
|
self.mouse_idle_timer = tp.self_pid().delay_send_cancellable(self.allocator, "tui.mouse_idle_timer", delay, .{"MOUSE_IDLE"}) catch return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn auto_run(self: *Self) void {
|
||||||
|
const auto_run_cmds = self.config_.auto_run_commands orelse return;
|
||||||
|
for (auto_run_cmds) |cmd|
|
||||||
|
command.executeName(cmd, .{}) catch |e| self.logger.print_err("autorun", "auto run command '{s}' failed: {t}", .{ cmd, e });
|
||||||
|
self.start_auto_run_timer();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn start_auto_run_timer(self: *Self) void {
|
||||||
|
const delay = std.time.us_per_s * @as(u64, self.config_.auto_run_time_seconds);
|
||||||
|
if (self.auto_run_timer) |*t| {
|
||||||
|
t.cancel() catch {};
|
||||||
|
t.deinit();
|
||||||
|
self.auto_run_timer = null;
|
||||||
|
}
|
||||||
|
self.auto_run_timer = tp.self_pid().delay_send_cancellable(self.allocator, "tui.auto_run_timer", delay, .{"AUTO_RUN"}) catch return;
|
||||||
|
}
|
||||||
|
|
||||||
fn receive(self: *Self, from: tp.pid_ref, m: tp.message) tp.result {
|
fn receive(self: *Self, from: tp.pid_ref, m: tp.message) tp.result {
|
||||||
const frame = tracy.initZone(@src(), .{ .name = "tui" });
|
const frame = tracy.initZone(@src(), .{ .name = "tui" });
|
||||||
defer frame.deinit();
|
defer frame.deinit();
|
||||||
|
|
@ -510,6 +535,13 @@ fn receive_safe(self: *Self, from: tp.pid_ref, m: tp.message) !void {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (try m.match(.{"AUTO_RUN"})) {
|
||||||
|
if (self.auto_run_timer) |*t| t.deinit();
|
||||||
|
self.auto_run_timer = null;
|
||||||
|
self.auto_run();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (try m.match(.{ "fontface", "done" })) {
|
if (try m.match(.{ "fontface", "done" })) {
|
||||||
return self.enter_overlay_mode(@import("mode/overlay/fontface_palette.zig").Type);
|
return self.enter_overlay_mode(@import("mode/overlay/fontface_palette.zig").Type);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue