termio: indicate support for OSC 52 in primary DA report

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.
This commit is contained in:
James Holderness
2025-06-29 15:32:17 +01:00
parent 0d55a1deef
commit 7f0778bcf2
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(.{