fix: allow wrapping in putstr calls on scrollable vaxis planes

This commit is contained in:
CJ van den Berg 2024-05-20 11:06:27 +02:00
parent b3543f520c
commit 26232c3af3
2 changed files with 7 additions and 5 deletions

View file

@ -142,8 +142,6 @@ pub fn putstr(self: *Plane, text: []const u8) !usize {
const width = self.window.width; const width = self.window.width;
var iter = self.window.screen.unicode.graphemeIterator(text); var iter = self.window.screen.unicode.graphemeIterator(text);
while (iter.next()) |grapheme| { while (iter.next()) |grapheme| {
if (self.col >= width)
return result;
const s = grapheme.bytes(text); const s = grapheme.bytes(text);
if (std.mem.eql(u8, s, "\n")) { if (std.mem.eql(u8, s, "\n")) {
if (self.scrolling and self.row == height - 1) if (self.scrolling and self.row == height - 1)
@ -154,6 +152,12 @@ pub fn putstr(self: *Plane, text: []const u8) !usize {
result += 1; result += 1;
continue; continue;
} }
if (self.col >= width) {
if (self.scrolling) {
self.row += 1;
self.col = 0;
} else return result;
}
self.write_cell(@intCast(self.col), @intCast(self.row), s); self.write_cell(@intCast(self.col), @intCast(self.row), s);
result += 1; result += 1;
} }

View file

@ -46,7 +46,6 @@ pub fn deinit(self: *Self, a: Allocator) void {
pub fn render(self: *Self, theme: *const Widget.Theme) bool { pub fn render(self: *Self, theme: *const Widget.Theme) bool {
self.plane.set_base_style(" ", theme.panel); self.plane.set_base_style(" ", theme.panel);
self.plane.erase(); self.plane.erase();
self.plane.home(); self.plane.home();
const height = self.plane.dim_y(); const height = self.plane.dim_y();
@ -57,11 +56,10 @@ pub fn render(self: *Self, theme: *const Widget.Theme) bool {
for (buffer.items[begin_at..]) |item| { for (buffer.items[begin_at..]) |item| {
if (first) first = false else _ = self.plane.putstr("\n") catch return false; if (first) first = false else _ = self.plane.putstr("\n") catch return false;
self.output_tdiff(item.tdiff) catch return false; self.output_tdiff(item.tdiff) catch return false;
_ = self.plane.print("{s}: {s}", .{ escape(item.src), escape(item.msg) }) catch return false; _ = self.plane.print("{s}: {s}", .{ escape(item.src), escape(item.msg) }) catch {};
} }
if (last_count > 0) if (last_count > 0)
_ = self.plane.print(" ({})", .{last_count}) catch {}; _ = self.plane.print(" ({})", .{last_count}) catch {};
return false; return false;
} }