Measure styled smoke frames by visible cells
This commit is contained in:
+23
-1
@@ -250,6 +250,28 @@ test "regular: ns8 local production smoke covers editor workflow before real-dev
|
|||||||
|
|
||||||
fn frameLinesFit(frame: []const u8, width: usize) bool {
|
fn frameLinesFit(frame: []const u8, width: usize) bool {
|
||||||
var lines = std.mem.splitScalar(u8, frame, '\n');
|
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;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user