summaryrefslogtreecommitdiff
path: root/src/tui/tui.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/tui/tui.zig')
-rw-r--r--src/tui/tui.zig132
1 files changed, 121 insertions, 11 deletions
diff --git a/src/tui/tui.zig b/src/tui/tui.zig
index fae55141..b2a198c7 100644
--- a/src/tui/tui.zig
+++ b/src/tui/tui.zig
@@ -12,7 +12,6 @@ const message = pardes.Messages.Message;
const file_watch = @import("../file_watch.zig");
const selection_pipe = @import("../selection_pipe.zig");
const ninep_io = @import("../9p_io.zig");
-const panel_compositor = @import("panel_compositor.zig");
const daemon = @import("../daemon.zig");
const host_io = @import("../host_io.zig");
const upgrade = @import("../upgrade.zig");
@@ -1408,7 +1407,6 @@ const Screen = struct {
caps_pending: bool = true,
/// Its size as last taken (`Shell.resized`).
size: ?vaxis.Winsize = null,
- tracks: []const pardes.animation.Track = &.{},
/// The view's glide, the GUI's motion drawn at whole rows (anim 12).
glide: pardes.glide.Glide = .{},
@@ -2601,7 +2599,6 @@ const Shell = struct {
const s = of(ctx);
const sc = s.term() orelse return;
const vx = &sc.vx;
- sc.tracks = canonical.panelTracks();
// The last frame is not answered yet: this one stays owed, and the
// answer's wake draws the state as it is then.
if (sc.feed.ack.holds(@intCast(std.Io.Clock.awake.now(s.io).nanoseconds), s.io)) {
@@ -2609,10 +2606,6 @@ const Shell = struct {
return;
}
_ = s.frame.reset(.retain_capacity);
- // Each pass below draws on the frame's one copy of the canonical
- // surface, made by the first that changes anything.
- var frame: panel_compositor.Frame = .{ .arena = s.frame.allocator(), .canonical = canonical };
- panel_compositor.compose(&frame, sc.tracks, s.core.theme().bg) catch return;
const tz_cells = tracy.zone(@src(), "surface->vaxis");
const win = vx.window();
// Each of the shell's own motions below asks for frames while it runs.
@@ -2620,13 +2613,11 @@ const Shell = struct {
if (sc.glide.moving()) sc.glide.advance(s.core.now_ns, sc.glide.motion);
s.core.shell_continuous = sc.glide.moving();
s.core.frames.scroll = @round(sc.glide.follow.offset);
- panel_compositor.glideRows(&frame, &sc.glide) catch {};
- const shown = frame.shown();
+ const shown = glideRows(s.frame.allocator(), canonical, &sc.glide) catch canonical;
paintCells(win, shown.cells, shown.cols, shown.rows);
if (s.remote) |c| if (c.link.notice_len > 0) noticeLine(win, c.link.notice(), shown.cols, shown.rows);
tz_cells.end();
for (canonical.images.items) |place| {
- if (panel_compositor.hidesAttachment(canonical.panelTracks(), place.serial)) continue;
if (comptime pardes.pdf_enabled) {
if (!kittyImageRepresentable(place)) continue;
}
@@ -2726,7 +2717,7 @@ const Shell = struct {
fn postPresent(ctx: ?*anyopaque) void {
const s = of(ctx);
- if (s.term()) |sc| s.core.acknowledgePanelPresentation(sc.tracks);
+ if (s.term() != null) s.core.presented();
tracy.frameMark();
}
@@ -3352,6 +3343,45 @@ fn noticeLine(win: vaxis.Window, text: []const u8, cols: u16, rows: u16) void {
/// (pardes's patch to Vaxis.zig in build.zig), since a blank's ink shows
/// nowhere. Deciding that here cost every cell of every frame a look at the
/// frame before; vaxis already makes that comparison.
+/// The tty's picture of the glide (glide.zig, anim 12): the body's rows
+/// moved by the offset rounded to whole rows (the position rounded, never
+/// the step, so a slowing glide's steps come further apart), the rows that
+/// left in the gap it opens, and a caret whose line rode the scroll carried
+/// with it; `canonical` itself while the picture is where the core is, else
+/// a copy of it in `arena`. The rows are walked from the side they move
+/// toward, so each is read before a move writes over it.
+fn glideRows(arena: std.mem.Allocator, canonical: *const pardes.Surface, glide: *const pardes.glide.Glide) !*const pardes.Surface {
+ const k: i32 = @intFromFloat(@round(glide.follow.offset));
+ const w = glide.bw();
+ const h = glide.body_h;
+ const x0 = glide.rect.x + pardes.config.GUTTER;
+ const y0 = glide.body_y;
+ if (k == 0 or w == 0 or h == 0 or x0 + w > canonical.cols or y0 + h > canonical.rows) return canonical;
+ const out = try arena.create(pardes.Surface);
+ out.* = canonical.*;
+ out.cells = try arena.dupe(pardes.Cell, canonical.cells);
+ const cols: usize = out.cols;
+ for (0..h) |i| {
+ const r = if (k > 0) i else h - 1 - i;
+ const from = @as(i32, @intCast(r)) + k;
+ const to = out.cells[(y0 + r) * cols + x0 ..][0..w];
+ const kept: ?[]const pardes.Cell = if (from >= 0 and from < h)
+ out.cells[(y0 + @as(usize, @intCast(from))) * cols + x0 ..][0..w]
+ else if (from < 0 and -from - 1 < glide.nabove)
+ glide.above[@as(usize, @intCast(-from - 1)) * w ..][0..w]
+ else if (from >= h and from - h < glide.nbelow)
+ glide.below[@as(usize, @intCast(from - h)) * w ..][0..w]
+ else
+ null;
+ if (kept) |cells| @memcpy(to, cells) else @memset(to, .{});
+ }
+ if (out.cursor) |*c| if (glide.caret_rides and c.x >= x0 and c.x < x0 + w and c.y >= y0 and c.y < y0 + h) {
+ const y = @as(i32, c.y) - k;
+ if (y >= y0 and y < y0 + h) c.y = @intCast(y) else out.cursor = null;
+ };
+ return out;
+}
+
fn paintCells(win: vaxis.Window, cells: []const pardes.Cell, cols: u16, rows: u16) void {
win.clear();
var y: u16 = 0;
@@ -3399,3 +3429,83 @@ test "a fade sends the text it dims, not the blanks beside it" {
try std.testing.expect(std.mem.indexOf(u8, sent[1], "90:90:90") != null);
try std.testing.expect(std.mem.indexOfScalar(u8, sent[1], 'a') != null);
}
+
+test "the tty draws a glide at whole rows: once a flick or a spin slows, its steps a tick never grow and its one-row steps come further apart, to where the core is" {
+ const gpa = std.testing.allocator;
+ const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 30, .tty_only = true });
+ defer core.deinit();
+ var text: std.ArrayList(u8) = .empty;
+ defer text.deinit(gpa);
+ for (0..3000) |i| try text.print(gpa, "{d:0>5} line\n", .{i});
+ _ = try core.setTestFile(text.items);
+ core.settings.motion = .smooth;
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ var glide: pardes.glide.Glide = .{};
+ defer glide.deinit(gpa);
+ var now: u64 = std.time.ns_per_s;
+ // One tick of the tty: its loop step, the frame, the picture.
+ const tick = struct {
+ fn f(c: *pardes.Pardes, g: *pardes.glide.Glide, a: *std.heap.ArenaAllocator, t: u64) !i32 {
+ c.advance(t);
+ g.step(c, std.testing.allocator, null, null);
+ _ = a.reset(.retain_capacity);
+ const s = try c.render(a.allocator());
+ if (g.pending) g.measure(std.testing.allocator, s);
+ if (g.moving()) g.advance(t, g.motion);
+ _ = try glideRows(a.allocator(), s, g);
+ return @intFromFloat(@round(g.follow.offset));
+ }
+ }.f;
+ _ = try tick(core, &glide, &arena, now);
+ for ([_]usize{ 4, 24 }) |notches| {
+ for (0..notches) |i| {
+ core.update(.{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = 20, .row = 10 } });
+ if (i % 2 == 1) {
+ now += pardes.animation.frame_ns;
+ _ = try tick(core, &glide, &arena, now);
+ }
+ }
+ var drawn = try tick(core, &glide, &arena, now + pardes.animation.frame_ns);
+ now += pardes.animation.frame_ns;
+ var last_step: i32 = std.math.maxInt(i32);
+ var last_gap: usize = 0;
+ var since: usize = 0;
+ var ticks: usize = 0;
+ while (glide.moving()) : (ticks += 1) {
+ try std.testing.expect(ticks < 200);
+ now += pardes.animation.frame_ns;
+ const k = try tick(core, &glide, &arena, now);
+ const step = k - drawn;
+ drawn = k;
+ since += 1;
+ if (step == 0) continue;
+ // Toward the core, never past it, each step no longer than the last.
+ try std.testing.expect(step > 0 and k <= 0);
+ try std.testing.expect(step <= last_step);
+ if (step == 1 and last_step == 1) try std.testing.expect(since >= last_gap);
+ if (step == 1) last_gap = since;
+ last_step = step;
+ since = 0;
+ }
+ try std.testing.expectEqual(@as(i32, 0), drawn);
+ }
+ // j held on the bottom row: the text glides a row a key under a caret
+ // that stays on its cell (it does not ride: its row is kept).
+ const keys = struct {
+ fn j(c: *pardes.Pardes) void {
+ c.update(.{ .key = .{ .cp = 'j', .text = "j" } });
+ }
+ };
+ for (0..40) |_| keys.j(core);
+ now += std.time.ns_per_s;
+ _ = try tick(core, &glide, &arena, now);
+ const row = (core.surface.cursor orelse return error.NoCursor).y;
+ for (0..20) |i| {
+ if (i % 2 == 0) keys.j(core);
+ now += pardes.animation.frame_ns;
+ _ = try tick(core, &glide, &arena, now);
+ const shown = try glideRows(arena.allocator(), &core.surface, &glide);
+ try std.testing.expectEqual(row, (shown.cursor orelse return error.NoCursor).y);
+ }
+}