summaryrefslogtreecommitdiff
path: root/src/exec.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/exec.zig')
-rw-r--r--src/exec.zig37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/exec.zig b/src/exec.zig
index ece4f98d..b4c20f45 100644
--- a/src/exec.zig
+++ b/src/exec.zig
@@ -112,7 +112,7 @@ pub fn operandAt(p: *Pardes, pane: *Pane, clicked: Pane.Sel, borrow: bool, for_l
const visible = clicked.r0 - @as(i32, pane.tag_rows);
const wrapped = pane.wrapAt(visible);
const raw = pane.isTerminal() and pane.body.mode == .tty and clicked.r0 >= pane.tag_rows;
- const row = if (raw) panes.terminal.gridOffset(pane) + visible else wrapped.line;
+ const row = if (raw) @as(i32, @intCast(panes.Term.grid(pane.terminal).offset)) + visible else wrapped.line;
const raw_line = if (raw) modal.lineSlice(body_layer.bodyText(p.scratch.allocator(), pane) catch "", @intCast(@max(0, visible))) else "";
const col = if (raw)
@as(i32, @intCast(panes.File.rawAtDisplay(raw_line, @intCast(@max(0, clicked.c0)))))
@@ -144,7 +144,7 @@ pub fn operandAt(p: *Pardes, pane: *Pane, clicked: Pane.Sel, borrow: bool, for_l
lo -|= span.prompt_bytes;
hi -|= span.prompt_bytes;
} else if (!span.raw_terminal and raw) {
- const prefix = panes.terminal.promptPrefixBytes(pane, row, raw_line);
+ const prefix = panes.Term.promptPrefix(pane.terminal, row, raw_line);
lo += prefix;
hi += prefix;
}
@@ -587,7 +587,7 @@ pub fn sendToRepl(p: *Pardes, from: usize, to: usize, text: []const u8) void {
var said: pardes.Kind.Buf(128) = .{};
return p.setMessage(from, said.print("Repl: {d} bytes is more than can be sent at once; send less", .{n}));
}
- const pasted = panes.terminal.bracketedPaste(dst);
+ const pasted = panes.Term.modes(dst.terminal).bracketed_paste;
edit.typeToTty(p, to, dst, clean[0..n]);
// A Python block whose last line is indented, or a bare header, is not
// over at one Enter, pasted into 3.13's REPL or typed into the old one:
@@ -610,7 +610,7 @@ pub fn sendToRepl(p: *Pardes, from: usize, to: usize, text: []const u8) void {
dst.repl_enter_due_ns = clockNow(p) + repl_enter_wait_ns;
} else for (0..enters) |_| p.emitWrite(to, "\r");
// Line by line, a blank line inside a Python block ends the block.
- if (!panes.terminal.bracketedPaste(dst) and !dst.repl_warned and (if (dst.repl) |r| r.lang == python_lang else false) and
+ if (!panes.Term.modes(dst.terminal).bracketed_paste and !dst.repl_warned and (if (dst.repl) |r| r.lang == python_lang else false) and
std.mem.indexOfScalar(u8, text, '\n') != null)
{
dst.repl_warned = true;
@@ -655,7 +655,8 @@ pub fn takesCommandLine(p: *const Pardes, id: usize) bool {
// idle, EMPTY prompt is typed at; otherwise a new pane runs the line.
// (Text in pardes's own edit buffer is not the shell's yet: an exec of
// it, or of anything, types only what it runs.)
- if (panes.terminal.promptInputReady(pane) and !panes.terminal.promptInputEmpty(pane)) return false;
+ const at = panes.Term.prompt(pane.terminal);
+ if (at.input_ready and !at.input_empty) return false;
return !p.hostTtyTaken(id);
}
@@ -696,9 +697,19 @@ pub fn executeFrom(p: *Pardes, id: usize, txt: []const u8, from_body: bool) ?usi
// command pane in the session's directory, never typed into whichever
// terminal has the keyboard.
if (p.exec_header or !takesCommandLine(p, id)) return runCommand(p, id, cmd);
- panes.terminal.padOutputBelowEdits(p, id);
- panes.terminal.noteCommand(pane, cmd);
- if (panes.terminal.queuePendingCommand(pane, cmd) catch |err| {
+ // At a prompt with typed text below it: the output area padded with
+ // newlines so the command's output does not overwrite the buffer.
+ if (pane.ovl) |o| if (pane.isTerminal()) if (pane.terminal) |state| if (panes.Term.prompt(state).at_prompt) {
+ // the buffer's LAST surface row: its lines may outnumber the shell
+ // rows it covers, and it is the bottom one output must clear
+ const max_row = o.row + @as(i32, @intCast(modal.lineCount(o.text))) - 1;
+ const grid = panes.Term.grid(state);
+ const cursor_abs = pane.surfRow(@as(i32, @intCast(grid.offset)) + @as(i32, grid.cursor_y));
+ const pad = std.math.clamp(max_row - cursor_abs, 0, @as(i32, pane.rows));
+ for (0..@intCast(pad)) |_| p.emitWrite(id, "\r");
+ };
+ pane.noteCommand(cmd);
+ if (pane.queuePendingCommand(cmd) catch |err| {
p.reportError(id, "queue command", err);
return id;
}) return id;
@@ -756,10 +767,10 @@ pub fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize {
// What the last program left the emulator in goes first: the
// alternate screen left (only if it is there: leaving restores a
// saved cursor), mouse reports and bracketed paste off, the cursor
- // shown, colours reset. (Not DECSTR: ghostty's stream does not
+ // shown, colours reset. (Not DECSTR: the emulator's stream does not
// implement it.)
- if (panes.terminal.onAlternateScreen(pane)) panes.terminal.feedOutput(p, pane, "\x1b[?1049l");
- panes.terminal.feedOutput(p, pane, "\x1b[?1000l\x1b[?1002l\x1b[?1003l\x1b[?1006l\x1b[?2004l\x1b[?25h\x1b[0m");
+ if (panes.Term.modes(pane.terminal).alternate) pane.feedOutput(p, "\x1b[?1049l");
+ pane.feedOutput(p, "\x1b[?1000l\x1b[?1002l\x1b[?1003l\x1b[?1006l\x1b[?2004l\x1b[?25h\x1b[0m");
echoCommand(p, pane, line);
pane.command_from = winid(p, src);
p.emitSpawn(id, pane.serial, pane.cwdSlice());
@@ -809,11 +820,11 @@ fn echoCommand(p: *Pardes, pane: *Pane, line: []const u8) void {
var w = std.Io.Writer.fixed(&buf);
// A line past the room is cut at its end.
echo: {
- w.writeAll(if (panes.terminal.gridCursor(pane).x != 0) "\r\n% " else "% ") catch break :echo;
+ w.writeAll(if (panes.Term.grid(pane.terminal).cursor_x != 0) "\r\n% " else "% ") catch break :echo;
for (line) |c| (if (c == '\n') w.writeAll("\r\n") else w.writeByte(c)) catch break :echo;
w.writeAll("\r\n") catch break :echo;
}
- panes.terminal.feedOutput(p, pane, w.buffered());
+ pane.feedOutput(p, w.buffered());
}
/// Trim and unwrap clickable command-word notation once for every command