mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-25 13:16:11 +03:00
terminal/osc: allow empty payloads
xterm docs explicitly say that empty payloads should be permitted and are used to clear the selected clipboards, so we need to implement that correctly. The GTK apprt still shows a "Copied to Clipboard" toast though and we might want to change that too
This commit is contained in:
@ -800,6 +800,9 @@ pub const Parser = struct {
|
||||
self.temp_state = .{ .str = &self.command.clipboard_contents.data };
|
||||
self.buf_start = self.buf_idx;
|
||||
self.prepAllocableString();
|
||||
|
||||
// See clipboard_kind_end
|
||||
self.complete = true;
|
||||
},
|
||||
else => {
|
||||
self.command.clipboard_contents.kind = c;
|
||||
@ -812,6 +815,11 @@ pub const Parser = struct {
|
||||
self.temp_state = .{ .str = &self.command.clipboard_contents.data };
|
||||
self.buf_start = self.buf_idx;
|
||||
self.prepAllocableString();
|
||||
|
||||
// OSC 52 can have empty payloads (quoting xterm ctlseqs):
|
||||
// "If the second parameter is neither a base64 string nor ?,
|
||||
// then the selection is cleared."
|
||||
self.complete = true;
|
||||
},
|
||||
else => self.state = .invalid,
|
||||
},
|
||||
@ -1928,6 +1936,21 @@ test "OSC: get/set clipboard with allocator" {
|
||||
try testing.expect(std.mem.eql(u8, "?", cmd.clipboard_contents.data));
|
||||
}
|
||||
|
||||
test "OSC: clear clipboard" {
|
||||
const testing = std.testing;
|
||||
|
||||
var p: Parser = .{ .alloc = testing.allocator };
|
||||
defer p.deinit();
|
||||
|
||||
const input = "52;;";
|
||||
for (input) |ch| p.next(ch);
|
||||
|
||||
const cmd = p.end(null).?;
|
||||
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;
|
||||
|
||||
|
Reference in New Issue
Block a user