diff options
Diffstat (limited to 'dev/tui/tui.zig')
| -rw-r--r-- | dev/tui/tui.zig | 74 |
1 files changed, 64 insertions, 10 deletions
diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index f0011273..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); } @@ -1572,11 +1576,9 @@ const Shell = struct { var motion: ?Msg = null; var ev = first; while (true) { - if (s.split(ev)) break; + if (s.split(ev, motion)) break; if (ev == .mouse and (ev.mouse.type == .motion or ev.mouse.type == .drag)) { - if (motion) |m| if (m.mouse.button != ev.mouse.button or m.mouse.type != ev.mouse.type or - @as(u3, @bitCast(m.mouse.mods)) != @as(u3, @bitCast(ev.mouse.mods))) - { + if (motion) |m| if (!movesOn(m, ev)) { _ = s.apply(m); }; motion = ev; @@ -1605,14 +1607,16 @@ const Shell = struct { /// a person's input, and none after a pty's output: a step reads the /// terminals as the clients' deltas bring them, sent after each unit /// (docs/next-daemon.md, part B terminal notes). One that must wait is - /// held for the next. Whether `ev` is. - fn split(s: *Shell, ev: Msg) bool { + /// held for the next. Whether `ev` is; a motion that goes on this + /// wait's run of them (`streak`) is that one input, its last. + fn split(s: *Shell, ev: Msg, streak: ?Msg) bool { if (!s.peers.recording) return false; switch (ev) { .key_press => if (s.in_paste) return false, .mouse, .paste, .paste_end, .reply_dropped, .winsize, .focus_in, .focus_out => {}, else => return false, } + if (streak) |m| if (movesOn(m, ev)) return false; if (s.took_output or s.took_input) { s.held = ev; s.input_seen = true; @@ -1622,6 +1626,13 @@ const Shell = struct { return false; } + /// Whether `ev` goes on the motion `streak`: one move to its last cell + /// (the same button, kind and modifiers). + fn movesOn(streak: Msg, ev: Msg) bool { + return ev == .mouse and ev.mouse.type == streak.mouse.type and ev.mouse.button == streak.mouse.button and + @as(u3, @bitCast(ev.mouse.mods)) == @as(u3, @bitCast(streak.mouse.mods)); + } + fn apply(s: *Shell, event: Msg) bool { const core = s.core; const tz_event = tracy.zone(@src(), "event"); @@ -3282,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; + }; +} |
