From bb2455b3fce9410114ebd391d144c60a9fa2677d Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Sun, 16 Nov 2025 11:27:59 -0700 Subject: [PATCH] fix(terminal/stream): handle executing C1 controls These can be unambiguously invoked in certain parser states, and as such we need to handle them. In real world use they are extremely rare, hence the branch hint. Without this, we get illegal behavior by trying to cast the value to the 7-bit C0 enum. --- src/terminal/stream.zig | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/terminal/stream.zig b/src/terminal/stream.zig index 23211fa80..de83dbe9c 100644 --- a/src/terminal/stream.zig +++ b/src/terminal/stream.zig @@ -660,6 +660,11 @@ pub fn Stream(comptime Handler: type) type { /// This function is abstracted this way to handle the case where /// the decoder emits a 0x1B after rejecting an ill-formed sequence. inline fn handleCodepoint(self: *Self, c: u21) !void { + // We need to increase the eval branch limit because a lot of + // tests end up running almost completely at comptime due to + // a chain of inline functions. + @setEvalBranchQuota(100_000); + if (c <= 0xF) { try self.execute(@intCast(c)); return; @@ -777,6 +782,18 @@ pub fn Stream(comptime Handler: type) type { } pub inline fn execute(self: *Self, c: u8) !void { + // If the character is > 0x7F, it's a C1 (8-bit) control, + // which is strictly equivalent to `ESC` plus `c - 0x40`. + if (c > 0x7F) { + @branchHint(.unlikely); + log.info("executing C1 0x{x} as ESC {c}", .{ c, c - 0x40 }); + try self.escDispatch(.{ + .intermediates = &.{}, + .final = c - 0x40, + }); + return; + } + const c0: ansi.C0 = @enumFromInt(c); if (comptime debug) log.info("execute: {f}", .{c0}); switch (c0) {