diff options
Diffstat (limited to 'src/ninep')
| -rw-r--r-- | src/ninep/ctl.zig | 54 | ||||
| -rw-r--r-- | src/ninep/pane.zig | 21 |
2 files changed, 12 insertions, 63 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 42d9f3bd..53128c5e 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -442,10 +442,9 @@ pub fn paneText(p: *Pardes, pane: *Pane, buf: []u8) []const u8 { var idbuf: [48]u8 = undefined; const id = exec_line.replId(&idbuf, pane); if (id.len > 0) w.print("{s} ", .{id}) catch {}; - // Then what its tag does not say: Collapse, and a PDF's PdfFit and - // PdfTint, in the words they take. + // Then what its tag does not say: Collapse, and a kind's own fields (a + // PDF's PdfFit and PdfTint, in the words they take). if (pane.collapsed) w.writeAll("collapsed ") catch {}; - if (comptime pardes.pdf_enabled) if (pane.pdf) |pv| w.print("fit:{s} tint:{s} ", .{ @tagName(pv.fit), @tagName(pv.tint) }) catch {}; if (pane.addon != null) { var fields: [128]u8 = undefined; const kind_fields = pardes.Kind.ctlRead(pane, &fields); @@ -1544,7 +1543,7 @@ test "an address looked at in an image pane names the image, never an empty subj try testing.expect(th.logHas(p, "look: /tmp/pardes-pic.ppm is no text to address")); } -test "Save and Save path on an image pane are refused with why, never a silent success" { +test "Save and Save path on a kind's pane (a picture) are refused with why, never a silent success" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); const id = p.freeSlot().?; @@ -1552,7 +1551,7 @@ test "Save and Save path on an image pane are refused with why, never a silent s for ([_][]const u8{ "Save\n", "Save /tmp/pardes-copy.ppm\n" }) |line| { const r = wr(p, Node.of(doc.serial, .ctl), line); try testing.expectEqual(Status.err, r.reply.status); - try testing.expectEqualStrings("Save: an image pane has no text to save", r.reply.ename); + try testing.expectEqualStrings("Save: a test pane has no text to save", r.reply.ename); } } @@ -1574,9 +1573,6 @@ test "a builtin for one kind of pane is refused on another, and still acts on it try testing.expectEqual(Status.err, r.reply.status); try testing.expectEqualStrings(case[1], r.reply.ename); } - if (pardes.pdf_enabled) for ([_][]const u8{ "PdfFit\n", "PdfTint\n", "PdfSections\n" }) |line| { - try testing.expectEqual(Status.err, wr(p, Node.of(serial, .ctl), line).reply.status); - }; const id = p.freeSlot().?; // A picture shown: the core's art words follow the kind's prefix. const doc = try pardes.Kind.open(p, id, pardes.Kind.test_kind.of(p), "/tmp/pardes-pic.ppm", "P6\n1 1\n255\n\x01\x02\x03"); @@ -2160,48 +2156,6 @@ test "a language server question that finds nothing, cannot be answered, or is a try testing.expectEqual(E.INVAL, wr(p, Node.of(img.serial, .body), "text\n").errno()); } -test "a truncated PDF fails its look with its path and why" { - if (comptime !pardes.pdf_enabled) return; - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - var tmp = testing.tmpDir(.{}); - defer tmp.cleanup(); - const bytes = try @import("mupdf").testFixture(testing.allocator, "links.pdf"); - defer testing.allocator.free(bytes); - try tmp.dir.writeFile(testing.io, .{ .sub_path = "cut.pdf", .data = bytes[0..40] }); - var dir_buf: [4096]u8 = undefined; - const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; - var line: [4200]u8 = undefined; - const r = wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/cut.pdf\n", .{dir})); - try testing.expectEqual(Status.err, r.reply.status); - try testing.expect(std.mem.indexOf(u8, r.reply.ename, "cut.pdf: not a PDF pardes can read: ") != null); -} - -test "a PDF's body reads its page's text layer, and takes no write" { - if (comptime !pardes.pdf_enabled) return; - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - var tmp = testing.tmpDir(.{}); - defer tmp.cleanup(); - const bytes = try @import("mupdf").testFixture(testing.allocator, "links.pdf"); - defer testing.allocator.free(bytes); - try tmp.dir.writeFile(testing.io, .{ .sub_path = "doc.pdf", .data = bytes }); - var dir_buf: [4096]u8 = undefined; - const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; - var line: [4200]u8 = undefined; - _ = wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/doc.pdf\n", .{dir})); - p.sync(); - const doc = p.panes[p.view().active].?; - try testing.expect(doc.hasPdf()); - const body = Node.of(doc.serial, .body); - try testing.expect(std.mem.indexOf(u8, rd(p, body, 0, 4096).bytes, "target.txt") != null); - // Read from an offset, as a mount's chunked reads ask: the text from there. - const whole = try testing.allocator.dupe(u8, rd(p, body, 0, 4096).bytes); - defer testing.allocator.free(whole); - try testing.expectEqualStrings(whole[3..], rd(p, body, 3, 4096).bytes); - try testing.expectEqual(E.INVAL, wr(p, body, "more\n").errno()); -} - test "workspace symbols, Symbols and Diagnostics share their directory's one +Search" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig index 92d28b99..704f1ac8 100644 --- a/src/ninep/pane.zig +++ b/src/ninep/pane.zig @@ -145,7 +145,6 @@ pub fn dirtyOf(pane: *const Pane) bool { /// The pane's name: its file, its document, or a terminal's directory. pub fn nameOf(p: *Pardes, pane: *const Pane) []const u8 { if (pane.file) |*f| return f.path; - if (pane.pdfPath()) |path| return path; if (pane.addon) |k| if (k.path.len > 0) return k.path; const cwd = pane.cwdSlice(); // A shell given no directory was started in the session's, and is @@ -155,7 +154,6 @@ pub fn nameOf(p: *Pardes, pane: *const Pane) []const u8 { pub fn kindOf(pane: *const Pane) []const u8 { if (pane.file != null) return "text"; - if (pane.pdfPath() != null) return "pdf"; if (pane.addon) |k| return k.nameOf(); // A command's pane is no shell to type into: a script choosing a // terminal by kind must not pick one. @@ -350,7 +348,7 @@ pub fn fileSize(p: *Pardes, id: usize, f: PaneFile) u64 { const pf = &pane.fs; return switch (f) { // A terminal's body reads its screen and history, as text. - .body => if (pane.file == null and pane.isTerminal()) panes.terminal.screenTextLen(pane) else if (pdfText(p, pane)) |t| t.len else bodyOf(pane).len, + .body => if (pane.file == null and pane.isTerminal()) panes.terminal.screenTextLen(pane) else if (kindText(p, pane)) |t| t.len else bodyOf(pane).len, // What addr selects, generated by each read: no length, as acme's // data and xdata have none. .data, .xdata => 0, @@ -452,14 +450,11 @@ fn readFlag(p: *Pardes, req: Req, on: bool) Reply { return tree.stagedReply(p, req); } -/// The text layer of the page a PDF pane shows (MuPDF's extraction, kept -/// with the page), null for any other pane. -/// A document's text, read-only: a PDF's text layer, a kind's `body`. -fn pdfText(p: *Pardes, pane: *Pane) ?[]const u8 { - if (pane.addon != null) return pardes.Kind.body(pane, p.scratch.allocator()) catch null; - if (comptime !pardes.pdf_enabled) return null; - const pv = pane.pdf orelse return null; - return pv.ensureText(p.pdf_gpa); +/// A kind's pane's text, read-only: its `body` (a PDF's: the text layer +/// of the page shown); null for any other pane. +fn kindText(p: *Pardes, pane: *Pane) ?[]const u8 { + if (pane.addon == null) return null; + return pardes.Kind.body(pane, p.scratch.allocator()) catch null; } fn readBody(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply { @@ -474,8 +469,8 @@ fn readBody(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply { .len = clip(n), } } }; } - // A PDF's body is its text layer, the page shown's: read-only. - if (pdfText(p, pane)) |text| return tree.window(p, req, text); + // A kind's body is its text (a PDF's, the page shown's): read-only. + if (kindText(p, pane)) |text| return tree.window(p, req, text); if (req.handle != 0 and pane.isTerminal()) return screen.readSnapshot(p, req, pane); const text = panes.terminal.screenTextAlloc(pane, p.gpa) catch return Reply.fail(req.tag, E.NOMEM); |
