summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CHANGELOG.md7
-rw-r--r--src/builtins.zig10
-rw-r--r--src/config.zig14
-rw-r--r--src/draw.zig17
-rw-r--r--src/layout.zig72
-rw-r--r--src/mouse.zig1
-rw-r--r--src/pardes.zig85
-rw-r--r--src/tutor.txt7
8 files changed, 183 insertions, 30 deletions
diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md
index 76a1fd56..6f94b98f 100644
--- a/src/CHANGELOG.md
+++ b/src/CHANGELOG.md
@@ -29,6 +29,13 @@
restores the old way round. A terminal without the kitty keyboard
protocol sends Shift-Esc as a plain Esc, so under one a program gets
no Esc unless ProgramEsc is on.
+- Window mode (`Window`, Ctrl-w or SPC w): every pane shows a letter
+ and the focused one is outlined; h/j/k/l move the outline without
+ giving any pane the keys, Enter or Esc focuses the outlined pane, `:`
+ its tag, and a
+ pane's letter jumps straight to it. Ctrl-w h/j/k/l and SPC w h/j/k/l
+ no longer move the focus at once; on a column or workspace tag Ctrl-w
+ h/j/k/l still walk the tags.
- Built with Zig 0.17. A bare `zig build` still puts the binaries in
`~/.local/bin`, now as a copy beside the prefix, which `--prefix` no
diff --git a/src/builtins.zig b/src/builtins.zig
index 83966228..6ecd3c9e 100644
--- a/src/builtins.zig
+++ b/src/builtins.zig
@@ -1819,6 +1819,16 @@ pub const Right = struct {
}
};
+/// Window mode: h/j/k/l move an outline between the panes; Enter or Esc
+/// focuses the outlined pane, `:` its tag, the letter shown on a pane that one.
+pub const Window = struct {
+ pub fn run(c: Ctx) void {
+ tagline.exitHeader(c.p);
+ c.p.window_pick = if (c.p.panes[c.id] != null) c.id else c.p.active;
+ c.p.setMessage(c.p.window_pick.?, "Window: h/j/k/l move, Enter or Esc focuses the outlined pane, : its tag, a letter that pane");
+ }
+};
+
// ---- the jump group ----
/// Ctrl-o: one step back into the history.
diff --git a/src/config.zig b/src/config.zig
index f3cc0948..a92aabb6 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -119,10 +119,11 @@ pub const leader_path = paths: {
.Ascii = "ta",
.Dump = "sd",
.Restore = "sr",
- .Left = "wh",
- .Down = "wj",
- .Up = "wk",
- .Right = "wl",
+ .Left = null,
+ .Down = null,
+ .Up = null,
+ .Right = null,
+ .Window = "w",
.Back = "jo",
.Forward = "ji",
.Last = "jj",
@@ -212,7 +213,7 @@ pub const leader_path = paths: {
test "Space-k is unbound while Exit, Kill and other k chords remain available" {
try std.testing.expect(leader_path.get(.Kill) == null);
try std.testing.expectEqualStrings("q", leader_path.get(.Exit).?);
- try std.testing.expectEqualStrings("wk", leader_path.get(.Up).?);
+ try std.testing.expectEqualStrings("w", leader_path.get(.Window).?);
try std.testing.expectEqualStrings("lk", leader_path.get(.Hover).?);
try std.testing.expectEqualStrings("d", leader_path.get(.Del).?);
for (pardes.builtin_rows) |row| if (row.cmd == .Kill) {
@@ -264,7 +265,8 @@ pub const select_button: Mouse.Button = .left;
pub const look_cmd: Builtin = .Look;
pub const exec_cmd: Builtin = .Exec;
-// Ctrl-w remains available when a terminal owns printable keys.
+// Ctrl-w: window mode (layout.windowKey), as SPC w; on a header it
+// prefixes h/j/k/l, a move between the headers.
pub const window_prefix: []const Chord = &.{.{ .cp = 'w', .ctrl = true }};
pub const window_keys = [_]struct { letter: Chord, arrow: Chord, cmd: Builtin }{
diff --git a/src/draw.zig b/src/draw.zig
index 31157b1d..1cf136bd 100644
--- a/src/draw.zig
+++ b/src/draw.zig
@@ -1208,6 +1208,21 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r
@memset(storage, .{});
var temporary: Surface = .{ .cols = columns + TAG_TEXT_INSET, .rows = rows, .cells = storage };
try paintPaneTag(p, &temporary, arena, pane, .{ .x = 0, .y = 0, .w = columns + TAG_TEXT_INSET, .h = rows }, id, active, capacity);
+ // Window mode (layout.windowKey): the outlined pane's tag in the
+ // selection's colours, and each pane's letter over its tag's start.
+ if (p.window_pick) |pick| {
+ const th = p.theme();
+ if (pick == id) for (storage) |*cell| {
+ cell.style.bg = .{ .rgb = th.sel_bg };
+ cell.style.fg = .{ .rgb = th.sel_fg };
+ cell.default = false;
+ };
+ if (layout.windowLabel(p, id)) |letter| if (columns >= 3) for (" ? ", 0..) |ch, i| {
+ const at = temporary.at(@intCast(TAG_TEXT_INSET + i), 0);
+ const style: CellStyle = .{ .fg = .{ .rgb = chrome.tag_bg }, .bg = .{ .rgb = chrome.tag_fg }, .bold = true, .font_role = at.style.font_role };
+ temporary.set(@intCast(TAG_TEXT_INSET + i), 0, &.{if (ch == '?') letter else ch}, style);
+ };
+ }
const tag_fg: Color = .{ .rgb = if (active and p.settings.focus_tint) chrome.tag_active_fg else chrome.tag_fg };
// One layer, a row to each line the tag shows.
const layer = &s.tag_layers[id];
@@ -1220,7 +1235,7 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r
layer.cols = columns;
layer.rows = rows;
layer.context_rows = 0;
- layer.bg = if (active and p.settings.focus_tint) chrome.tag_active_bg else chrome.tag_bg;
+ layer.bg = if (p.window_pick == id) p.theme().sel_bg else if (active and p.settings.focus_tint) chrome.tag_active_bg else chrome.tag_bg;
layer.slide = 0;
layer.fade = 1;
layer.cursor = if (p.header_focus) null else if (temporary.cursor) |cursor|
diff --git a/src/layout.zig b/src/layout.zig
index 40bce75a..6345c91a 100644
--- a/src/layout.zig
+++ b/src/layout.zig
@@ -27,8 +27,19 @@ pub const MovePlacement = struct {
above_h: u16,
};
+pub const Dir = enum { left, right, up, down };
+
/// Move the keyboard to the nearest pane in `dir`; false when there is none.
-pub fn focusDir(p: *Pardes, from: usize, dir: enum { left, right, up, down }) bool {
+pub fn focusDir(p: *Pardes, from: usize, dir: Dir) bool {
+ const b = nearest(p, from, dir) orelse return false;
+ p.active = b;
+ // a count typed before the hop was meant for the pane you left
+ p.panes[b].?.body.normal.clear();
+ return true;
+}
+
+/// The pane next to `from` in `dir`, by the screen.
+pub fn nearest(p: *const Pardes, from: usize, dir: Dir) ?usize {
const a = p.rects[from];
var best: ?usize = null;
var best_d: i32 = 0;
@@ -55,11 +66,60 @@ pub fn focusDir(p: *Pardes, from: usize, dir: enum { left, right, up, down }) bo
best_d = d;
}
}
- const b = best orelse return false;
- p.active = b;
- // a count typed before the hop was meant for the pane you left
- p.panes[b].?.body.normal.clear();
- return true;
+ return best;
+}
+
+/// Window mode's labels, one a pane in reading order (columns left to
+/// right, each top to bottom); h, j, k and l move instead. ponytail: a
+/// pane past the 22nd has no label and is reached by moving.
+pub const window_labels = "asdfgqwertyuiopzxcvbnm";
+
+/// The letter window mode shows on pane `id`.
+pub fn windowLabel(p: *const Pardes, id: usize) ?u8 {
+ var n: usize = 0;
+ for (0..p.ncol) |c| for (p.col_panes[c][0..p.col_n[c]]) |pane| {
+ if (n == window_labels.len) return null;
+ if (pane == id) return window_labels[n];
+ n += 1;
+ };
+ return null;
+}
+
+/// Window mode (SPC w, Ctrl-w): h/j/k/l (or the arrows) move an outline
+/// from pane to pane and nothing else gets the keys; Enter or Esc focuses
+/// the outlined pane, `:` its tag, and a pane's label letter that one. Up past a
+/// column's top pane goes on to its tag, as the Up word does. Any other
+/// key changes nothing.
+pub fn windowKey(p: *Pardes, key: pardes.Key) void {
+ const at = p.window_pick orelse return;
+ if (p.panes[at] == null) {
+ p.window_pick = null;
+ return;
+ }
+ if (key.ctrl or key.alt) return;
+ for (config.window_keys) |wk| if (pardes.hit(key, &.{ wk.letter, wk.arrow })) {
+ const dir: Dir = switch (wk.cmd) {
+ .Left => .left,
+ .Down => .down,
+ .Up => .up,
+ else => .right,
+ };
+ if (nearest(p, at, dir)) |next| {
+ p.window_pick = next;
+ } else if (dir == .up) {
+ p.window_pick = null;
+ p.active = at;
+ pardes.exec.runBuiltin(p, .Up, at, "", null);
+ }
+ return;
+ };
+ const chosen = if (key.cp == pardes.Key.enter or key.cp == pardes.Key.escape or key.cp == ':') at else for (0..p.panes.len) |id| {
+ if (p.panes[id] != null and key.cp < 128 and windowLabel(p, id) == @as(u8, @intCast(key.cp))) break id;
+ } else return;
+ p.window_pick = null;
+ p.active = chosen;
+ p.panes[chosen].?.body.normal.clear();
+ if (key.cp == ':') tagline.enterTag(p, p.panes[chosen].?);
}
/// Column `c`'s serial, handed out the first time it is asked for.
diff --git a/src/mouse.zig b/src/mouse.zig
index 43323f9a..76c65a16 100644
--- a/src/mouse.zig
+++ b/src/mouse.zig
@@ -465,6 +465,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
var m = event;
// A click goes somewhere else: the question it leaves unanswered is
// taken back, and the pane stays. A wheel only looks around.
+ if (m.kind == .press) p.window_pick = null;
if (m.kind == .press and switch (m.button) {
.left, .middle, .right => true,
else => false,
diff --git a/src/pardes.zig b/src/pardes.zig
index c885acc2..cb2ebe56 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -2983,9 +2983,7 @@ fn chordName(comptime c: config.Chord) []const u8 {
fn shortcutCount(comptime b: Builtin) comptime_int {
var count = 0;
- for (config.window_keys) |wk| if (wk.cmd == b) {
- count += 2;
- };
+ if (b == .Window) count += 1;
for (config.jump_keys) |jk| if (jk.cmd == b) {
count += 1;
};
@@ -3003,13 +3001,9 @@ fn shortcuts(comptime b: Builtin) []const u8 {
@setEvalBranchQuota(20000);
var parts: [shortcutCount(b)][]const u8 = undefined;
var part: usize = 0;
- for (config.window_keys) |wk| {
- if (wk.cmd != b) continue;
- // the prefix has one spelling and this is it
- const pfx = chordName(config.window_prefix[0]) ++ " ";
- parts[part] = pfx ++ chordName(wk.letter);
- parts[part + 1] = pfx ++ chordName(wk.arrow);
- part += 2;
+ if (b == .Window) {
+ parts[part] = chordName(config.window_prefix[0]);
+ part += 1;
}
for (config.jump_keys) |jk| {
if (jk.cmd == b) {
@@ -4614,6 +4608,8 @@ pub const Pardes = struct {
/// default one.
register: u21 = 0,
leader_on: bool = false,
+ /// Window mode's outlined pane (layout.windowKey); null outside it.
+ window_pick: ?usize = null,
leader_keys: [4]u8 = undefined,
leader_n: u8 = 0,
/// The keyboard is on a header: the column tag `header_column` names, or
@@ -6372,6 +6368,7 @@ pub const Pardes = struct {
}
return;
}
+ if (p.window_pick != null) return layout.windowKey(p, key);
const pane = p.panes[p.active] orelse return;
p.noteTyped();
// In a raw terminal the two Escs swap unless ProgramEsc is on: Esc
@@ -6447,12 +6444,16 @@ pub const Pardes = struct {
}
return;
}
- // insert mode owns Ctrl-w (delete word backward, helix); the focus
- // prefix applies outside raw tty mode
+ // insert mode owns Ctrl-w (delete word backward, helix); outside raw
+ // tty mode it enters window mode, or on a header prefixes a move
+ // between the headers
const t = header orelse if (pane.focus == .tag) &pane.tag else &pane.body;
if (hit(key, config.window_prefix) and t.mode != .insert and (header != null or pane.prompt == .none)) {
- p.ctrl_w_pending = true;
- return;
+ if (header != null) {
+ p.ctrl_w_pending = true;
+ return;
+ }
+ return exec.runBuiltin(p, .Window, p.active, "", null);
}
// global window ops (any mode): Alt-n new terminal below, Alt-c move
// the active terminal into a fresh column
@@ -8534,6 +8535,61 @@ test "Shift-Esc backs out to the previous pane in every mode, never into raw" {
try std.testing.expect(p.active != 0);
}
+test "window mode moves an outline and focuses it on Enter, Esc or a label" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 30 });
+ defer p.deinit();
+ _ = try p.setTestFile("left\n");
+ _ = try p.newShell(1, "");
+ try std.testing.expect(layout.splitColumn(p, 0, 1, false));
+ p.newScratchBelow(1);
+ p.sync();
+ const lower = for (p.panes, 0..) |slot, id| {
+ if (slot != null and id > 1) break id;
+ } else return error.TestExpectedScratch;
+ p.active = 0;
+ // Ctrl-w enters it; h/j/k/l move only the outline.
+ p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
+ try std.testing.expectEqual(@as(?usize, 0), p.window_pick);
+ p.update(.{ .key = .{ .cp = 'l', .text = "l" } });
+ try std.testing.expect(p.window_pick != null and p.window_pick.? != 0);
+ p.update(.{ .key = .{ .cp = 'j', .text = "j" } });
+ try std.testing.expectEqual(@as(?usize, lower), p.window_pick);
+ try std.testing.expectEqual(@as(usize, 0), p.active);
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ try std.testing.expectEqual(lower, p.active);
+ try std.testing.expect(p.window_pick == null);
+ // SPC w enters it too, and Esc also leaves it on the outlined pane.
+ p.update(.{ .key = .{ .cp = ' ', .text = " " } });
+ p.update(.{ .key = .{ .cp = 'w', .text = "w" } });
+ p.update(.{ .key = .{ .cp = 'h', .text = "h" } });
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expect(p.window_pick == null);
+ // Other keys change nothing.
+ p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
+ p.update(.{ .key = .{ .cp = '!', .text = "!" } });
+ try std.testing.expectEqual(@as(?usize, 0), p.window_pick);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ // `:` focuses the outlined pane's tag.
+ p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
+ p.update(.{ .key = .{ .cp = 'l', .text = "l" } });
+ p.update(.{ .key = .{ .cp = ':', .text = ":" } });
+ try std.testing.expect(p.active != 0 and p.panes[p.active].?.focus == .tag);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ // A label goes straight there: the left column's pane is "a".
+ try std.testing.expectEqual(@as(?u8, 'a'), layout.windowLabel(p, 0));
+ try std.testing.expect(p.executeBuiltinLine(p.active, "Window"));
+ p.update(.{ .key = .{ .cp = 'a', .text = "a" } });
+ try std.testing.expectEqual(@as(usize, 0), p.active);
+ // Painted: the outlined tag's band in the selection colour, a label on each.
+ try std.testing.expect(p.executeBuiltinLine(p.active, "Window"));
+ var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
+ defer arena.deinit();
+ const shown = try p.render(arena.allocator());
+ try std.testing.expectEqual(p.theme().sel_bg, shown.tag_layers[0].bg);
+ try std.testing.expectEqualStrings("a", shown.tag_layers[0].cells[1].text[0..shown.tag_layers[0].cells[1].len]);
+}
+
test "raw tty Ctrl-B switches to editor mode without sending child input" {
if (platform == .web) return;
const p = try Pardes.init(std.testing.allocator, .{ .file = "mise.toml" });
@@ -8660,6 +8716,7 @@ test "hopping between two panes does not grow the jump stack" {
p.update(.{ .key = .{ .cp = ' ' } });
p.update(.{ .key = .{ .cp = 'w' } });
p.update(.{ .key = .{ .cp = dir } });
+ p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expectEqual(want, p.active);
}
try std.testing.expectEqual(depth, p.njumps);
diff --git a/src/tutor.txt b/src/tutor.txt
index 5df02f1a..b71b3bf2 100644
--- a/src/tutor.txt
+++ b/src/tutor.txt
@@ -83,7 +83,8 @@
shows its output, and the keyboard stays here.
2. `Exec` `New` in this column's tag: a scratch opens and
takes the keyboard.
- 3. Ctrl-w h, j, k, l move the keyboard between panes; Ctrl-o and
+ 3. Ctrl-w shows a letter on every pane: h, j, k, l move the outline
+ and Enter goes there, or press a pane's letter. Ctrl-o and
Ctrl-i walk back and forward through where you have been.
4. `Del` the scratch and the command pane, each in its own tag.
@@ -283,7 +284,7 @@ typed
SPC d `Del` SPC q `Exit`
SPC f s `Save` SPC f f `Find` SPC f n `New`
SPC y yank to the clipboard SPC p paste from it
- SPC w h focus left (and j, k, l)
+ SPC w window mode: h/j/k/l, Enter
SPC j j `Last` SPC j o / SPC j i back / forward
SPC s a `Attach` SPC s D `Detach`
SPC t ... the toggles SPC l ... the language
@@ -328,7 +329,7 @@ typed
2-1 `Exec` the middle word with the left selection
keyboard: Enter = `Look`, Tab = `Exec`
- PANES Ctrl-w h/j/k/l focus a neighbour (NORMAL mode)
+ PANES Ctrl-w h/j/k/l pick a pane, Enter (NORMAL mode)
Ctrl-o / Ctrl-i jump history back / forward
Alt-n new terminal Alt-c pane into a new column