summaryrefslogtreecommitdiff
path: root/src/look.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/look.zig')
-rw-r--r--src/look.zig48
1 files changed, 24 insertions, 24 deletions
diff --git a/src/look.zig b/src/look.zig
index 8f5ed900..aee96513 100644
--- a/src/look.zig
+++ b/src/look.zig
@@ -635,7 +635,7 @@ pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, start: SearchStart,
const loc: []const u8 = if (has_path)
std.Io.Dir.path.basename(pane.file.?.path)
else
- std.fmt.bufPrint(&idbuf, config.pane_addr ++ "{d}", .{pane.serial}) catch unreachable; // `@p` and a u32: 12 bytes
+ std.fmt.bufPrint(&idbuf, config.pane_addr ++ "{d}", .{pane.serial}) catch unreachable; // `@p` and a u32 fit 16
const cl: usize = @intCast(@max(0, pane.body.cur_row));
const cc: usize = @intCast(@max(0, pane.body.cur_col));
for (lines, 0..) |ln, i| {
@@ -1131,7 +1131,7 @@ fn canonicalLookLocation(p: *Pardes, id: usize, text: []const u8) ?[]const u8 {
if (pane.file) |file| return locationText(p, file.path, target.at);
if (pane.addon) |k| if (k.path.len > 0) return locationText(p, k.path, target.at);
var path: [32]u8 = undefined;
- return locationText(p, std.fmt.bufPrint(&path, config.pane_addr ++ "{d}", .{pane.serial}) catch unreachable, target.at); // 12 bytes
+ return locationText(p, std.fmt.bufPrint(&path, config.pane_addr ++ "{d}", .{pane.serial}) catch unreachable, target.at); // `@p` and a u32 fit 32
},
}
}
@@ -1168,8 +1168,8 @@ fn lookOpenFailed(p: *Pardes, id: usize, path: []const u8, err: anyerror) void {
const remote_missing = err == error.Remote and std.mem.indexOf(u8, @import("9p_io.zig").Client.lastSaid(), "not exist") != null;
if (err == error.FileNotFound or err == error.NotFound or remote_missing)
return missed(p, id, "{s}: no such file", .{missText(path, &cut)});
- var said: [miss_path_cap + 16]u8 = undefined;
- p.reportError(id, std.fmt.bufPrint(&said, "look: {s}", .{missText(path, &cut)}) catch unreachable, err); // missText fits miss_path_cap
+ var said: Kind.Buf(miss_path_cap + 16) = .{};
+ p.reportError(id, said.print("look: {s}", .{missText(path, &cut)}), err);
}
fn missedLine(p: *Pardes, id: usize, path: []const u8, line: usize) void {
@@ -1216,16 +1216,16 @@ test "a zero column after a path is found, in every spelling a look takes" {
fn missed(p: *Pardes, id: usize, comptime fmt: []const u8, args: anytype) void {
p.look_missed = true;
- var said: [miss_path_cap + 64]u8 = undefined;
- const why = std.fmt.bufPrint(&said, fmt, args) catch &said; // a longer miss is cut at the buffer's end
- var msg: [said.len + 8]u8 = undefined;
+ var said: Kind.Buf(miss_path_cap + 64) = .{};
+ const why = said.print(fmt, args);
+ var msg: Kind.Buf(miss_path_cap + 72) = .{};
// Shown on the pane; logged once, as the err below, not a msg too.
p.fs.unlogged = true;
- p.setMessage(id, std.fmt.bufPrint(&msg, "Look: {s}", .{why}) catch unreachable); // `why` fits `said`
+ p.setMessage(id, msg.print("Look: {s}", .{why}));
p.fs.unlogged = false;
const serial = if (p.panes[id]) |pane| pane.serial else 0;
- var rec: [said.len + 32]u8 = undefined;
- pardes.ctlfs.events.noteErrCounted(p, std.fmt.bufPrint(&rec, "{d} look: {s}", .{ serial, why }) catch unreachable); // a u32 and `why`
+ var rec: Kind.Buf(miss_path_cap + 96) = .{};
+ pardes.ctlfs.events.noteErrCounted(p, rec.print("{d} look: {s}", .{ serial, why }));
}
/// After a look at `path:N` focused its pane: a line past the end focuses
@@ -1295,9 +1295,9 @@ fn lookUnresolved(p: *Pardes, id: usize, pane: *Pane, trimmed: []const u8, text:
// that is gone, else the file named.
if (filesystem.dotRelative(trimmed)) {
const dir = Pardes.paneDir(pane);
- var said: [4200]u8 = undefined;
+ var said: [4096 + 104]u8 = undefined;
const gone = if (filesystem.localPath(dir)) |local| exec.kindOf(local) != .directory else false;
- if (gone) return p.reportFailure(id, std.fmt.bufPrint(&said, "look: {s}: no such directory", .{dir[0..@min(dir.len, 4096)]}) catch unreachable); // 4123 bytes at most
+ if (gone) return p.reportFailure(id, std.fmt.bufPrint(&said, "look: {s}: no such directory", .{dir[0..@min(dir.len, 4096)]}) catch unreachable); // 4096 + 27 fits 4096 + 104
// A file not there is a miss, as `x` and `/abs/x` are: said and
// logged, the write answered with nothing.
var cut: [miss_path_cap + "…".len]u8 = undefined;
@@ -1411,7 +1411,7 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void {
if ((by_serial or path.len == 0) and pane.isTerminal()) return lookTerminalAddress(p, id, target, expr);
// Named as the pane is, the bare `:addr` (path empty) included.
var serial_name: [32]u8 = undefined;
- const subject = if (pane.addon) |k| k.path else if (path.len > 0) path else std.fmt.bufPrint(&serial_name, config.pane_addr ++ "{d}", .{pane.serial}) catch unreachable; // 12 bytes
+ const subject = if (pane.addon) |k| k.path else if (path.len > 0) path else std.fmt.bufPrint(&serial_name, config.pane_addr ++ "{d}", .{pane.serial}) catch unreachable; // `@p` and a u32 fit 32
var cut: [miss_path_cap + "…".len]u8 = undefined;
return missed(p, id, "{s} is no text to address", .{missText(subject, &cut)});
};
@@ -1427,8 +1427,8 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void {
// A line past the end says so as `file:N` does, whichever way it
// was written: `<file>:N has no line N`.
if (std.fmt.parseInt(usize, expr, 10)) |line| {
- var placed: [miss_path_cap + "…".len + 24]u8 = undefined;
- const place = std.fmt.bufPrint(&placed, "{s}:{d}", .{ name, line }) catch unreachable; // missText and a usize
+ var placed: Kind.Buf(miss_path_cap + "…".len + 24) = .{};
+ const place = placed.print("{s}:{d}", .{ name, line });
if (!opened_here) return missedLine(p, target, place, line);
p.removePane(target, null) catch |err| p.reportError(id, "look", err);
if (p.panes[id] != null) v.active = id;
@@ -1464,7 +1464,7 @@ fn lookKind(p: *Pardes, id: usize, target: usize, expr_raw: []const u8, opened:
return;
}
var serial_name: [32]u8 = undefined;
- const subject = if (slot.path.len > 0) slot.path else std.fmt.bufPrint(&serial_name, config.pane_addr ++ "{d}", .{p.panes[target].?.serial}) catch unreachable; // 12 bytes
+ const subject = if (slot.path.len > 0) slot.path else std.fmt.bufPrint(&serial_name, config.pane_addr ++ "{d}", .{p.panes[target].?.serial}) catch unreachable; // `@p` and a u32 fit 32
var cut: [miss_path_cap + "…".len]u8 = undefined;
const name = missText(subject, &cut);
if (opened) {
@@ -1479,8 +1479,8 @@ fn lookKind(p: *Pardes, id: usize, target: usize, expr_raw: []const u8, opened:
/// A place as `address` takes it: `12`, `12:3`.
fn spotText(at: Spot, buf: *[41]u8) []const u8 {
- if (at.col == 0) return std.fmt.bufPrint(buf, "{d}", .{at.line}) catch unreachable; // two usizes fit 41
- return std.fmt.bufPrint(buf, "{d}:{d}", .{ at.line, at.col }) catch unreachable;
+ if (at.col == 0) return std.fmt.bufPrint(buf, "{d}", .{at.line}) catch unreachable; // a usize fits 41
+ return std.fmt.bufPrint(buf, "{d}:{d}", .{ at.line, at.col }) catch unreachable; // two usizes fit 41
}
fn closeAndMiss(p: *Pardes, id: usize, opened: usize, name: []const u8, why: []const u8) void {
@@ -1571,9 +1571,9 @@ pub fn reopenAt(p: *Pardes, from: usize, path: []const u8, at: Spot) void {
// Said when the file no longer has the line, closed or open: the place
// is its last line now.
if (at.line > n or at.end_line > n) {
- var said: [miss_path_cap + 64]u8 = undefined;
+ var said: Kind.Buf(miss_path_cap + 64) = .{};
var cut: [miss_path_cap + "…".len]u8 = undefined;
- p.setMessage(id, std.fmt.bufPrint(&said, "{s} has {d} lines now: at its last", .{ missText(path, &cut), n }) catch unreachable); // missText and a usize
+ p.setMessage(id, said.print("{s} has {d} lines now: at its last", .{ missText(path, &cut), n }));
}
}
@@ -1755,8 +1755,8 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
// A directory that is not there (the pane's own, gone): said,
// ENOENT, no terminal made in it.
if (filesystem.localPath(dir)) |local| if (exec.kindOf(local) != .directory) {
- var said: [4200]u8 = undefined;
- return p.reportFailure(id, std.fmt.bufPrint(&said, "look: {s}: no such directory", .{dir[0..@min(dir.len, 4096)]}) catch unreachable); // 4123 bytes at most
+ var said: [4096 + 104]u8 = undefined;
+ return p.reportFailure(id, std.fmt.bufPrint(&said, "look: {s}: no such directory", .{dir[0..@min(dir.len, 4096)]}) catch unreachable); // 4096 + 27 fits 4096 + 104
};
// acme's: a pane listing it (Dir.zig).
panes.Dir.look(p, id, dir);
@@ -1829,9 +1829,9 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
if (made.addon.?.refused.len > 0) {
made.vweight = 0;
p.unplaced.set(free);
- var said: [miss_path_cap + 160]u8 = undefined;
+ var said: Kind.Buf(miss_path_cap + 160) = .{};
var cut: [miss_path_cap + "…".len]u8 = undefined;
- return p.reportFailure(id, std.fmt.bufPrint(&said, "look: {s}: {s}", .{ missText(target.path, &cut), made.addon.?.refused.slice() }) catch unreachable); // missText and a Buf(96)
+ return p.reportFailure(id, said.print("look: {s}: {s}", .{ missText(target.path, &cut), made.addon.?.refused.slice() }));
}
exec.placeNew(p, id, id, free, .doc);
if (target.at.line > 0) lookKind(p, id, free, spotText(target.at, &place), true);