summaryrefslogtreecommitdiff
path: root/src/look.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-29 12:31:47 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:16 -0300
commita5be027a0c05c8950bada14fa2f2e713ce7d6986 (patch)
tree8eecd0fd54ef077baf1239f5f00277329974ee95 /src/look.zig
parent549cfa40e99c3d1937b742a0dba043281c687c83 (diff)
downloadpardes-a5be027a0c05c8950bada14fa2f2e713ce7d6986.tar.gz
pardes-a5be027a0c05c8950bada14fa2f2e713ce7d6986.zip
A look at a corrupt image fails with an err rather than open a blank pane
An image stb_image could not read opened as an empty image pane, the look succeeding. The bytes' header is now checked at the look (stbi_info_from_memory), and one that is no image it reads fails the look, look: <path>: not an image pardes can read, making no pane. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/look.zig')
-rw-r--r--src/look.zig11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/look.zig b/src/look.zig
index 6f279769..5cf26240 100644
--- a/src/look.zig
+++ b/src/look.zig
@@ -1572,8 +1572,17 @@ pub fn lookAt(p: *Pardes, id: usize, operand: []const u8) void {
.image => |target| {
if (focusPaneByPath(p, target.path, .{})) return;
const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots);
- _ = panes.Image.create(p, free, target.path, &.{}) catch |err|
+ const made = panes.Image.create(p, free, target.path, &.{}) catch |err|
return p.reportError(id, if (@import("Messages.zig").dialReason(err) != null) target.path else "look", err);
+ // One it cannot read (corrupt, truncated, not what its name says)
+ // is said, a failure, rather than shown as a blank pane.
+ if (!@import("image.zig").readable(made.image.?.raw)) {
+ made.vweight = 0;
+ p.unplaced.set(free);
+ var said: [miss_path_cap + 64]u8 = undefined;
+ var cut: [miss_path_cap + "…".len]u8 = undefined;
+ return p.reportFailure(id, std.fmt.bufPrint(&said, "look: {s}: not an image pardes can read", .{missText(target.path, &cut)}) catch "look: not an image pardes can read");
+ }
exec.placeNew(p, id, id, free, .doc);
},
}