Skip to content

Commit

Permalink
write_scrollback_file binding
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Jul 9, 2023
1 parent 9a0d131 commit 5faafbb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/Surface.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions src/config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions src/input/Binding.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down

0 comments on commit 5faafbb

Please sign in to comment.