fix: correctly read inputs from *stdin* when not using *raw mode*
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m6s

This commit is contained in:
2026-01-23 12:44:48 +01:00
parent 4441f1b933
commit eb36c7c410

View File

@@ -443,6 +443,7 @@ pub fn App(comptime M: type, comptime E: type) type {
},
}
} else {
if (this.config.rawMode) {
const b = buf[0];
const key: Key = switch (b) {
0x00 => .{ .cp = '@', .mod = .{ .ctrl = true } },
@@ -460,12 +461,20 @@ pub fn App(comptime M: type, comptime E: type) type {
var len = read_bytes;
while (!std.unicode.utf8ValidateSlice(buf[0..len])) len -= 1;
remaining_bytes = read_bytes - len;
if (this.config.rawMode) {
var iter: std.unicode.Utf8Iterator = .{ .bytes = buf[0..len], .i = 0 };
while (iter.nextCodepoint()) |cp| this.postEvent(.{ .key = .{ .cp = cp } });
} else try lines.appendSlice(this.gpa, buf[0..len]);
if (remaining_bytes > 0) {
@memmove(buf[0..remaining_bytes], buf[len .. len + remaining_bytes]);
}
continue; // this switch block does not return a `Key` we continue with loop
},
};
this.postEvent(.{ .key = key });
} else {
var len = read_bytes;
while (!std.unicode.utf8ValidateSlice(buf[0..len])) len -= 1;
remaining_bytes = read_bytes - len;
try lines.appendSlice(this.gpa, buf[0..len]);
if (remaining_bytes > 0) {
@memmove(buf[0..remaining_bytes], buf[len .. len + remaining_bytes]);
} else {
@@ -476,10 +485,7 @@ pub fn App(comptime M: type, comptime E: type) type {
this.postEvent(.cancel);
}
}
continue; // this switch block does not return a `Key` we continue with loop
},
};
this.postEvent(.{ .key = key });
}
}
continue;
};