mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
core: print current selection to file
This commit is contained in:
@ -3193,6 +3193,46 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
|
|||||||
try self.io_thread.wakeup.notify();
|
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: {
|
.write_scrollback_file => write_scrollback_file: {
|
||||||
// Create a temporary directory to store our scrollback.
|
// Create a temporary directory to store our scrollback.
|
||||||
var tmp_dir = try internal_os.TempDir.init();
|
var tmp_dir = try internal_os.TempDir.init();
|
||||||
|
@ -1214,6 +1214,12 @@ pub fn default(alloc_gpa: Allocator) Allocator.Error!Config {
|
|||||||
.{ .reset_font_size = {} },
|
.{ .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(
|
try result.keybind.set.put(
|
||||||
alloc,
|
alloc,
|
||||||
.{ .key = .{ .translated = .j }, .mods = inputpkg.ctrlOrSuper(.{ .shift = true }) },
|
.{ .key = .{ .translated = .j }, .mods = inputpkg.ctrlOrSuper(.{ .shift = true }) },
|
||||||
|
@ -199,6 +199,10 @@ pub const Action = union(enum) {
|
|||||||
/// number of prompts to jump forward, negative is backwards.
|
/// number of prompts to jump forward, negative is backwards.
|
||||||
jump_to_prompt: i16,
|
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
|
/// Write the entire scrollback into a temporary file and write the path to
|
||||||
/// the file to the tty.
|
/// the file to the tty.
|
||||||
write_scrollback_file: void,
|
write_scrollback_file: void,
|
||||||
|
Reference in New Issue
Block a user