summaryrefslogtreecommitdiff
path: root/src/exec.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/exec.zig')
-rw-r--r--src/exec.zig84
1 files changed, 41 insertions, 43 deletions
diff --git a/src/exec.zig b/src/exec.zig
index df578d08..5f5a2206 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;
}
@@ -165,44 +165,30 @@ pub fn operandAt(p: *Pardes, pane: *Pane, clicked: Pane.Sel, borrow: bool, for_l
return result;
}
}
- // In a diff, a file or hunk header, and a hunk line pointed at on its
- // `+`/`-`/` ` prefix, expand to the whole line (the hover shows it) and
- // the look is of the address it names (look.diffAddress), a regular
- // look from there. A hunk line's code is words, looked at as ever:
- // the code's, the prefix never one of them.
- // A query pane's row pointed at on its gutter (its line number): the
- // look is of the row's address (Query.rowAddress), as a +Diff line's
- // prefix is its place; the row's code is words, looked at as ever.
- if (for_look and pane.query != null and clicked.r0 >= pane.tag_rows and clicked.r0 == clicked.r1 and clicked.c0 == clicked.c1 and row >= 0 and col >= 0) gutter: {
- var address_buf: [4096 + 32]u8 = undefined;
- const address = panes.Query.rowAddress(pane, @intCast(row), @intCast(col), &address_buf) orelse break :gutter;
- const meta = pane.file.?.location_rows[@intCast(row)];
- result.text = p.scratch.allocator().dupe(u8, address) catch break :gutter;
- result.file_word = .{ .row = row, .lo = 0, .hi = @intCast(meta.location_end) };
- const expanded = fileWordCells(pane, clicked, row, 0, @intCast(meta.location_end)) orelse return result;
- result.preview = expanded;
- result.expanded = expanded;
- return result;
- }
+ // A row that names an address (look.rowAddressAt), pointed at on it: a
+ // query pane's row on its address (its gutter), a diff's file or hunk
+ // header anywhere, a hunk line on its `+`/`-`/` ` prefix. It expands
+ // to the address's text (the hover shows it) and the look is of the
+ // address, a regular look from there. A row's code is words, looked at
+ // as ever: the code's, the prefix never one of them. A click left of a
+ // query pane's text is no part of its row.
var word_from: usize = 0;
- if (for_look and clicked.r0 >= pane.tag_rows and clicked.r0 == clicked.r1 and clicked.c0 == clicked.c1 and row >= 0) diff: {
+ if (for_look and clicked.r0 >= pane.tag_rows and clicked.r0 == clicked.r1 and clicked.c0 == clicked.c1 and row >= 0 and (col >= 0 or pane.query == null)) row_address: {
var address_buf: [4096 + 32]u8 = undefined;
- const at: usize = @intCast(row);
- const click = look.diffClick(p, pane, at, @intCast(@max(0, col)), &address_buf) orelse break :diff;
- const address = click.address orelse {
- word_from = click.word_from;
- break :diff;
+ const got = look.rowAddressAt(p, pane, @intCast(row), @intCast(@max(0, col)), &address_buf) orelse break :row_address;
+ const address = got.address orelse {
+ word_from = got.word_from;
+ break :row_address;
};
- const line = (look.diffLines(p, pane) orelse break :diff)[at];
- result.text = p.scratch.allocator().dupe(u8, address) catch break :diff;
- const hi = std.math.cast(i32, line.len) orelse return result;
+ result.text = p.scratch.allocator().dupe(u8, address) catch break :row_address;
+ const hi = std.math.cast(i32, got.end) orelse return result;
if (hi == 0) return result;
var expanded = clicked;
if (pane.file != null) {
result.file_word = .{ .row = row, .lo = 0, .hi = hi };
expanded = fileWordCells(pane, clicked, row, 0, hi) orelse return result;
} else {
- const shown = if (raw) raw_line else line;
+ const shown = if (raw) raw_line else got.line;
expanded.c0 = 0;
expanded.c1 = @as(i32, @intCast(panes.File.rawDisplayCol(shown, shown.len))) - 1;
}
@@ -601,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:
@@ -624,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;
@@ -669,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);
}
@@ -710,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;
@@ -726,7 +723,7 @@ pub fn executeFrom(p: *Pardes, id: usize, txt: []const u8, from_body: bool) ?usi
/// is done, else a new one, placed as layout.placeNew places a command pane.
/// A pane reused keeps what it showed: the new command runs below a line
/// naming it, as acme appends to +Errors and never clears it (util.c:213).
-fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize {
+pub fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize {
if (line.len > command_max) {
p.reportFailure(from, "exec: a command line is at most 1024 bytes");
return null;
@@ -770,10 +767,10 @@ 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());
@@ -823,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
@@ -906,6 +903,7 @@ pub fn executeBuiltinLine(p: *Pardes, id: usize, txt: []const u8) bool {
}
pub fn applyStartupConfig(p: *Pardes) void {
+ @import("Plumb.zig").boot(p);
applyInitText(p, p.opts.startup_config orelse return, false);
}