diff options
| author | Can Celik <ogulcancelik@gmail.com> | 2026-09-10 21:51:57 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-09-10 21:51:57 +0300 |
| commit | 425c86179791cd32e2d4ce0ae7f269940b4b0663 (patch) | |
| tree | e52c4383a6d69216cbe2a32638bf90841d7e2189 /vendor/libghostty-vt/src/terminal/device_status.zig | |
| parent | 90e947a6e26e02f10ec7f1694c4eb5b78a86406b (diff) | |
chore: upgrade libghostty and preserve terminal behavior (#3906)
Diffstat (limited to 'vendor/libghostty-vt/src/terminal/device_status.zig')
| -rw-r--r-- | vendor/libghostty-vt/src/terminal/device_status.zig | 60 |
1 files changed, 44 insertions, 16 deletions
diff --git a/vendor/libghostty-vt/src/terminal/device_status.zig b/vendor/libghostty-vt/src/terminal/device_status.zig index fd1a9b7e..9d158f39 100644 --- a/vendor/libghostty-vt/src/terminal/device_status.zig +++ b/vendor/libghostty-vt/src/terminal/device_status.zig @@ -7,6 +7,13 @@ pub const ColorScheme = lib.Enum(lib.target, &.{ "dark", }); +/// The visibility state reported in response to a CSI ? 998 n query or when +/// DEC mode 2033 is enabled. +pub const Visibility = lib.Enum(lib.target, &.{ + "potentially_visible", + "not_visible", +}); + /// Maximum number of bytes that `encodeColorSchemeReport` will write. pub const max_color_scheme_report_encode_size = max: { var result: usize = 0; @@ -33,26 +40,35 @@ pub fn encodeColorSchemeReport( }); } +/// Maximum number of bytes that `encodeVisibilityReport` will write. +pub const max_visibility_report_encode_size = "\x1B[?999;2n".len; + +/// Encode a visibility report response for CSI ? 998 n queries and DEC mode +/// 2033 notifications. +pub fn encodeVisibilityReport( + writer: *std.Io.Writer, + visibility: Visibility, +) std.Io.Writer.Error!void { + try writer.writeAll(switch (visibility) { + .potentially_visible => "\x1B[?999;1n", + .not_visible => "\x1B[?999;2n", + }); +} + /// An enum(u16) of the available device status requests. pub const Request = dsr_enum: { - const EnumField = std.builtin.Type.EnumField; - var fields: [entries.len]EnumField = undefined; - for (entries, 0..) |entry, i| { - fields[i] = .{ - .name = entry.name, - .value = @as(Tag.Backing, @bitCast(Tag{ - .value = entry.value, - .question = entry.question, - })), - }; + var names: [entries.len][]const u8 = undefined; + var values: [entries.len]Tag.Backing = undefined; + + for (entries, &names, &values) |entry, *name, *value| { + name.* = entry.name; + value.* = @bitCast(Tag{ + .value = entry.value, + .question = entry.question, + }); } - break :dsr_enum @Type(.{ .@"enum" = .{ - .tag_type = Tag.Backing, - .fields = &fields, - .decls = &.{}, - .is_exhaustive = true, - } }); + break :dsr_enum @Enum(Tag.Backing, .exhaustive, &names, &values); }; /// The tag type for our enum is a u16 but we use a packed struct @@ -97,6 +113,7 @@ const entries: []const Entry = &.{ .{ .name = "operating_status", .value = 5 }, .{ .name = "cursor_position", .value = 6 }, .{ .name = "color_scheme", .value = 996, .question = true }, + .{ .name = "visibility", .value = 998, .question = true }, }; test "encode color scheme report dark" { @@ -114,3 +131,14 @@ test "encode color scheme report light" { try encodeColorSchemeReport(&writer, .light); try std.testing.expectEqualStrings("\x1B[?997;2n", writer.buffered()); } + +test "encode visibility report" { + var buf: [max_visibility_report_encode_size]u8 = undefined; + var writer: std.Io.Writer = .fixed(&buf); + try encodeVisibilityReport(&writer, .potentially_visible); + try std.testing.expectEqualStrings("\x1B[?999;1n", writer.buffered()); + + writer = .fixed(&buf); + try encodeVisibilityReport(&writer, .not_visible); + try std.testing.expectEqualStrings("\x1B[?999;2n", writer.buffered()); +} |
