summaryrefslogtreecommitdiff
path: root/src/keys.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/keys.zig')
-rw-r--r--src/keys.zig51
1 files changed, 46 insertions, 5 deletions
diff --git a/src/keys.zig b/src/keys.zig
index 7703d573..c4651be7 100644
--- a/src/keys.zig
+++ b/src/keys.zig
@@ -46,11 +46,52 @@ pub fn cycleMode(p: *Pardes, id: usize) void {
.normal => edit.enterInsert(p, &pane.body, .at, 1) catch |err| p.reportError(id, "edit", err),
.insert => {
edit.exitInsert(p, &pane.body);
- if (pane.isTerminal()) panes.terminal.enterTty(p, id);
+ if (pane.isTerminal()) enterTty(p, id);
},
}
}
+/// Raw tty mode, the keys the program's: the shell's cursor first moved to
+/// where the edit cursor was on its prompt line (cursor keys, as a click
+/// there would), unless the pointer holds a selection to keep.
+pub fn enterTty(p: *Pardes, id: usize) void {
+ const pane = p.panes[id] orelse return;
+ const selected = pane.rawPointerText(pane.sel[@backingInt(config.select_button)]) != null;
+ if (!selected and pane.body.cur_pinned) if (pane.terminal) |state| {
+ const row = pane.gridRow(pane.body.cur_row) - @as(i32, @intCast(panes.Term.grid(state).offset));
+ if (panes.Term.promptMoves(state, row, pane.body.cur_col)) |moves| {
+ for (0..moves.left) |_| p.emitWrite(id, "\x1b[D");
+ for (0..moves.right) |_| p.emitWrite(id, "\x1b[C");
+ }
+ };
+ pane.body.mode = .tty;
+ pane.followOutput(); // entering raw mode is a request for the live shell
+ pane.body.vsel.active = false;
+ pane.body.nsel = 0;
+ // The raw renderer follows the live cursor. A captured mouse selection
+ // keeps its modal endpoint for the next return to editor mode.
+ pane.body.cur_pinned = selected;
+ pane.body.select = false;
+ pane.body.restore_cursor = false;
+ pane.body.sticky_col = -1;
+ pane.body.normal.clear();
+}
+
+/// One key for the program that owns a raw terminal, its pty write queued.
+pub fn forwardKey(p: *Pardes, id: usize, key: Key) void {
+ const pane = p.panes[id] orelse return;
+ const state = pane.terminal orelse return;
+ // A key's text has no bound of its own (an input method's commit, a
+ // paste as one key): past the stack's room the encoding grows on the
+ // heap, and emitWrite cuts it into writes.
+ var room: [256]u8 = undefined;
+ var first: std.heap.BufferFirstAllocator = .init(&room, p.gpa);
+ var out: std.Io.Writer.Allocating = .init(first.allocator());
+ defer out.deinit();
+ panes.Term.key(state, key, &out.writer) catch |err| return p.reportError(id, "key", err);
+ if (out.written().len > 0) p.emitWrite(id, out.written());
+}
+
/// One mode transition for the terminal tag command and the Ctrl-B chord.
pub fn toggleTty(p: *Pardes, id: usize) void {
const pane = p.panes[id] orelse return;
@@ -62,7 +103,7 @@ pub fn toggleTty(p: *Pardes, id: usize) void {
if (pane.body.mode == .tty) {
pane.body.mode = .normal;
pane.body.normal.clear();
- } else panes.terminal.enterTty(p, id);
+ } else enterTty(p, id);
}
/// Type `keys` again (a macro, `.`): through the modal handling as
@@ -179,7 +220,7 @@ pub fn handleKey(p: *Pardes, key: Key) void {
pane.followOutput();
var plain = key;
plain.shift = false;
- return panes.terminal.forwardKey(p, p.view().active, plain);
+ return forwardKey(p, p.view().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
@@ -225,7 +266,7 @@ pub fn handleKey(p: *Pardes, key: Key) void {
// Ctrl-V a black hole in every full-screen application.
if (p.registers.text(p.gpa, Registers.default)) |text| return edit.typeToTty(p, p.view().active, pane, text);
}
- return panes.terminal.forwardKey(p, p.view().active, key);
+ return forwardKey(p, p.view().active, key);
}
// A kind's pane that takes keys takes them all, as a raw terminal
// does; Esc too, first, when its kind is of 2.1 (a PDF's drops its
@@ -406,7 +447,7 @@ pub fn handleKey(p: *Pardes, key: Key) void {
edit.exitInsert(p, t)
else
edit.handleInsert(p, t, key),
- .tty => panes.terminal.forwardKey(p, p.view().active, key),
+ .tty => forwardKey(p, p.view().active, key),
}
// `.`'s log: the keys of the normal command that entered insert
// mode, then everything typed until it is left