write_scrollback_file binding

This commit is contained in:
Mitchell Hashimoto
2023-07-09 12:28:48 -07:00
parent 9a0d131b5b
commit 5faafbbfa5
3 changed files with 46 additions and 0 deletions

View File

@ -1113,6 +1113,42 @@ pub fn keyCallback(
try self.io_thread.wakeup.notify(); 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) { .toggle_dev_mode => if (DevMode.enabled) {
DevMode.instance.visible = !DevMode.instance.visible; DevMode.instance.visible = !DevMode.instance.visible;
try self.queueRender(); try self.queueRender();

View File

@ -393,6 +393,12 @@ pub const Config = struct {
.{ .toggle_dev_mode = {} }, .{ .toggle_dev_mode = {} },
); );
try result.keybind.set.put(
alloc,
.{ .key = .j, .mods = ctrlOrSuper(.{ .shift = true }) },
.{ .write_scrollback_file = {} },
);
// Windowing // Windowing
if (comptime !builtin.target.isDarwin()) { if (comptime !builtin.target.isDarwin()) {
try result.keybind.set.put( try result.keybind.set.put(

View File

@ -174,6 +174,10 @@ pub const Action = union(enum) {
/// is backwards. /// is backwards.
jump_to_prompt: i16, 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 /// Dev mode
toggle_dev_mode: void, toggle_dev_mode: void,