diff options
Diffstat (limited to 'vendor/libghostty-vt/src/terminal/focus.zig')
| -rw-r--r-- | vendor/libghostty-vt/src/terminal/focus.zig | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/src/terminal/focus.zig b/vendor/libghostty-vt/src/terminal/focus.zig new file mode 100644 index 00000000..91c579e1 --- /dev/null +++ b/vendor/libghostty-vt/src/terminal/focus.zig @@ -0,0 +1,39 @@ +const std = @import("std"); +const lib = @import("lib.zig"); + +/// Maximum number of bytes that `encode` will write. Any users of this +/// should be resilient to this changing, so this is always a specific +/// value (e.g. we don't add unnecessary padding). +pub const max_encode_size = 3; + +/// A focus event that can be reported to the application running in the +/// terminal when focus reporting mode (mode 1004) is enabled. +pub const Event = lib.Enum(lib.target, &.{ + "gained", + "lost", +}); + +/// Encode a focus in/out report (CSI I / CSI O). +pub fn encode( + writer: *std.Io.Writer, + event: Event, +) std.Io.Writer.Error!void { + try writer.writeAll(switch (event) { + .gained => "\x1B[I", + .lost => "\x1B[O", + }); +} + +test "encode focus gained" { + var buf: [max_encode_size]u8 = undefined; + var writer: std.Io.Writer = .fixed(&buf); + try encode(&writer, .gained); + try std.testing.expectEqualStrings("\x1B[I", writer.buffered()); +} + +test "encode focus lost" { + var buf: [max_encode_size]u8 = undefined; + var writer: std.Io.Writer = .fixed(&buf); + try encode(&writer, .lost); + try std.testing.expectEqualStrings("\x1B[O", writer.buffered()); +} |
