summaryrefslogtreecommitdiff
path: root/src/body_layer.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 00:17:45 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commit5354090b6122faf0d18e246a55e8a4ead0955394 (patch)
treef27fc08bba1ceded6bf315125090ef0b64405463 /src/body_layer.zig
parentc742d19d4bacbd9a91627c4859ca8cb0d11bdba7 (diff)
downloadpardes-5354090b6122faf0d18e246a55e8a4ead0955394.tar.gz
pardes-5354090b6122faf0d18e246a55e8a4ead0955394.zip
Term: output and view through the interface: Term.feed takes one read and the rows the core keeps positions on and gives back a Term.Told (where each went, erased or not, cleared, alive, a pin missed), Term.grid is the plain record of the view and the cursor (total, offset, len, the cursor, whether it shows, the view's row or null while it follows), Term.scroll, Term.follow, Term.viewTo, Term.resize (now or for later) and Term.resizeDeferred move it, Term.cellPixels sizes its cells in pixels and Term.replies hands over what it answered its program; the core's half is the core's: Pane.feedOutput and its row tracking (the edit copy's rows, the cursors and selections, their undo and the pointer's rows, gathered as rows and moved as the feed told, ingestWithPositions's core) and Pane.followOutput, Pane.resizeGrid and Pane.panFor in panes.zig with panes.resizeDeferred, the cursor a program shows read from the grid where the body draws it, tape.viewOnly beside tape.authorityOnly; scrollbar, gridOffset, gridCursor, visibleCursor, viewOf, atBottom and their types go; nothing else changes
Diffstat (limited to 'src/body_layer.zig')
-rw-r--r--src/body_layer.zig25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/body_layer.zig b/src/body_layer.zig
index 76aec179..a8d09c66 100644
--- a/src/body_layer.zig
+++ b/src/body_layer.zig
@@ -37,7 +37,7 @@ fn paintTerminalSelection(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, rows: [
var visible: i32 = 0;
while (lines.next()) |line| : (visible += 1) {
if (visible >= r.h -| pane.tag_rows) break;
- const source_row = if (raw) panes.terminal.gridOffset(pane) + visible else pane.wrapAt(visible).line;
+ const source_row = if (raw) @as(i32, @intCast(panes.Term.grid(pane.terminal).offset)) + visible else pane.wrapAt(visible).line;
for (rows) |row| {
const target = if (row.raw_terminal)
(if (raw) row.row else pane.surfRow(row.row))
@@ -230,8 +230,7 @@ pub fn joinBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
fn drawGutter(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, tx: u16, tw: u16, body_h: u16, active: bool) void {
const prefix_width = panes.File.gutterWidth(pane);
const goff = pane.scroll();
- const gcur = panes.terminal.gridCursor(pane);
- const gcrow = if (pane.body.cur_pinned) pane.body.cur_row else @as(i32, gcur.y) + goff;
+ const gcrow = if (pane.body.cur_pinned) pane.body.cur_row else @as(i32, panes.Term.grid(pane.terminal).cursor_y) + goff;
const typing_body = pane.focus == .body and (pane.prompt == .none or pane.prompt == .del_side or pane.prompt == .repl_choice);
const cur_line: i32 = if (active and typing_body) gcrow else std.math.minInt(i32);
// the body's first row, the way renderPane derives it
@@ -491,10 +490,9 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane
// (the tag's or a prompt's cursor wins while that is being typed into)
if (active and pane.focus == .body and (pane.prompt == .none or pane.prompt == .del_side or pane.prompt == .repl_choice)) {
if (pane.body.mode != .tty) {
- const cur = panes.terminal.gridCursor(pane);
- const goff = panes.terminal.gridOffset(pane);
- const crow = if (pane.body.cur_pinned) pane.body.cur_row else pane.surfRow(@as(i32, @intCast(cur.y)) + goff);
- const ccol = if (pane.body.cur_pinned) pane.body.cur_col else @as(i32, @intCast(cur.x));
+ const grid = panes.Term.grid(pane.terminal);
+ const crow = if (pane.body.cur_pinned) pane.body.cur_row else pane.surfRow(@as(i32, grid.cursor_y) + @as(i32, @intCast(grid.offset)));
+ const ccol = if (pane.body.cur_pinned) pane.body.cur_col else @as(i32, grid.cursor_x);
const cwp = pane.wrapRow(crow, ccol);
const prow = cwp.row + @as(i32, pane.tag_rows);
// Off the view, the cursor is not measured (its column may be
@@ -515,9 +513,16 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane
if (prow >= pane.tag_rows and cx >= 0 and prow < body_bottom and cx < tw)
s.cursor = .{ .x = tx + @as(u16, @intCast(cx)), .y = body_y + @as(u16, @intCast(prow - pane.tag_rows)), .bar = pane.body.mode == .insert };
}
- } else if (panes.terminal.visibleCursor(pane)) |cur| {
- if (cur.y + pane.tag_rows < body_bottom and cur.x < tw)
- s.cursor = .{ .x = tx + cur.x, .y = body_y + cur.y };
+ } else if (pane.terminal != null) visible: {
+ // Where the program shows its cursor, if it does and in the rows
+ // the view shows (past the rows a short view pans over).
+ const grid = panes.Term.grid(pane.terminal);
+ if (!grid.cursor_visible) break :visible;
+ const row = grid.total - grid.len + grid.cursor_y;
+ if (row < grid.offset + pane.pan or row - grid.offset >= grid.len) break :visible;
+ const y: u16 = @intCast(row - grid.offset - pane.pan);
+ if (y + pane.tag_rows < body_bottom and grid.cursor_x < tw)
+ s.cursor = .{ .x = tx + grid.cursor_x, .y = body_y + y };
}
}