mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-05 17:36:32 +00:00
OSC 52: Clipboard Control (#52)
This adds support for OSC 52 -- applications can read/write the clipboard. Due to the security risk of this, the default configuration allows for writing but _not reading_. This is configurable using two new settings: `clipboard-read` and `clipboard-write` (both booleans).
This commit is contained in:

committed by
GitHub

parent
173aff1e80
commit
56de5846f4
@@ -567,6 +567,31 @@ test "osc: change window title" {
|
||||
|
||||
const cmd = a[0].?.osc_dispatch;
|
||||
try testing.expect(cmd == .change_window_title);
|
||||
try testing.expectEqualStrings("abc", cmd.change_window_title);
|
||||
}
|
||||
}
|
||||
|
||||
test "osc: change window title (end in esc)" {
|
||||
var p = init();
|
||||
_ = p.next(0x1B);
|
||||
_ = p.next(']');
|
||||
_ = p.next('0');
|
||||
_ = p.next(';');
|
||||
_ = p.next('a');
|
||||
_ = p.next('b');
|
||||
_ = p.next('c');
|
||||
|
||||
{
|
||||
const a = p.next(0x1B);
|
||||
_ = p.next('\\');
|
||||
try testing.expect(p.state == .ground);
|
||||
try testing.expect(a[0].? == .osc_dispatch);
|
||||
try testing.expect(a[1] == null);
|
||||
try testing.expect(a[2] == null);
|
||||
|
||||
const cmd = a[0].?.osc_dispatch;
|
||||
try testing.expect(cmd == .change_window_title);
|
||||
try testing.expectEqualStrings("abc", cmd.change_window_title);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -326,11 +326,7 @@ pub const Parser = struct {
|
||||
else => self.state = .invalid,
|
||||
},
|
||||
|
||||
.string => {
|
||||
// Complete once we receive one character since we have
|
||||
// at least SOME value for the expected string value.
|
||||
self.complete = true;
|
||||
},
|
||||
.string => self.complete = true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,6 +348,10 @@ pub const Parser = struct {
|
||||
}
|
||||
}
|
||||
|
||||
fn endString(self: *Parser) void {
|
||||
self.temp_state.str.* = self.buf[self.buf_start..self.buf_idx];
|
||||
}
|
||||
|
||||
/// End the sequence and return the command, if any. If the return value
|
||||
/// is null, then no valid command was found.
|
||||
pub fn end(self: *Parser) ?Command {
|
||||
@@ -364,7 +364,7 @@ pub const Parser = struct {
|
||||
switch (self.state) {
|
||||
.semantic_exit_code => self.endSemanticExitCode(),
|
||||
.semantic_option_value => self.endSemanticOptionValue(),
|
||||
.string => self.temp_state.str.* = self.buf[self.buf_start..self.buf_idx],
|
||||
.string => self.endString(),
|
||||
else => {},
|
||||
}
|
||||
|
||||
|
@@ -464,6 +464,12 @@ pub fn Stream(comptime Handler: type) type {
|
||||
} else log.warn("unimplemented OSC callback: {}", .{cmd});
|
||||
},
|
||||
|
||||
.clipboard_contents => |clip| {
|
||||
if (@hasDecl(T, "clipboardContents")) {
|
||||
try self.handler.clipboardContents(clip.kind, clip.data);
|
||||
} else log.warn("unimplemented OSC callback: {}", .{cmd});
|
||||
},
|
||||
|
||||
else => if (@hasDecl(T, "oscUnimplemented"))
|
||||
try self.handler.oscUnimplemented(cmd)
|
||||
else
|
||||
|
Reference in New Issue
Block a user