mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 08:16:13 +03:00
fix(terminal/stream): correct invalid assertion
This commit is contained in:
@ -149,7 +149,7 @@ pub fn Stream(comptime Handler: type) type {
|
|||||||
/// try to get multiple bytes at once.
|
/// try to get multiple bytes at once.
|
||||||
pub fn next(self: *Self, c: u8) !void {
|
pub fn next(self: *Self, c: u8) !void {
|
||||||
// The scalar path can be responsible for decoding UTF-8.
|
// The scalar path can be responsible for decoding UTF-8.
|
||||||
if (self.parser.state == .ground and c != 0x1B) {
|
if (self.parser.state == .ground) {
|
||||||
try self.nextUtf8(c);
|
try self.nextUtf8(c);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -162,16 +162,12 @@ pub fn Stream(comptime Handler: type) type {
|
|||||||
/// This assumes we're in the UTF-8 decoding state. If we may not
|
/// This assumes we're in the UTF-8 decoding state. If we may not
|
||||||
/// be in the UTF-8 decoding state call nextSlice or next.
|
/// be in the UTF-8 decoding state call nextSlice or next.
|
||||||
fn nextUtf8(self: *Self, c: u8) !void {
|
fn nextUtf8(self: *Self, c: u8) !void {
|
||||||
assert(self.parser.state == .ground and c != 0x1B);
|
assert(self.parser.state == .ground);
|
||||||
|
|
||||||
const res = self.utf8decoder.next(c);
|
const res = self.utf8decoder.next(c);
|
||||||
const consumed = res[1];
|
const consumed = res[1];
|
||||||
if (res[0]) |codepoint| {
|
if (res[0]) |codepoint| {
|
||||||
if (codepoint <= 0xF) {
|
try self.handleCodepoint(codepoint);
|
||||||
try self.execute(@intCast(codepoint));
|
|
||||||
} else {
|
|
||||||
try self.print(@intCast(codepoint));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!consumed) {
|
if (!consumed) {
|
||||||
const retry = self.utf8decoder.next(c);
|
const retry = self.utf8decoder.next(c);
|
||||||
@ -179,13 +175,25 @@ pub fn Stream(comptime Handler: type) type {
|
|||||||
// to not consume the byte twice in a row.
|
// to not consume the byte twice in a row.
|
||||||
assert(retry[1] == true);
|
assert(retry[1] == true);
|
||||||
if (retry[0]) |codepoint| {
|
if (retry[0]) |codepoint| {
|
||||||
if (codepoint <= 0xF) {
|
try self.handleCodepoint(codepoint);
|
||||||
try self.execute(@intCast(codepoint));
|
|
||||||
} else {
|
|
||||||
try self.print(@intCast(codepoint));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// To be called whenever the utf-8 decoder produces a codepoint.
|
||||||
|
///
|
||||||
|
/// 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 {
|
||||||
|
if (c <= 0xF) {
|
||||||
|
try self.execute(@intCast(c));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (c == 0x1B) {
|
||||||
|
try self.nextNonUtf8(@intCast(c));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try self.print(@intCast(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Process the next character and call any callbacks if necessary.
|
/// Process the next character and call any callbacks if necessary.
|
||||||
|
Reference in New Issue
Block a user