summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CHANGELOG.md5
-rw-r--r--src/config.zig13
-rw-r--r--src/pardes.zig47
-rw-r--r--src/tutor.txt4
4 files changed, 60 insertions, 9 deletions
diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md
index 362aaf5b..76a1fd56 100644
--- a/src/CHANGELOG.md
+++ b/src/CHANGELOG.md
@@ -24,6 +24,11 @@
scroll as it glides, instead of jumping a row of the track at a time.
- A click in another pane glides the cursor once, straight to where it
was clicked, no longer first to that pane's old cursor.
+- Esc in a raw terminal goes back to the previous pane, as it does from
+ normal mode; Shift-Esc sends the program its Esc. `ProgramEsc on`
+ 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.
- 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/config.zig b/src/config.zig
index 8166954d..f3cc0948 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -153,6 +153,7 @@ pub const leader_path = paths: {
table.set(.JumpTrail, null);
table.set(.ChipShadow, null);
table.set(.ThumbFlash, null);
+ table.set(.ProgramEsc, null);
if (builtins.capabilities.lift) table.set(.Lift, null);
table.set(.Motion, null);
table.set(.InactiveDim, null);
@@ -283,8 +284,9 @@ pub const jump_keys = [_]struct { chord: Chord, cmd: Builtin }{
};
/// Shift-Esc: the Esc nothing swallows. In every mode and pane it does what
-/// Esc does from normal mode, back to the previous pane (Last); a raw
-/// terminal's program never sees it. Ctrl-b alone toggles raw.
+/// Esc does from normal mode, back to the previous pane (Last); in a raw
+/// terminal plain Esc does it and Shift-Esc is the program's Esc, unless
+/// ProgramEsc is on. Ctrl-b alone toggles raw.
pub const back_out: []const Chord = &.{.{ .cp = Key.escape, .shift = true }};
pub const tty_toggle_default: u21 = 'b';
@@ -764,6 +766,9 @@ pub const Runtime = struct {
/// T7: in a terminal, a pane's scroll thumb brightens as it scrolls and
/// fades back (truecolor terminals).
thumb_flash: bool = false,
+ /// In a raw terminal, Esc goes to the program and Shift-Esc backs out
+ /// (off, the default: Esc backs out and Shift-Esc is the program's).
+ program_esc: bool = false,
/// How long a message stays after the key or click that dismisses it.
message_linger_ms: u16 = 800,
/// How long its fall into the row takes, easing out (ยง8.1: arriving,
@@ -1022,7 +1027,7 @@ pub const Runtime = struct {
/// The message timings a setting word sets, each in milliseconds.
pub const MessageTime = enum { linger, fall, dissolve };
- pub const Toggle = enum { colors, wrap, tree_context_tag_style, tag_bottom, debug, focus_tint, syntax_bold, pager_color, verbose, message_animation, ligatures, cursor_blink, selection_glow, hover_glow, occlusion, parallax, jump_trail, chip_shadow, thumb_flash };
+ pub const Toggle = enum { colors, wrap, tree_context_tag_style, tag_bottom, debug, focus_tint, syntax_bold, pager_color, verbose, message_animation, ligatures, cursor_blink, selection_glow, hover_glow, occlusion, parallax, jump_trail, chip_shadow, thumb_flash, program_esc };
/// A bundled post pass, a Shadertoy file in shaders/post/: the CRT, and
/// G4's bloom, vignette and grain (docs/effects.md).
pub const Scene = enum { crt, bloom, vignette, grain };
@@ -1090,6 +1095,7 @@ pub const Runtime = struct {
.{ .word = "JumpTrail", .action = .{ .toggle = .jump_trail }, .doc = "In a terminal, a jump of the cursor leaves a short trail that fades, on or off." },
.{ .word = "ChipShadow", .action = .{ .toggle = .chip_shadow }, .doc = "In a terminal, a notice chip casts a cell's shadow right and down, on or off." },
.{ .word = "ThumbFlash", .action = .{ .toggle = .thumb_flash }, .doc = "In a terminal, a pane's scroll thumb brightens as it scrolls and fades back, on or off." },
+ .{ .word = "ProgramEsc", .action = .{ .toggle = .program_esc }, .doc = "In a raw terminal, Esc goes to the program and Shift-Esc backs out, on; off (the default) swaps them." },
.{ .word = "Lift", .action = .lift, .availability = .lift, .doc = "How the focused pane stands off the page: off, shadow, rim or auto." },
.{ .word = "Motion", .action = .motion, .doc = "How animations move: off, crisp, smooth, bouncy or playful." },
.{ .word = "InactiveDim", .action = .inactive_dim, .doc = "Fade the unfocused panes' text by a percentage, 0 through 100, 0 off." },
@@ -1876,6 +1882,7 @@ pub const Runtime = struct {
.jump_trail => "JumpTrail on\n",
.chip_shadow => "ChipShadow on\n",
.thumb_flash => "ThumbFlash on\n",
+ .program_esc => "ProgramEsc on\n",
},
.shell => "Shell fish\n",
.tagline_size => "TaglineSize 73\n",
diff --git a/src/pardes.zig b/src/pardes.zig
index 72470490..c885acc2 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -6374,10 +6374,23 @@ pub const Pardes = struct {
}
const pane = p.panes[p.active] orelse return;
p.noteTyped();
+ // In a raw terminal the two Escs swap unless ProgramEsc is on: Esc
+ // backs out, and Shift-Esc is the program's, sent as a plain Esc.
+ const raw_esc = key.cp == Key.escape and !key.ctrl and !key.alt and !p.settings.program_esc and
+ pane.isTerminal() and pane.body.mode == .tty and pane.focus == .body and pane.prompt == .none and
+ tagline.focusedHeader(p) == null;
+ if (raw_esc and key.shift) {
+ p.leader_on = false;
+ p.ctrl_w_pending = false;
+ panes.terminal.followOutput(pane);
+ var plain = key;
+ plain.shift = false;
+ return panes.terminal.forwardKey(p, p.active, plain);
+ }
// Shift-Esc backs out of whatever the pane is in -- a prompt, insert
// mode, a pending count, a raw program -- to the previous pane, as
// Esc does from normal mode. Nothing under it sees the key.
- if (hit(key, config.back_out)) {
+ if (raw_esc or hit(key, config.back_out)) {
p.leader_on = false;
p.ctrl_w_pending = false;
if (pane.prompt != .none) {
@@ -6405,8 +6418,8 @@ pub const Pardes = struct {
p.ctrl_w_pending = false;
if (key.ctrl and !key.alt and key.cp == p.opts.tty_toggle)
return p.toggleTty(p.active);
- // Bare Escape leaves only at a shell prompt (Shift-Esc, above,
- // always).
+ // With ProgramEsc on, bare Escape leaves only at a shell prompt
+ // (Shift-Esc, above, always).
if (key.cp == Key.escape and !key.ctrl and !key.alt and !key.shift and exec.takesCommandLine(p, p.active))
return exec.runBuiltin(p, .Last, p.active, "", null);
panes.terminal.followOutput(pane); // typing snaps back to live output
@@ -8442,10 +8455,36 @@ test "Esc back into a file leaves its view where it was" {
try std.testing.expectEqual(@as(usize, @intCast(row)) -| @as(usize, dp.rows) / 2, dp.file.?.scroll);
}
-test "raw tty Escape only leaves at a shell prompt" {
+test "raw tty Esc backs out and Shift-Esc is the program's Esc" {
+ if (platform == .web) return;
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24, .file = "mise.toml" });
+ defer p.deinit();
+ _ = exec.spawnTty(p, 0);
+ const shell = p.active;
+ const pane = p.panes[shell].?;
+ var buf: [256]u8 = undefined;
+ _ = drainWrites(p, &buf);
+
+ p.update(.{ .key = .{ .cp = 'x', .text = "x" } });
+ _ = drainWrites(p, &buf);
+ p.update(.{ .key = .{ .cp = Key.escape } }); // past typed text too
+ try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqualStrings("", drainWrites(p, &buf));
+ try std.testing.expectEqual(Text.Mode.tty, pane.body.mode);
+
+ p.update(.{ .key = .{ .cp = Key.escape } }); // back into the shell
+ try std.testing.expectEqual(shell, p.active);
+ _ = drainWrites(p, &buf);
+ p.update(.{ .key = .{ .cp = Key.escape, .shift = true } });
+ try std.testing.expectEqual(shell, p.active);
+ try std.testing.expectEqualStrings("\x1b", drainWrites(p, &buf));
+}
+
+test "with ProgramEsc raw tty Escape only leaves at a shell prompt" {
if (platform == .web) return;
const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24, .file = "mise.toml" });
defer p.deinit();
+ p.settings.program_esc = true;
_ = exec.spawnTty(p, 0);
const shell = p.active;
const pane = p.panes[shell].?;
diff --git a/src/tutor.txt b/src/tutor.txt
index 8f5cf241..5df02f1a 100644
--- a/src/tutor.txt
+++ b/src/tutor.txt
@@ -29,8 +29,8 @@
pane you were in before (not what helix does). Come back with
Esc again.
3. Press Alt-n: a terminal opens, in NORMAL mode. Press Ctrl-b: its
- box shows $ (RAW), and keys go to the shell. At its empty prompt,
- Esc brings you back here; the terminal stays $.
+ box shows $ (RAW), and keys go to the shell. Esc brings you back
+ here; the terminal stays $. Shift-Esc sends the shell an Esc.
-> Guide: Modes