Measure styled smoke frames by visible cells

This commit is contained in:
slhx agent
2026-06-21 22:21:19 +02:00
parent f00eddcb2b
commit 6271fac301
+23 -1
View File
@@ -250,6 +250,28 @@ test "regular: ns8 local production smoke covers editor workflow before real-dev
fn frameLinesFit(frame: []const u8, width: usize) bool {
var lines = std.mem.splitScalar(u8, frame, '\n');
while (lines.next()) |line| if (line.len > width) return false;
while (lines.next()) |line| if (visibleCells(line) > width) return false;
return true;
}
fn visibleCells(line: []const u8) usize {
var cells: usize = 0;
var i: usize = 0;
while (i < line.len) {
if (line[i] == 0x1b and i + 1 < line.len and line[i + 1] == '[') {
i += 2;
while (i < line.len) : (i += 1) {
const byte = line[i];
if ((byte >= 'A' and byte <= 'Z') or (byte >= 'a' and byte <= 'z')) {
i += 1;
break;
}
}
continue;
}
const len = std.unicode.utf8ByteSequenceLength(line[i]) catch 1;
cells += 1;
i += @min(len, line.len - i);
}
return cells;
}