summaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig24
1 files changed, 5 insertions, 19 deletions
diff --git a/src/main.zig b/src/main.zig
index 6627bece..1075b596 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -101,8 +101,8 @@ const help_text =
;
/// `pardes -` inside a session: `text` into the directory's one +Pager
-/// (root ctl `pager <dir>`, refilled when it is there), streamed into its
-/// body a bounded chunk at a time as one undo step, and left clean. A text
+/// (root ctl `pager <dir>`, refilled when it is there), written into its
+/// body through one open, as one undo step, and left clean. A text
/// the session would not take is never lost: it goes to stderr, with why,
/// and the exit is 1.
fn pageInto(io: std.Io, gpa: std.mem.Allocator, dial: []const u8, text: []const u8) void {
@@ -129,25 +129,11 @@ fn pageInto(io: std.Io, gpa: std.mem.Allocator, dial: []const u8, text: []const
ninep_io.Client.write(gpa, dial, "/ctl", ctl_line) catch |err| Fail.with(io, text, "no +Pager pane", err);
const answer = ninep_io.Client.read(gpa, dial, "/exec", "/exec") catch |err| Fail.with(io, text, "no +Pager pane", err);
const serial = std.fmt.parseInt(u32, std.mem.trim(u8, answer, " \n"), 10) catch |err| Fail.with(io, text, "no +Pager pane", err);
- var path_buf: [64]u8 = undefined;
- const mark = std.fmt.bufPrint(&path_buf, "/pane/{d}/mark", .{serial}) catch unreachable;
- // One undo step for the whole text, however many writes carry it.
- ninep_io.Client.write(gpa, dial, mark, "0\n") catch |err| Fail.with(io, text, "the +Pager pane went", err);
+ // The whole text through one open of the body (truncated once, then
+ // written at rising offsets): one undo step, and every byte of it.
var body_buf: [64]u8 = undefined;
const body = std.fmt.bufPrint(&body_buf, "/pane/{d}/body", .{serial}) catch unreachable;
- // A chunk ends on a line's end (never inside a character), each its own
- // write with its own deadline, so a large text arrives whole.
- const chunk_max = 8 * 1024 * 1024;
- var at: usize = 0;
- while (at < text.len) {
- var end = @min(text.len, at + chunk_max);
- if (end < text.len) if (std.mem.lastIndexOfScalar(u8, text[at..end], '\n')) |nl| {
- end = at + nl + 1;
- };
- ninep_io.Client.write(gpa, dial, body, text[at..end]) catch |err| Fail.with(io, text[at..], "the +Pager pane would not take it", err);
- at = end;
- }
- ninep_io.Client.write(gpa, dial, mark, "1\n") catch {};
+ ninep_io.Client.write(gpa, dial, body, text) catch |err| Fail.with(io, text, "the +Pager pane would not take it", err);
var ctl_buf: [64]u8 = undefined;
ninep_io.Client.write(gpa, dial, std.fmt.bufPrint(&ctl_buf, "/pane/{d}/ctl", .{serial}) catch unreachable, "clean\n") catch {};
}