From 9b60771ffcd254772b716fafe488b09d9c2d3e0c Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 6 Nov 2026 12:15:23 -0300 Subject: idioms #16, edits fail by name: the edit operations return edit.Error (memory, or a terminal's rows not read) and try where they caught and returned, so the key, chord or paste that ran one says the failure (`edit: out of memory`, reportError) where it did nothing; look, Core, File and terminal say theirs the same way, and the prints whose buffer provably fits catch unreachable with why Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/terminal.zig | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/terminal.zig') diff --git a/src/terminal.zig b/src/terminal.zig index 3d2e4943..097005bc 100644 --- a/src/terminal.zig +++ b/src/terminal.zig @@ -204,8 +204,8 @@ pub const State = struct { var buf: [4096]u8 = undefined; var text: std.Io.Writer.Hashing(pardes.walk.Hasher) = .initHasher(h.*, &buf); if (screen.pages.getBottomRight(.active)) |br| - screen.dumpString(&text.writer, .{ .tl = screen.pages.getTopLeft(.active), .br = br, .unwrap = false }) catch {}; - text.writer.flush() catch {}; + screen.dumpString(&text.writer, .{ .tl = screen.pages.getTopLeft(.active), .br = br, .unwrap = false }) catch unreachable; // a hashing writer never fails + text.writer.flush() catch unreachable; h.* = text.hasher; } @@ -777,7 +777,7 @@ pub fn mouseBytes(pane: *Pane, buf: *[64]u8, action: MouseAction, button: ?Mouse } else null, .mods = .{ .shift = mods.shift, .alt = mods.alt, .ctrl = mods.ctrl }, .pos = .{ .x = @as(f32, @floatFromInt(col)) + 0.5, .y = @as(f32, @floatFromInt(row)) + 0.5 }, - }, opts) catch return &.{}; + }, opts) catch unreachable; // a mouse report is at most 31 bytes return writer.buffered(); } @@ -853,7 +853,7 @@ const TeeWriter = struct { pub fn screenTextLen(pane: *Pane) usize { var buf: [256]u8 = undefined; var counting: std.Io.Writer.Discarding = .init(&buf); - writeScreenText(pane, &counting.writer) catch return 0; + writeScreenText(pane, &counting.writer) catch unreachable; // a discarding writer never fails return @intCast(counting.fullCount()); } @@ -1895,7 +1895,7 @@ pub fn flatSurface(p: *Pardes, pane: *Pane, lines: []const []const u8) ![]const /// Materialize or extend the terminal edit overlay with one exact allocation. /// Row slices are scratch-owned/borrowed; only the joined text is installed. -pub fn editText(p: *Pardes, pane: *Pane, lo: i32, hi: i32, col: i32) ?EditText { +pub fn editText(p: *Pardes, pane: *Pane, lo: i32, hi: i32, col: i32) error{ OutOfMemory, WriteFailed, UnknownPoint }!?EditText { const want_lo = @max(0, @min(lo, hi)); const want_hi = @max(want_lo, @max(lo, hi)); const fresh = pane.ovl == null; @@ -1909,12 +1909,12 @@ pub fn editText(p: *Pardes, pane: *Pane, lo: i32, hi: i32, col: i32) ?EditText { var text = old.text; var owned = false; if (extending) { - const rows = shellRows(p, pane) catch return null; + const rows = try shellRows(p, pane); row0 = old.row - @max(0, up); covered = old.rows + @max(0, up) + @max(0, down); const up_len: usize = @intCast(@max(0, up)); const down_len: usize = @intCast(@max(0, down)); - const parts = p.scratch.allocator().alloc([]const u8, up_len + 1 + down_len) catch return null; + const parts = try p.scratch.allocator().alloc([]const u8, up_len + 1 + down_len); for (parts[0..up_len], 0..) |*part, i| { const src = @as(usize, @intCast(row0)) + i; part.* = if (src < rows.len) rows[src] else ""; @@ -1928,7 +1928,7 @@ pub fn editText(p: *Pardes, pane: *Pane, lo: i32, hi: i32, col: i32) ?EditText { const src = @as(usize, @intCast(old.row + old.rows)) + i; part.* = if (src < rows.len) rows[src] else ""; } - text = std.mem.join(p.gpa, "\n", parts) catch return null; + text = try std.mem.join(p.gpa, "\n", parts); owned = true; } -- cgit v1.3