terminal: device attributes

pull/9342/head
Mitchell Hashimoto 2025-10-24 07:08:09 -07:00
parent 109376115b
commit e347ab6915
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
3 changed files with 26 additions and 21 deletions

View File

@ -53,11 +53,14 @@ pub const RenditionAspect = enum(u16) {
};
/// The device attribute request type (ESC [ c).
pub const DeviceAttributeReq = enum {
primary, // Blank
secondary, // >
tertiary, // =
};
pub const DeviceAttributeReq = lib.Enum(
lib_target,
&.{
"primary", // Blank
"secondary", // >
"tertiary", // =
},
);
/// Possible cursor styles (ESC [ q)
pub const CursorStyle = enum(u16) {

View File

@ -93,6 +93,7 @@ pub const Action = union(Key) {
title_push: u16,
title_pop: u16,
xtversion,
device_attributes: ansi.DeviceAttributeReq,
kitty_keyboard_query,
kitty_keyboard_push: KittyKeyboardFlags,
kitty_keyboard_pop: u16,
@ -177,6 +178,7 @@ pub const Action = union(Key) {
"title_push",
"title_pop",
"xtversion",
"device_attributes",
"kitty_keyboard_query",
"kitty_keyboard_push",
"kitty_keyboard_pop",
@ -1042,22 +1044,24 @@ pub fn Stream(comptime Handler: type) type {
},
// c - Device Attributes (DA1)
'c' => if (@hasDecl(T, "deviceAttributes")) {
const req: ansi.DeviceAttributeReq = switch (input.intermediates.len) {
0 => ansi.DeviceAttributeReq.primary,
'c' => {
const req: ?ansi.DeviceAttributeReq = switch (input.intermediates.len) {
0 => .primary,
1 => switch (input.intermediates[0]) {
'>' => ansi.DeviceAttributeReq.secondary,
'=' => ansi.DeviceAttributeReq.tertiary,
'>' => .secondary,
'=' => .tertiary,
else => null,
},
else => @as(?ansi.DeviceAttributeReq, null),
} orelse {
log.warn("invalid device attributes command: {f}", .{input});
return;
else => null,
};
try self.handler.deviceAttributes(req, input.params);
} else log.warn("unimplemented CSI callback: {f}", .{input}),
if (req) |r| {
try self.handler.vt(.device_attributes, r);
} else {
log.warn("invalid device attributes command: {f}", .{input});
return;
}
},
// VPA - Cursor Vertical Position Absolute
'd' => switch (input.intermediates.len) {
@ -1963,8 +1967,8 @@ pub fn Stream(comptime Handler: type) type {
},
// DECID
'Z' => if (@hasDecl(T, "deviceAttributes") and action.intermediates.len == 0) {
try self.handler.deviceAttributes(.primary, &.{});
'Z' => if (action.intermediates.len == 0) {
try self.handler.vt(.device_attributes, .primary);
} else log.warn("unimplemented ESC callback: {f}", .{action}),
// RIS - Full Reset

View File

@ -277,6 +277,7 @@ pub const StreamHandler = struct {
.mouse_shift_capture => self.terminal.flags.mouse_shift_capture = if (value) .true else .false,
.size_report => self.sendSizeReport(value),
.xtversion => try self.reportXtversion(),
.device_attributes => try self.deviceAttributes(value),
.kitty_keyboard_query => try self.queryKittyKeyboard(),
.kitty_keyboard_push => {
log.debug("pushing kitty keyboard mode: {}", .{value.flags});
@ -722,10 +723,7 @@ pub const StreamHandler = struct {
pub fn deviceAttributes(
self: *StreamHandler,
req: terminal.DeviceAttributeReq,
params: []const u16,
) !void {
_ = params;
// For the below, we quack as a VT220. We don't quack as
// a 420 because we don't support DCS sequences.
switch (req) {