diff --git a/src/Window.zig b/src/Window.zig index fcbb00ebe..0eb69672b 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -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}), } } diff --git a/src/terminal/ansi.zig b/src/terminal/ansi.zig index 61221e93b..f64fcf1c8 100644 --- a/src/terminal/ansi.zig +++ b/src/terminal/ansi.zig @@ -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. _, };