diff options
| author | Can Celik <ogulcancelik@gmail.com> | 2026-04-04 19:22:04 +0300 |
|---|---|---|
| committer | Can Celik <ogulcancelik@gmail.com> | 2026-04-05 01:23:06 +0300 |
| commit | 41dd733ca7123c9ac4bfc6c781697a660e95b052 (patch) | |
| tree | 3fc91815ca139ef2e0b281bba0abda4ef15175f4 /vendor/libghostty-vt/src/terminal/focus.zig | |
| parent | 55c138263e190a1e79d4b997bfb9397306c0ec1f (diff) | |
feat: finish ghostty pane backend integration
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()); +} |
