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.zig112
1 files changed, 6 insertions, 106 deletions
diff --git a/src/tui/tui.zig b/src/tui/tui.zig
index fd47cb67..78789f69 100644
--- a/src/tui/tui.zig
+++ b/src/tui/tui.zig
@@ -984,7 +984,6 @@ test "Kitty PDF fragments never declare pixels beyond their clipped bottom" {
}
test "on a terminal with no kitty graphics a program's 64x64 image over 8x4 cells is glyph art in every cell, and pixels stay put where it has them" {
- if (comptime !pardes.pdf_enabled) return;
const gpa = std.testing.allocator;
const core = try pardes.Pardes.init(gpa, .{ .cols = 120, .rows = 40, .shells = 1 });
defer core.deinit();
@@ -1023,66 +1022,6 @@ test "on a terminal with no kitty graphics a program's 64x64 image over 8x4 cell
try std.testing.expectEqual(@as(usize, 32), painted);
}
-test "host watch closes initial race and reloads rename-over PDF while idle" {
- if (comptime !file_watch.supported or !pardes.pdf_enabled) return;
- const io = std.testing.io;
- const gpa = std.testing.allocator;
- var tmp = std.testing.tmpDir(.{});
- defer tmp.cleanup();
- const original = try pardes.pdf.testFixture(gpa, "outline.pdf");
- defer gpa.free(original);
- const replacement = try pardes.pdf.testFixture(gpa, "offset-rotated.pdf");
- defer gpa.free(replacement);
- try tmp.dir.writeFile(io, .{ .sub_path = "live.pdf", .data = original });
- try tmp.dir.writeFile(io, .{ .sub_path = "initial.pdf", .data = replacement });
- try tmp.dir.writeFile(io, .{ .sub_path = "live-replacement.pdf", .data = original });
- var path_buf: [256]u8 = undefined;
- const path = try std.fmt.bufPrint(&path_buf, ".zig-cache/tmp/{s}/live.pdf", .{tmp.sub_path});
-
- const fd = file_watch.init(true);
- if (fd < 0) return error.WatchInitFailed;
- defer _ = libc.close(fd);
- var watches: file_watch.Table = @splat(null);
- defer file_watch.unwatchAll(fd, &watches);
-
- const core = try pardes.Pardes.init(gpa, .{ .file = path, .cols = 80, .rows = 28 });
- defer core.deinit();
- try std.testing.expectEqual(@as(usize, 3), core.panes[0].?.pdf.?.page_count);
-
- try tmp.dir.rename("initial.pdf", tmp.dir, "live.pdf", io);
- var armed = false;
- while (core.nextEffect()) |effect| switch (effect) {
- .watch => |watch| if (watch.pane == 0 and watch.on) {
- armed = true;
- try std.testing.expect(!file_watch.applyEffect(core, io, fd, &watches, 0, true, watch.mode));
- },
- else => {},
- };
- try std.testing.expect(armed and watches[0] != null);
- try std.testing.expectEqual(@as(usize, 1), core.panes[0].?.pdf.?.page_count);
-
- try tmp.dir.rename("live-replacement.pdf", tmp.dir, "live.pdf", io);
- try std.testing.expect(file_watch.drain(fd));
-
- try std.testing.expect(!file_watch.reloadChanged(core, io, gpa, &watches));
- const pane = core.panes[0].?;
- try std.testing.expectEqual(@as(usize, 3), pane.pdf.?.page_count);
- const disk_identity = try file_watch.identify(io, path);
- switch (watches[0].?.generation) {
- .pdf => |accepted| try std.testing.expect(accepted != null and accepted.?.eql(disk_identity)),
- .text => return error.PdfWatchStoredTextGeneration,
- }
- try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "reloaded") != null);
-
- core.view().frontend.native_images = true;
- var frame = std.heap.ArenaAllocator.init(gpa);
- defer frame.deinit();
- const surface = try core.render(frame.allocator());
- try std.testing.expect(surface.placements.items.len > 0);
- const shown = surface.placements.items[0];
- try std.testing.expectEqual(pardes.Placement.keyOf(pane.serial, 0, pardes.panes.Pdf.rasterForPage(pane.pdf.?, 0).?.revision), shown.key);
-}
-
fn kittyImageRepresentable(place: pardes.Placement) bool {
return place.raster.w > 0 and place.raster.h > 0 and
place.raster.w <= std.math.maxInt(u16) and place.raster.h <= std.math.maxInt(u16);
@@ -1096,26 +1035,6 @@ fn surfaceHasKittyKey(surface: *const pardes.Surface, key: u64) bool {
return false;
}
-const PdfWheelTarget = struct { pane: usize, page: usize };
-
-fn nativePdfWheelTarget(core: *const pardes.Pardes, mouse: vaxis.Mouse) ?PdfWheelTarget {
- if (comptime !pardes.pdf_enabled) return null;
- if (!core.view().frontend.native_images or mouse.type != .press or
- (mouse.button != .wheel_up and mouse.button != .wheel_down) or
- mouse.col < 0 or mouse.row < 0) return null;
- const col: u16 = @intCast(mouse.col);
- const row: u16 = @intCast(mouse.row);
- for (core.panes, 0..) |slot, id| {
- const pane = slot orelse continue;
- const rect = core.view().rects[id];
- if (col < rect.x or col >= rect.x + rect.w or
- row < rect.y or row >= rect.y + rect.h) continue;
- const page = pane.pdfPage() orelse return null;
- return .{ .pane = id, .page = page };
- }
- return null;
-}
-
/// Where a session's terminal comes from: /dev/tty, as a plain `pardes`
/// opens it; one open already (a session forked off its stub,
/// daemon.forkSession); or none, until one is attached (`--detach`).
@@ -1221,21 +1140,15 @@ pub fn remote(init: std.process.Init, opts: pardes.Options, path: []const u8, se
const have: ?*replica.Have = if (far) &have_store else null;
const allocs = pardes.memory.init(gpa);
defer pardes.memory.deinit();
- if (comptime pardes.pdf_enabled) {
- pardes.TerminalImages.start(io, allocs.image);
- pardes.pdf.start(allocs.pdf);
- }
+ pardes.TerminalImages.start(io, allocs.image);
+ pardes.Kind.heap = allocs.addon;
pardes.syntax.start(allocs.tree_sitter);
defer {
- if (comptime pardes.pdf_enabled) {
- pardes.TerminalImages.stop();
- pardes.pdf.stop();
- }
+ pardes.TerminalImages.stop();
pardes.syntax.stop();
}
var o = opts;
o.image_allocator = allocs.image;
- o.pdf_allocator = allocs.pdf;
var joined: replica.Joined = undefined;
var r = replica.join(gpa, &joined, path, session, o, have, &why, null) orelse Said.no(io, "{s}", .{std.mem.sliceTo(&why, 0)});
@@ -1507,7 +1420,6 @@ fn localSession(
defer pardes.memory.deinit();
var options = opts;
options.image_allocator = allocs.image;
- options.pdf_allocator = allocs.pdf;
options.tree_sitter_allocator = allocs.tree_sitter;
options.frame_allocator = allocs.frame;
@@ -1668,9 +1580,7 @@ fn localSession(
core.deinit();
core = nc;
sh.core = nc;
- if (comptime pardes.pdf_enabled) if (live.on) {
- core.update(.{ .resize = terminalSize(live.vx.screen.width, live.vx.screen.height, live.vx.screen.width_pix, live.vx.screen.height_pix) });
- };
+ if (live.on) core.update(.{ .resize = terminalSize(live.vx.screen.width, live.vx.screen.height, live.vx.screen.width_pix, live.vx.screen.height_pix) });
}
}
if (fs) |f| {
@@ -2316,17 +2226,7 @@ const Shell = struct {
const room = max_paste_bytes -| s.paste_buf.written().len;
s.paste_buf.writer.writeAll(bytes[0..@min(bytes.len, room)]) catch {};
} else s.feed(vaxis_input.keyEvent(key)),
- .mouse => |m| {
- const pdf_before = nativePdfWheelTarget(core, m);
- if (mouseEvent(m)) |ev| s.feed(ev);
- if (pdf_before) |before| {
- if (core.panes[before.pane]) |pane| {
- if (pane.pdfPage()) |page| {
- if (page != before.page) return true;
- }
- }
- }
- },
+ .mouse => |m| if (mouseEvent(m)) |ev| s.feed(ev),
.paste => |bytes| {
s.feed(.{ .paste = bytes });
s.gpa.free(@constCast(bytes));
@@ -2385,7 +2285,7 @@ const Shell = struct {
sc.size = ws;
sc.vx.resize(s.gpa, sc.tty.writer(), ws) catch {};
}
- s.feed(.{ .resize = if (comptime pardes.pdf_enabled) terminalSize(ws.cols, ws.rows, ws.x_pixel, ws.y_pixel) else .{ .cols = ws.cols, .rows = ws.rows } });
+ s.feed(.{ .resize = terminalSize(ws.cols, ws.rows, ws.x_pixel, ws.y_pixel) });
}
/// A SIGWINCH: the terminal, if it changed size, resized in its view