From 5faafbbfa5d0104b70e1361dea34e9c5b6f0d2b7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 9 Jul 2023 12:28:48 -0700 Subject: [PATCH] write_scrollback_file binding --- src/Surface.zig | 36 ++++++++++++++++++++++++++++++++++++ src/config.zig | 6 ++++++ src/input/Binding.zig | 4 ++++ 3 files changed, 46 insertions(+) diff --git a/src/Surface.zig b/src/Surface.zig index 3f0e0b25b..d5a994556 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -1113,6 +1113,42 @@ pub fn keyCallback( try self.io_thread.wakeup.notify(); }, + .write_scrollback_file => { + // Create a temporary directory to store our scrollback. + var tmp_dir = try internal_os.TempDir.init(); + errdefer tmp_dir.deinit(); + + // Open our scrollback file + var file = try tmp_dir.dir.createFile("scrollback", .{}); + defer file.close(); + + // Write the scrollback contents. This requires a lock. + { + self.renderer_state.mutex.lock(); + defer self.renderer_state.mutex.unlock(); + + const history_max = terminal.Screen.RowIndexTag.history.maxLen( + &self.io.terminal.screen, + ); + + try self.io.terminal.screen.dumpString(file.writer(), .{ + .start = .{ .history = 0 }, + .end = .{ .history = history_max -| 1 }, + .unwrap = true, + }); + } + + // Get the final path + var path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + const path = try tmp_dir.dir.realpath("scrollback", &path_buf); + + _ = self.io_thread.mailbox.push(try termio.Message.writeReq( + self.alloc, + path, + ), .{ .forever = {} }); + try self.io_thread.wakeup.notify(); + }, + .toggle_dev_mode => if (DevMode.enabled) { DevMode.instance.visible = !DevMode.instance.visible; try self.queueRender(); diff --git a/src/config.zig b/src/config.zig index feeea8cd2..0a7f9f533 100644 --- a/src/config.zig +++ b/src/config.zig @@ -393,6 +393,12 @@ pub const Config = struct { .{ .toggle_dev_mode = {} }, ); + try result.keybind.set.put( + alloc, + .{ .key = .j, .mods = ctrlOrSuper(.{ .shift = true }) }, + .{ .write_scrollback_file = {} }, + ); + // Windowing if (comptime !builtin.target.isDarwin()) { try result.keybind.set.put( diff --git a/src/input/Binding.zig b/src/input/Binding.zig index 010992960..f57ecaae0 100644 --- a/src/input/Binding.zig +++ b/src/input/Binding.zig @@ -174,6 +174,10 @@ pub const Action = union(enum) { /// is backwards. jump_to_prompt: i16, + /// Write the entire scrollback into a temporary file and write the + /// path to the file to the tty. + write_scrollback_file: void, + /// Dev mode toggle_dev_mode: void,