summaryrefslogtreecommitdiff
path: root/src/tagline.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/tagline.zig')
-rw-r--r--src/tagline.zig34
1 files changed, 21 insertions, 13 deletions
diff --git a/src/tagline.zig b/src/tagline.zig
index a918689b..8bd8000a 100644
--- a/src/tagline.zig
+++ b/src/tagline.zig
@@ -104,19 +104,27 @@ pub fn revealHeader(p: *Pardes) void {
pub fn tagPrefix(p: *Pardes, pane: *Pane) ![]u8 {
const arena = p.scratch.allocator();
- if (comptime pdf_enabled) if (pane.pdf) |pv| return std.fmt.allocPrint(
- arena,
- "{s} [{d}/{d}]",
- .{ pv.path, pv.page + 1, pv.page_count },
- );
- if (pane.image) |*state| return panes.Image.tagPrefix(arena, state);
- if (pane.file) |f| {
- const name = if (pane.prompt == .name) pane.input.own orelse f.path else f.path;
- if (panes.Output.fileTraits(f.output).saves and f.revision != f.saved_revision)
- return std.fmt.allocPrint(arena, "{s}{s}", .{ name, dirty_marker });
- return arena.dupe(u8, name);
- }
- return arena.dupe(u8, pane.cwdSlice());
+ const prefix = prefix: {
+ if (comptime pdf_enabled) if (pane.pdf) |pv|
+ break :prefix try std.fmt.allocPrint(arena, "{s} [{d}/{d}]", .{ pv.path, pv.page + 1, pv.page_count });
+ if (pane.image) |*state| break :prefix try panes.Image.tagPrefix(arena, state);
+ if (pane.file) |f| {
+ const name = if (pane.prompt == .name) pane.input.own orelse f.path else f.path;
+ if (panes.Output.fileTraits(f.output).saves and f.revision != f.saved_revision)
+ break :prefix try std.fmt.allocPrint(arena, "{s}{s}", .{ name, dirty_marker });
+ break :prefix name;
+ }
+ break :prefix pane.cwdSlice();
+ };
+ // The space between the prefix and the tag's own text is the text's
+ // (every default starts with one), but the prefix is computed, so it
+ // cannot trust the text to keep it: with it deleted, Look and Exec
+ // would see the path and the first word as one. The prefix brings its
+ // own then.
+ const tail = curTail(pane);
+ if (tail.len > 0 and std.mem.indexOfScalar(u8, " \t\n", tail[0]) == null)
+ return std.fmt.allocPrint(arena, "{s} ", .{prefix});
+ return arena.dupe(u8, prefix);
}
/// The tag's own text: what the user made of it, or until then the