termio: indicate support for OSC 52 in primary DA report (#7725)

This is an extension agreed upon by modern terminals to indicate that
they support copying to the clipboard with XTerm's OSC 52 sequence. It
is only reported when writing to the clipboard is actually allowed.

Ref: #7590
pull/5374/head
Mitchell Hashimoto 2025-06-29 19:18:53 -07:00 committed by GitHub
commit 2592286988
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View File

@ -168,6 +168,7 @@ pub const DerivedConfig = struct {
foreground: configpkg.Config.Color,
background: configpkg.Config.Color,
osc_color_report_format: configpkg.Config.OSCColorReportFormat,
clipboard_write: configpkg.ClipboardAccess,
enquiry_response: []const u8,
pub fn init(
@ -188,6 +189,7 @@ pub const DerivedConfig = struct {
.foreground = config.foreground,
.background = config.background,
.osc_color_report_format = config.@"osc-color-report-format",
.clipboard_write = config.@"clipboard-write",
.enquiry_response = try alloc.dupe(u8, config.@"enquiry-response"),
// This has to be last so that we copy AFTER the arena allocations
@ -278,6 +280,7 @@ pub fn init(self: *Termio, alloc: Allocator, opts: termio.Options) !void {
.size = &self.size,
.terminal = &self.terminal,
.osc_color_report_format = opts.config.osc_color_report_format,
.clipboard_write = opts.config.clipboard_write,
.enquiry_response = opts.config.enquiry_response,
.default_foreground_color = opts.config.foreground.toTerminalRGB(),
.default_background_color = opts.config.background.toTerminalRGB(),

View File

@ -74,6 +74,9 @@ pub const StreamHandler = struct {
/// The color reporting format for OSC requests.
osc_color_report_format: configpkg.Config.OSCColorReportFormat,
/// The clipboard write access configuration.
clipboard_write: configpkg.ClipboardAccess,
//---------------------------------------------------------------
// Internal state
@ -112,6 +115,7 @@ pub const StreamHandler = struct {
/// Change the configuration for this handler.
pub fn changeConfig(self: *StreamHandler, config: *termio.DerivedConfig) void {
self.osc_color_report_format = config.osc_color_report_format;
self.clipboard_write = config.clipboard_write;
self.enquiry_response = config.enquiry_response;
self.default_foreground_color = config.foreground.toTerminalRGB();
self.default_background_color = config.background.toTerminalRGB();
@ -723,7 +727,13 @@ pub const StreamHandler = struct {
// a 420 because we don't support DCS sequences.
switch (req) {
.primary => self.messageWriter(.{
.write_stable = "\x1B[?62;22c",
// 62 = Level 2 conformance
// 22 = Color text
// 52 = Clipboard access
.write_stable = if (self.clipboard_write != .deny)
"\x1B[?62;22;52c"
else
"\x1B[?62;22c",
}),
.secondary => self.messageWriter(.{