diff options
Diffstat (limited to 'dev/tui/tui.zig')
| -rw-r--r-- | dev/tui/tui.zig | 55 |
1 files changed, 51 insertions, 4 deletions
diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index e2cdd2fa..44f931b6 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -442,6 +442,11 @@ fn terminalSize(cols: u16, rows: u16, pixel_w: u16, pixel_h: u16) @FieldType(par .w = @intCast(terminalCellPixels(pixel_w, cols, 8)), .h = @intCast(terminalCellPixels(pixel_h, rows, 16)), }, + // A terminal's tag and body are one cell: its own row metrics, said, + // never those of the view its client's was opened from (a window's + // tagline is narrower than its body: a tag wrapped at a fifth more + // than its row held, the middle of a long tag never shown). + .row_metrics = .{}, }; } @@ -1240,9 +1245,8 @@ const Shell = struct { /// The session's replica clients (core/replica.zig), on sockets: the /// session loop's (runtime/session.zig); a client's, none. peers: *replica.Peers, - /// This wait took only a replica's post (its input, its join): the - /// pump after it reads no new time, so it moves nothing the replicas' - /// speculations stand on (a replica takes such a unit as is). + /// This wait took nothing but a replica's post, if one (its input, its + /// join): the pump after one reads no new time (Peers.heldNow). mail_only: bool = false, waited: bool = false, /// This wait's steps so far, and the input held for the next (`split`). @@ -1321,7 +1325,7 @@ const Shell = struct { const s = of(ctx); if (s.waited) { s.waited = false; - if (s.mail_only and s.peers.count() > 0 and s.core.clock.started) return s.core.clock.now_ns; + if (s.peers.heldNow(s.core, s.mail_only)) |held| return held; } return s.test_clock orelse @intCast(std.Io.Clock.awake.now(s.io).nanoseconds); } @@ -3289,3 +3293,46 @@ test "the tty draws a glide at whole rows: once a flick or a spin slows, its ste try std.testing.expectEqual(row, (shown.cursor orelse return error.NoCursor).y); } } +test "a terminal client's view, opened from a window's, wraps a tag at its own width: a terminal's resize says a terminal's row metrics" { + const gpa = std.testing.allocator; + const core = try pardes.Pardes.init(gpa, .{ .tty_only = true, .cols = 140, .rows = 45 }); + defer core.deinit(); + // The session's window: its tag line's glyphs narrower than its body's, + // so a tag row holds more of them than it has cells. + core.update(.{ .resize = .{ .cols = 140, .rows = 45, .cell_pixels = .{ .w = 16, .h = 33 }, .row_metrics = .{ .body_w = 16, .body_h = 33, .tagline_w = 13, .tagline_h = 26 } } }); + const pane = try core.setTestFile("text\n"); + var words: [40][3]u8 = undefined; + var tag: std.ArrayList(u8) = .empty; + defer tag.deinit(gpa); + for (&words, 0..) |*w, i| { + w.* = .{ 'w', '0' + @as(u8, @intCast(i / 10)), '0' + @as(u8, @intCast(i % 10)) }; + try tag.appendSlice(gpa, " "); + try tag.appendSlice(gpa, w); + } + if (pane.tag.own) |own| gpa.free(own); + pane.tag.own = try gpa.dupe(u8, tag.items); + // A terminal's client joins: its view opened from the window's, then + // sized by its terminal, as the client's first inputs do. + const k = core.openView().?; + core.toView(k); + core.update(.{ .resize = terminalSize(100, 30, 0, 0) }); + core.sync(); + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + const s = try core.render(arena.allocator()); + var shown: std.ArrayList(u8) = .empty; + defer shown.deinit(gpa); + for (s.regionList()) |region| { + if (region.kind != .tag) continue; + for (region.rect.y..region.rect.y + region.rect.h) |y| { + for (s.cells[y * s.cols ..][region.rect.x..][0..region.rect.w]) |cell| try shown.appendSlice(gpa, if (cell.len == 0) " " else cell.grapheme()); + try shown.append(gpa, '\n'); + } + } + // Each of its words shows: wrapped at its rows' width, none lost + // between a row cut short and the next. + for (&words) |*w| if (std.mem.indexOf(u8, shown.items, w) == null) { + std.debug.print("{s} is not shown in the tag:\n{s}\n", .{ w, shown.items }); + return error.TestUnexpectedResult; + }; +} |
