diff --git a/src/Surface.zig b/src/Surface.zig index 25fa09713..fee7425a4 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -3193,6 +3193,46 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool try self.io_thread.wakeup.notify(); }, + .write_selection_file => write_selection_file: { + // Create a temporary directory to store our selection. + var tmp_dir = try internal_os.TempDir.init(); + errdefer tmp_dir.deinit(); + + // Open our selection file + var file = try tmp_dir.dir.createFile("selection", .{}); + defer file.close(); + + // Write the selection contents. This requires a lock. + { + self.renderer_state.mutex.lock(); + defer self.renderer_state.mutex.unlock(); + + // We do not support this for alternate screens + // because they don't have output anyways. + if (self.io.terminal.active_screen == .alternate) { + tmp_dir.deinit(); + break :write_selection_file; + } + + if (self.io.terminal.screen.selection) |selection| { + try self.io.terminal.screen.dumpString( + file.writer(), + .{ .tl = selection.start(), .br = selection.end(), .unwrap = true }, + ); + } + } + + // Get the final path + var path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + const path = try tmp_dir.dir.realpath("selection", &path_buf); + + _ = self.io_thread.mailbox.push(try termio.Message.writeReq( + self.alloc, + path, + ), .{ .forever = {} }); + try self.io_thread.wakeup.notify(); + }, + .write_scrollback_file => write_scrollback_file: { // Create a temporary directory to store our scrollback. var tmp_dir = try internal_os.TempDir.init(); diff --git a/src/config/Config.zig b/src/config/Config.zig index 42e6cd584..aeb986563 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -1214,6 +1214,12 @@ pub fn default(alloc_gpa: Allocator) Allocator.Error!Config { .{ .reset_font_size = {} }, ); + try result.keybind.set.put( + alloc, + .{ .key = .{ .translated = .j }, .mods = inputpkg.ctrlOrSuper(.{ .ctrl = true }) }, + .{ .write_selection_file = {} }, + ); + try result.keybind.set.put( alloc, .{ .key = .{ .translated = .j }, .mods = inputpkg.ctrlOrSuper(.{ .shift = true }) }, diff --git a/src/input/Binding.zig b/src/input/Binding.zig index 5640843d9..add7dcd78 100644 --- a/src/input/Binding.zig +++ b/src/input/Binding.zig @@ -199,6 +199,10 @@ pub const Action = union(enum) { /// number of prompts to jump forward, negative is backwards. jump_to_prompt: i16, + /// Write the selection into a temporary file and write the path to the file + /// to the tty. + write_selection_file: void, + /// Write the entire scrollback into a temporary file and write the path to /// the file to the tty. write_scrollback_file: void,