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
This commit is contained in:
Kevin Hovsäter
2023-08-22 13:23:03 +02:00
parent 99abff85dd
commit 59fd918443

View File

@ -260,7 +260,12 @@ pub const Parser = struct {
}, },
.clipboard_kind => switch (c) { .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 => { else => {
self.command.clipboard_contents.kind = c; self.command.clipboard_contents.kind = c;
self.state = .clipboard_kind_end; 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)); 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" { test "OSC: report pwd" {
const testing = std.testing; const testing = std.testing;