Compare commits
No commits in common. "8b17eb98179ec297788fac675cf8e10977081d45" and "23ac73ec1ce4df5a1a65b18c117f8b8bd8bcf699" have entirely different histories.
8b17eb9817
...
23ac73ec1c
3 changed files with 6 additions and 80 deletions
|
|
@ -22,7 +22,6 @@ animation_max_lag: usize = 50, //milliseconds
|
||||||
hover_time_ms: usize = 500, //milliseconds
|
hover_time_ms: usize = 500, //milliseconds
|
||||||
input_idle_time_ms: usize = 150, //milliseconds
|
input_idle_time_ms: usize = 150, //milliseconds
|
||||||
idle_actions: []const IdleAction = &default_actions,
|
idle_actions: []const IdleAction = &default_actions,
|
||||||
idle_commands: ?[]const []const u8 = null, // a list of simple commands
|
|
||||||
enable_format_on_save: bool = false,
|
enable_format_on_save: bool = false,
|
||||||
restore_last_cursor_position: bool = true,
|
restore_last_cursor_position: bool = true,
|
||||||
follow_cursor_on_buffer_switch: bool = false, //scroll cursor into view on buffer switch
|
follow_cursor_on_buffer_switch: bool = false, //scroll cursor into view on buffer switch
|
||||||
|
|
@ -33,9 +32,6 @@ 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 = 120, //seconds
|
|
||||||
auto_run_commands: ?[]const []const u8 = &.{"save_session_quiet"}, // 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,
|
||||||
|
|
|
||||||
|
|
@ -355,26 +355,6 @@ const cmds = struct {
|
||||||
}
|
}
|
||||||
pub const quit_without_saving_meta: Meta = .{ .description = "Quit without saving" };
|
pub const quit_without_saving_meta: Meta = .{ .description = "Quit without saving" };
|
||||||
|
|
||||||
pub fn save_session(self: *Self, _: Ctx) Result {
|
|
||||||
const logger = log.logger("session");
|
|
||||||
defer logger.deinit();
|
|
||||||
logger.print("saving session...", .{});
|
|
||||||
try self.write_restore_info();
|
|
||||||
logger.print("session saved", .{});
|
|
||||||
}
|
|
||||||
pub const save_session_meta: Meta = .{ .description = "Save session" };
|
|
||||||
|
|
||||||
pub fn save_session_quiet(self: *Self, _: Ctx) Result {
|
|
||||||
try self.write_restore_info();
|
|
||||||
}
|
|
||||||
pub const save_session_quiet_meta: Meta = .{};
|
|
||||||
|
|
||||||
pub fn save_session_and_quit(self: *Self, _: Ctx) Result {
|
|
||||||
try self.write_restore_info();
|
|
||||||
try tp.self_pid().send("quit");
|
|
||||||
}
|
|
||||||
pub const save_session_and_quit_meta: Meta = .{ .description = "Save session and quit" };
|
|
||||||
|
|
||||||
pub fn open_project_cwd(self: *Self, _: Ctx) Result {
|
pub fn open_project_cwd(self: *Self, _: Ctx) Result {
|
||||||
if (try project_manager.open(".")) |state|
|
if (try project_manager.open(".")) |state|
|
||||||
try self.restore_state(state);
|
try self.restore_state(state);
|
||||||
|
|
@ -809,6 +789,9 @@ const cmds = struct {
|
||||||
pub const close_buffer_meta: Meta = .{ .arguments = &.{.string} };
|
pub const close_buffer_meta: Meta = .{ .arguments = &.{.string} };
|
||||||
|
|
||||||
pub fn restore_session(self: *Self, _: Ctx) Result {
|
pub fn restore_session(self: *Self, _: Ctx) Result {
|
||||||
|
if (tp.env.get().str("project").len == 0) {
|
||||||
|
try open_project_cwd(self, .{});
|
||||||
|
}
|
||||||
try self.create_editor();
|
try self.create_editor();
|
||||||
try self.read_restore_info();
|
try self.read_restore_info();
|
||||||
tui.need_render();
|
tui.need_render();
|
||||||
|
|
@ -1682,8 +1665,6 @@ pub fn write_restore_info(self: *Self) WriteStateError!void {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_state(self: *Self, writer: *std.Io.Writer) WriteStateError!void {
|
pub fn write_state(self: *Self, writer: *std.Io.Writer) WriteStateError!void {
|
||||||
const current_project = tp.env.get().str("project");
|
|
||||||
try cbor.writeValue(writer, current_project);
|
|
||||||
if (self.get_active_editor()) |editor| {
|
if (self.get_active_editor()) |editor| {
|
||||||
try cbor.writeValue(writer, editor.file_path);
|
try cbor.writeValue(writer, editor.file_path);
|
||||||
editor.update_meta();
|
editor.update_meta();
|
||||||
|
|
@ -1720,36 +1701,20 @@ fn read_restore_info(self: *Self) !void {
|
||||||
const size = try file.readAll(buf);
|
const size = try file.readAll(buf);
|
||||||
var iter: []const u8 = buf[0..size];
|
var iter: []const u8 = buf[0..size];
|
||||||
|
|
||||||
try self.extract_state(&iter, .with_project);
|
try self.extract_state(&iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn restore_state(self: *Self, state: []const u8) !void {
|
fn restore_state(self: *Self, state: []const u8) !void {
|
||||||
var iter = state;
|
var iter = state;
|
||||||
try self.extract_state(&iter, .no_project);
|
try self.extract_state(&iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract_state(self: *Self, iter: *[]const u8, mode: enum { no_project, with_project }) !void {
|
fn extract_state(self: *Self, iter: *[]const u8) !void {
|
||||||
const logger = log.logger("extract_state");
|
const logger = log.logger("extract_state");
|
||||||
defer logger.deinit();
|
defer logger.deinit();
|
||||||
tp.trace(tp.channel.debug, .{ "mainview", "extract" });
|
tp.trace(tp.channel.debug, .{ "mainview", "extract" });
|
||||||
var project_dir: []const u8 = undefined;
|
|
||||||
var editor_file_path: ?[]const u8 = undefined;
|
var editor_file_path: ?[]const u8 = undefined;
|
||||||
var prev_len = iter.len;
|
var prev_len = iter.len;
|
||||||
if (!try cbor.matchValue(iter, cbor.extract(&project_dir))) {
|
|
||||||
logger.print("restore project_dir failed", .{});
|
|
||||||
return error.MatchStoredProjectFailed;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (mode) {
|
|
||||||
.with_project => {
|
|
||||||
_ = try project_manager.open(project_dir);
|
|
||||||
tui.rdr().set_terminal_working_directory(project_dir);
|
|
||||||
if (self.top_bar) |bar| _ = try bar.msg(.{ "PRJ", "open" });
|
|
||||||
if (self.bottom_bar) |bar| _ = try bar.msg(.{ "PRJ", "open" });
|
|
||||||
},
|
|
||||||
.no_project => {},
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!try cbor.matchValue(iter, cbor.extract(&editor_file_path))) {
|
if (!try cbor.matchValue(iter, cbor.extract(&editor_file_path))) {
|
||||||
logger.print("restore editor_file_path failed", .{});
|
logger.print("restore editor_file_path failed", .{});
|
||||||
return error.MatchFilePathFailed;
|
return error.MatchFilePathFailed;
|
||||||
|
|
|
||||||
|
|
@ -87,8 +87,6 @@ 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 {
|
||||||
|
|
@ -259,15 +257,9 @@ 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();
|
||||||
|
|
@ -318,9 +310,6 @@ fn handle_input_idle(self: *Self) void {
|
||||||
var buf: [32]u8 = undefined;
|
var buf: [32]u8 = undefined;
|
||||||
const m = tp.message.fmtbuf(&buf, .{"input_idle"}) catch return;
|
const m = tp.message.fmtbuf(&buf, .{"input_idle"}) catch return;
|
||||||
_ = self.send_widgets(tp.self_pid(), m) catch return;
|
_ = self.send_widgets(tp.self_pid(), m) catch return;
|
||||||
const idle_cmds = self.config_.idle_commands orelse return;
|
|
||||||
for (idle_cmds) |cmd|
|
|
||||||
command.executeName(cmd, .{}) catch |e| self.logger.print_err("idlerun", "idle run command '{s}' failed: {t}", .{ cmd, e });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_input_idle_timer(self: *Self) void {
|
fn update_input_idle_timer(self: *Self) void {
|
||||||
|
|
@ -357,23 +346,6 @@ 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();
|
||||||
|
|
@ -538,13 +510,6 @@ 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