bracketed paste

This commit is contained in:
Mitchell Hashimoto
2022-05-20 16:01:57 -07:00
parent 92b7488449
commit 00a9987cd9
2 changed files with 16 additions and 0 deletions

View File

@ -90,6 +90,9 @@ bg_g: f32,
bg_b: f32,
bg_a: f32,
/// Bracketed paste mode
bracketed_paste: bool = false,
/// Create a new window. This allocates and returns a pointer because we
/// need a stable pointer for user data callbacks. Therefore, a stack-only
/// initialization is not currently possible.
@ -390,8 +393,11 @@ fn keyCallback(
if (data.len > 0) {
const win = window.getUserPointer(Window) orelse return;
if (win.bracketed_paste) win.queueWrite("\x1B[200~") catch unreachable;
win.queueWrite(data) catch |err|
log.warn("error pasting clipboard: {}", .{err});
if (win.bracketed_paste) win.queueWrite("\x1B[201~") catch unreachable;
}
return;
@ -677,6 +683,8 @@ pub fn setMode(self: *Window, mode: terminal.Mode, enabled: bool) !void {
unreachable; // TODO: implement
},
.bracketed_paste => self.bracketed_paste = true,
else => if (enabled) log.warn("unimplemented mode: {}", .{mode}),
}
}

View File

@ -39,6 +39,14 @@ pub const Mode = enum(u16) {
/// the current scroll region.
origin = 6,
/// Bracket clipboard paste contents in delimiter sequences.
///
/// When pasting from the (e.g. system) clipboard add "ESC [ 2 0 0 ~"
/// before the clipboard contents and "ESC [ 2 0 1 ~" after the clipboard
/// contents. This allows applications to distinguish clipboard contents
/// from manually typed text.
bracketed_paste = 2004,
// Non-exhaustive so that @intToEnum never fails for unsupported modes.
_,
};