mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-07-28 19:46:35 +00:00
input: use std.Io.Writer for key encoder, new API, expose via libghostty
This modernizes `KeyEncoder` to a new `std.Io.Writer`-based API. Additionally, instead of a single struct, it is now an `encode` function that takes a series of more focused options. This is more idiomatic Zig while also making it easier to expose via libghostty-vt. libghostty-vt also gains access to key encoding APIs.
This commit is contained in:
@@ -8,7 +8,7 @@ const std = @import("std");
|
||||
pub const FlagStack = struct {
|
||||
const len = 8;
|
||||
|
||||
flags: [len]Flags = @splat(.{}),
|
||||
flags: [len]Flags = @splat(.disabled),
|
||||
idx: u3 = 0,
|
||||
|
||||
/// Return the current stack value
|
||||
@@ -51,12 +51,12 @@ pub const FlagStack = struct {
|
||||
// could send a huge number of pop commands to waste cpu.
|
||||
if (n >= self.flags.len) {
|
||||
self.idx = 0;
|
||||
self.flags = @splat(.{});
|
||||
self.flags = @splat(.disabled);
|
||||
return;
|
||||
}
|
||||
|
||||
for (0..n) |_| {
|
||||
self.flags[self.idx] = .{};
|
||||
self.flags[self.idx] = .disabled;
|
||||
self.idx -%= 1;
|
||||
}
|
||||
}
|
||||
@@ -83,6 +83,15 @@ pub const Flags = packed struct(u5) {
|
||||
report_all: bool = false,
|
||||
report_associated: bool = false,
|
||||
|
||||
/// Kitty keyboard protocol disabled (all flags off).
|
||||
pub const disabled: Flags = .{
|
||||
.disambiguate = false,
|
||||
.report_events = false,
|
||||
.report_alternates = false,
|
||||
.report_all = false,
|
||||
.report_associated = false,
|
||||
};
|
||||
|
||||
/// Sets all modes on.
|
||||
pub const @"true": Flags = .{
|
||||
.disambiguate = true,
|
||||
|
||||
Reference in New Issue
Block a user