summaryrefslogtreecommitdiff
path: root/src/terminal.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 12:15:23 -0300
committerGabriel Schneider <[email protected]>2026-11-06 14:56:36 -0300
commit9b60771ffcd254772b716fafe488b09d9c2d3e0c (patch)
tree917b658065d2aa1b5b59c797249d1fa5d32c0983 /src/terminal.zig
parent961bea06443e25a92e02be58136065c2a1ea84c1 (diff)
downloadpardes-9b60771ffcd254772b716fafe488b09d9c2d3e0c.tar.gz
pardes-9b60771ffcd254772b716fafe488b09d9c2d3e0c.zip
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 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/terminal.zig')
-rw-r--r--src/terminal.zig16
1 files changed, 8 insertions, 8 deletions
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;
}