summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/edit.zig2
-rw-r--r--src/image.zig6
-rw-r--r--src/ninep/ctl.zig9
-rw-r--r--src/ninep/pane.zig2
-rw-r--r--src/pardes.zig6
-rw-r--r--src/tagline.zig18
-rw-r--r--src/terminal.zig4
7 files changed, 31 insertions, 16 deletions
diff --git a/src/edit.zig b/src/edit.zig
index 1305d66f..3e3ba341 100644
--- a/src/edit.zig
+++ b/src/edit.zig
@@ -500,7 +500,7 @@ pub fn setEditTextEnd(p: *Pardes, t: *Text, new: []u8, known_end: ?modal.Cursor)
// caller reads the new text back, as a body's is kept.
defer retireEditText(p, new);
const pane = t.pane() orelse return;
- const prefix = tagline.pathPrefix(p.scratch.allocator(), pane) catch return;
+ const prefix = tagline.pathPrefix(p, p.scratch.allocator(), pane) catch return;
if (!std.mem.startsWith(u8, new, prefix)) {
t.refused = true;
return;
diff --git a/src/image.zig b/src/image.zig
index 4a8bcdf4..72520ad6 100644
--- a/src/image.zig
+++ b/src/image.zig
@@ -919,13 +919,15 @@ pub fn toggleAscii(state: *State) void {
/// Image renderer choices are pane-local, not global Config values. Keep them
/// queryable where they apply: the live tag beside the image's path.
-pub fn tagPrefix(arena: std.mem.Allocator, state: *const State) ![]u8 {
+/// `glyphs`: whether the picture is drawn as glyph art, which a terminal
+/// with no graphics does whatever `glyph_art` says.
+pub fn tagPrefix(arena: std.mem.Allocator, state: *const State, glyphs: bool) ![]u8 {
return std.fmt.allocPrint(
arena,
"{s} petscii:{s} palette:{s} ascii:{s} {s}",
.{
config.tag_image,
- if (state.glyph_art) "on" else "off",
+ if (glyphs) "on" else "off",
@tagName(state.pmode),
if (state.ascii) "on" else "off",
state.path,
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index f2490e38..75e4b823 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -1855,6 +1855,15 @@ test "a builtin for one kind of pane is refused on another, and still acts on it
const glyphs = doc.image.?.glyph_art;
try testing.expectEqual(Status.ok, wr(p, Node.of(doc.serial, .ctl), "Petscii\n").reply.status);
try testing.expect(doc.image.?.glyph_art != glyphs);
+ // Its tag says what is drawn: with no graphics, glyph art whatever
+ // Petscii chose; with them, what it chose.
+ for ([_]bool{ false, true }) |art| {
+ doc.image.?.glyph_art = art;
+ p.native_images = false;
+ try testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagPrefix(p, doc), " petscii:on ") != null);
+ p.native_images = true;
+ try testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagPrefix(p, doc), if (art) " petscii:on " else " petscii:off ") != null);
+ }
}
test "exec Save writes the named file through the host" {
diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig
index ae4dcd71..92ce8d8a 100644
--- a/src/ninep/pane.zig
+++ b/src/ninep/pane.zig
@@ -751,7 +751,7 @@ pub fn applyTagTruncation(p: *Pardes, pane: *Pane) void {
pane.tag.own = empty;
// what is left is the prefix; the cursor goes after it
pane.tag.cur_row = 0;
- pane.tag.cur_col = if (tagline.pathPrefix(p.scratch.allocator(), pane)) |prefix| @intCast(prefix.len) else |_| 0;
+ pane.tag.cur_col = if (tagline.pathPrefix(p, p.scratch.allocator(), pane)) |prefix| @intCast(prefix.len) else |_| 0;
pane.tag.vsel.active = false;
pane.tag.nsel = 0;
pf.tag_rewrite = true;
diff --git a/src/pardes.zig b/src/pardes.zig
index 310a4b56..d0bb9229 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -7136,7 +7136,7 @@ pub const Pardes = struct {
var wrap_room: [32 * 1024]u8 = undefined;
var wrap_fba = std.heap.FixedBufferAllocator.init(&wrap_room);
const wa = wrap_fba.allocator();
- const prefix = tagline.prefixIn(wa, pane) catch return pane.tag_rows;
+ const prefix = tagline.prefixIn(p, wa, pane) catch return pane.tag_rows;
const whole = std.mem.concat(wa, u8, &.{ prefix, tagline.curTail(pane) }) catch return pane.tag_rows;
const shown = tagline.wrapTag(wa, whole, tagline.tagWidth(p, id)) catch return pane.tag_rows;
return @intCast(@max(BOX_H, @min(shown.rows(), MAX_TAG_ROWS)));
@@ -7195,7 +7195,7 @@ pub const Pardes = struct {
// every event may take from the scratch arena.
var room: [2 * limits.host_path_cap + 256]u8 = undefined;
var measure = std.heap.FixedBufferAllocator.init(&room);
- const lead = if (tagline.prefixIn(measure.allocator(), pane)) |prefix| prefix.len else |_| pane.tag_lead;
+ const lead = if (tagline.prefixIn(p, measure.allocator(), pane)) |prefix| prefix.len else |_| pane.tag_lead;
if (lead != pane.tag_lead) {
const t = &pane.tag;
const old: i32 = @intCast(pane.tag_lead);
@@ -7215,7 +7215,7 @@ pub const Pardes = struct {
var lines = std.mem.count(u8, tagline.curTail(pane), "\n") + 1;
var wanted = lines;
var caret_row: usize = @intCast(@max(0, pane.tag.cur_row));
- if (tagline.prefixIn(wa, pane)) |prefix| {
+ if (tagline.prefixIn(p, wa, pane)) |prefix| {
if (std.mem.concat(wa, u8, &.{ prefix, tagline.curTail(pane) })) |whole| {
if (tagline.wrapTag(wa, whole, tagline.tagWidth(p, id))) |shown| {
lines = shown.rows();
diff --git a/src/tagline.zig b/src/tagline.zig
index 5a9e2346..a1ce437d 100644
--- a/src/tagline.zig
+++ b/src/tagline.zig
@@ -94,10 +94,11 @@ fn shownDir(arena: std.mem.Allocator, pane: *Pane) ![]const u8 {
/// The computed start of a pane's tag -- its path and dirty marker, a
/// PDF's page, a terminal's directory -- without the space that parts it
/// from the tag's own text. It is never stored, and never edited.
-pub fn pathPrefix(arena: std.mem.Allocator, pane: *Pane) ![]const u8 {
+pub fn pathPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]const u8 {
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);
+ // What is drawn: with no graphics, glyph art whatever `Petscii` says.
+ if (pane.image) |*state| return panes.Image.tagPrefix(arena, state, state.glyph_art or !p.native_images);
// A command pane: its directory, the line it runs, and how that went.
// Its first line only, cut to 48 bytes at a character's start: a tag's
// first row is where the prefix ends, and a line that ran over to a
@@ -127,18 +128,21 @@ pub fn pathPrefix(arena: std.mem.Allocator, pane: *Pane) ![]const u8 {
if (pane.file) |f| return if (pane.prompt == .name) pane.input.own orelse f.path else f.path;
// A terminal showing kitty graphics says how it draws them, as an image
// pane does, and so does one drawing them as glyph art by choice.
- if (panes.terminal.petscii(pane)) |on| if (on or panes.terminal.hasImages(pane))
- return std.fmt.allocPrint(arena, "{s} petscii:{s}", .{ (try shownDir(arena, pane)), if (on) "on" else "off" });
+ if (panes.terminal.petscii(pane)) |chosen| {
+ const on = chosen or !p.native_images;
+ if (chosen or panes.terminal.hasImages(pane))
+ return std.fmt.allocPrint(arena, "{s} petscii:{s}", .{ (try shownDir(arena, pane)), if (on) "on" else "off" });
+ }
return (try shownDir(arena, pane));
}
pub fn tagPrefix(p: *Pardes, pane: *Pane) ![]u8 {
- return prefixIn(p.scratch.allocator(), pane);
+ return prefixIn(p, p.scratch.allocator(), pane);
}
/// The prefix as the tag shows it, built in `arena`.
-pub fn prefixIn(arena: std.mem.Allocator, pane: *Pane) ![]u8 {
- const prefix = try pathPrefix(arena, pane);
+pub fn prefixIn(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]u8 {
+ const prefix = try pathPrefix(p, arena, pane);
// 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
diff --git a/src/terminal.zig b/src/terminal.zig
index 80b9455c..140dae76 100644
--- a/src/terminal.zig
+++ b/src/terminal.zig
@@ -3072,8 +3072,8 @@ test "without pixels, or by the Petscii builtin, a terminal's image is glyph art
try std.testing.expectEqual(@as(usize, 0), imagePlaces(s).len);
try std.testing.expect(painted(s.at(tx, y)) and painted(s.at(tx + 1, y)));
try std.testing.expect(!painted(s.at(tx + 2, y)));
- // The tag says so, as an image pane's does.
- try std.testing.expect(std.mem.indexOf(u8, try tagline.tagPrefix(p, pane), " petscii:off") != null);
+ // The tag says what is drawn, glyph art, as an image pane's does.
+ try std.testing.expect(std.mem.indexOf(u8, try tagline.tagPrefix(p, pane), " petscii:on") != null);
// Pixels where they can be drawn; the builtin flips the pane to glyphs
// and back.