diff options
| author | Leah Amelia Chen <hi@pluie.me> | 2025-07-22 16:14:53 +0000 |
|---|---|---|
| committer | Leah Amelia Chen <hi@pluie.me> | 2025-07-22 16:50:29 +0000 |
| commit | d3f40d70e25d86a692f5d1ec846b326ef58dc958 (patch) | |
| tree | 2861d924bbf35aa485228a7beed3b36cd0bc762b | |
| parent | 820879d2efb5679e1e1fee0d78ccaa29fb8a8312 (diff) | |
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
| -rw-r--r-- | src/terminal/osc.zig | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/terminal/osc.zig b/src/terminal/osc.zig index 9c35bd07e..7875f2037 100644 --- a/src/terminal/osc.zig +++ b/src/terminal/osc.zig @@ -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; |
