From 59fd918443d390035c2f95bdbc51765df8f373ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Hovs=C3=A4ter?= Date: Tue, 22 Aug 2023 13:23:03 +0200 Subject: [PATCH] Allow optional OSC 52 parameter Quoting from the XTerm documentation: The first, Pc, may contain zero or more characters from the set c, p, q, s, 0, 1, 2, 3, 4, 5, 6, and 7. It is used to construct a list of selection parameters for clipboard, primary, secondary, select, or cut-buffers 0 through 7 respectively, in the order given. If the parameter is empty, xterm uses s 0 , to specify the configurable primary/clipboard selection and cut-buffer 0. See https://invisible-island.net/xterm/ctlseqs/ctlseqs.html --- src/terminal/osc.zig | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/terminal/osc.zig b/src/terminal/osc.zig index 6adebf430..44e4b4bb5 100644 --- a/src/terminal/osc.zig +++ b/src/terminal/osc.zig @@ -260,7 +260,12 @@ pub const Parser = struct { }, .clipboard_kind => switch (c) { - ';' => self.state = .invalid, + ';' => { + self.command.clipboard_contents.kind = 'c'; + self.state = .string; + self.temp_state = .{ .str = &self.command.clipboard_contents.data }; + self.buf_start = self.buf_idx; + }, else => { self.command.clipboard_contents.kind = c; self.state = .clipboard_kind_end; @@ -580,6 +585,20 @@ test "OSC: get/set clipboard" { try testing.expect(std.mem.eql(u8, "?", cmd.clipboard_contents.data)); } +test "OSC: get/set clipboard (optional parameter)" { + const testing = std.testing; + + var p: Parser = .{}; + + const input = "52;;?"; + for (input) |ch| p.next(ch); + + const cmd = p.end().?; + try testing.expect(cmd == .clipboard_contents); + try testing.expect(cmd.clipboard_contents.kind == 'c'); + try testing.expect(std.mem.eql(u8, "?", cmd.clipboard_contents.data)); +} + test "OSC: report pwd" { const testing = std.testing;