summaryrefslogtreecommitdiff
path: root/core/Command.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Command.zig')
-rw-r--r--core/Command.zig34
1 files changed, 24 insertions, 10 deletions
diff --git a/core/Command.zig b/core/Command.zig
index 55c336f1..908358de 100644
--- a/core/Command.zig
+++ b/core/Command.zig
@@ -659,8 +659,22 @@ fn tagOf(p: *Pardes) ![]const u8 {
return tagline.tagText(p, p.scratch.allocator(), p.panes[p.view().active].?);
}
+/// Whether `needle` is in `hay`, a run of two spaces or more in either read
+/// as two: a right block's padding is its row's (UX D3).
fn has(hay: []const u8, needle: []const u8) bool {
- return std.mem.indexOf(u8, hay, needle) != null;
+ var in: [8192]u8 = undefined;
+ var of: [1024]u8 = undefined;
+ return std.mem.indexOf(u8, squeezed(hay, &in), squeezed(needle, &of)) != null;
+}
+
+fn squeezed(s: []const u8, buf: []u8) []const u8 {
+ var n: usize = 0;
+ for (s, 0..) |c, i| {
+ if (c == ' ' and i >= 2 and s[i - 1] == ' ' and s[i - 2] == ' ') continue;
+ buf[n] = c;
+ n += 1;
+ }
+ return buf[0..n];
}
/// Band row `y`'s text under the live view's active pane.
@@ -685,7 +699,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first,
try std.testing.expectEqual(Prompt.Op.command, s.prompt.op);
try std.testing.expectEqual(panes.Pane.Focus.body, pane.focus);
// The head: its key cell, the field, the count, the hints.
- try std.testing.expect(has(try tagOf(p), " : 16 commands Tab complete · ⏎ run · C-r history · esc"));
+ try std.testing.expect(has(try tagOf(p), ": 16 commands Tab complete · ⏎ run · C-r history · esc"));
// The rows: the tag's words in its order, `in the tag`, the last ruled
// off; then the commands, each what it takes.
try std.testing.expect(has(try bandRow(p, a, 0), "▶ Save "));
@@ -700,7 +714,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first,
try std.testing.expect(has(first[7].text, "theme") and has(first[7].text, "<theme>"));
// Typing filters both, by the scorer, in their order.
typeKeys(p, "th");
- try std.testing.expect(has(try tagOf(p), " : th = Exec th 1 command "));
+ try std.testing.expect(has(try tagOf(p), ": th = Exec th 1 command "));
try std.testing.expect(has(try bandRow(p, a, 0), "▶ theme "));
// Tab: the command, a space after it; the field's plain word is its
// pardes word once it is whole.
@@ -708,7 +722,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first,
try std.testing.expectEqualStrings("theme ", s.field.text());
typeKeys(p, "acme");
const worn = colors.themes[p.theme_preview.?].name;
- try std.testing.expect(has(try tagOf(p), try std.fmt.allocPrint(a, " : theme acme = Exec Theme {s} ", .{worn})));
+ try std.testing.expect(has(try tagOf(p), try std.fmt.allocPrint(a, ": theme acme = Exec Theme {s} ", .{worn})));
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expectEqual(TagState.Kind.rest, s.kind);
try std.testing.expectEqualStrings(worn, p.theme().name);
@@ -718,7 +732,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first,
// `:sort`: the selections piped through sort, as `|sort` does.
while (p.nextEffect()) |_| {}
typeKeys(p, "%:sort");
- try std.testing.expect(has(try tagOf(p), " : sort = Exec Edit |sort 1 command"));
+ try std.testing.expect(has(try tagOf(p), ": sort = Exec Edit |sort 1 command"));
p.update(.{ .key = .{ .cp = Key.enter } });
var asked: ?u32 = null;
while (p.nextEffect()) |effect| if (effect == .pipe) {
@@ -727,7 +741,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first,
try std.testing.expectEqualStrings("sort", p.pipe.pipeRequest(asked orelse return error.MissingPipeEffect).?.command);
// `:goto 2`: Look `:2`.
typeKeys(p, ":goto 2");
- try std.testing.expect(has(try tagOf(p), " : goto 2 = Look :2 <line> "));
+ try std.testing.expect(has(try tagOf(p), ": goto 2 = Look :2 <line> "));
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row);
// S-Tab: the last row; Tab after it, round to the first. A tag word
@@ -819,9 +833,9 @@ test ":theme lists the themes and the whole window wears the current one, none d
try std.testing.expectEqual(Rows.values, s.prompt.command.rows);
try std.testing.expectEqual(@as(u16, 2), s.nhits);
try std.testing.expect(has(try bandRow(p, a, 0), "▶ on now"));
- try std.testing.expect(has(try tagOf(p), " : set Wrap = Exec Wrap 2 values "));
+ try std.testing.expect(has(try tagOf(p), ": set Wrap = Exec Wrap 2 values "));
typeKeys(p, "of");
- try std.testing.expect(has(try tagOf(p), " : set Wrap of = Exec Wrap of 1 value "));
+ try std.testing.expect(has(try tagOf(p), ": set Wrap of = Exec Wrap of 1 value "));
p.update(.{ .key = .{ .cp = Key.tab } });
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expect(!p.settings.wrap);
@@ -843,7 +857,7 @@ test ":theme lists the themes and the whole window wears the current one, none d
// :open: the line goes to Find, the rest of it the query, the keys
// after it typed into Find's field.
typeKeys(p, ":o");
- try std.testing.expect(has(try tagOf(p), " : o = Exec Find "));
+ try std.testing.expect(has(try tagOf(p), ": o = Exec Find "));
typeKeys(p, " te");
try std.testing.expectEqual(TagState.Kind.pick, s.kind);
try std.testing.expectEqual(pardes.Pick.Source.find, pardes.Pick.live(p).?.source);
@@ -885,7 +899,7 @@ test ": has a history of its own: Up and Down bring back the lines Enter ran, ne
typeKeys(p, ":");
p.update(.{ .key = .{ .cp = Key.up } });
try std.testing.expectEqualStrings("goto 2", s.field.text());
- try std.testing.expect(has(try tagOf(p), " : goto 2 = Look :2 <line> "));
+ try std.testing.expect(has(try tagOf(p), ": goto 2 = Look :2 <line> "));
p.update(.{ .key = .{ .cp = Key.up } });
try std.testing.expectEqualStrings("set Wrap off", s.field.text());
try std.testing.expectEqual(Rows.values, s.prompt.command.rows);