summaryrefslogtreecommitdiff
path: root/src/mouse.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/mouse.zig')
-rw-r--r--src/mouse.zig70
1 files changed, 37 insertions, 33 deletions
diff --git a/src/mouse.zig b/src/mouse.zig
index 2ca984ba..4eb18141 100644
--- a/src/mouse.zig
+++ b/src/mouse.zig
@@ -91,7 +91,7 @@ fn headerSweepRun(p: *Pardes, sweep: HeaderSweep) void {
const v = p.view();
const column = sweep.column(p) catch return; // error.Gone: its column closed under the sweep
const t = if (column) |c| &v.col_tags[c] else &p.global_tag;
- const text = edit.flatSurface(p, t) catch |err| return p.reportError(v.active, "edit", err);
+ const text = edit.flatSurface(p.editor(), t) catch |err| return p.reportError(v.active, "edit", err);
const swept = sweep.span(text.len);
const selected = if (swept.lo < swept.hi) text[swept.lo..swept.hi] else click: {
const line = std.mem.count(u8, text[0..swept.lo], "\n");
@@ -164,7 +164,7 @@ pub fn sameBodyCell(a: ?Mouse.BodyHit, b: ?Mouse.BodyHit) bool {
return first.serial == second.serial and first.row == second.row and first.col == second.col;
}
-/// A wheel over a terminal whose program owns it (`terminal.ownsWheel`:
+/// A wheel over a terminal whose program owns it (`Term.Modes.wheel`:
/// codex, htop, less) goes to the program as the program asked, one turn
/// per line, instead of scrolling a scrollback the alternate screen does
/// not have. Shift keeps it pardes's, as xterm's Shift does. False when
@@ -172,19 +172,19 @@ pub fn sameBodyCell(a: ?Mouse.BodyHit, b: ?Mouse.BodyHit) bool {
fn programWheel(p: *Pardes, id: usize, m: Mouse, col: u16, row: u16) bool {
if (m.shift) return false;
const pane = p.panes[id] orelse return false;
- if (!pane.isTerminal() or !panes.terminal.ownsWheel(pane)) return false;
+ if (!pane.isTerminal() or !panes.Term.modes(pane.terminal).wheel) return false;
const r = p.view().rects[id];
const body_y = p.bodyTop(pane, r);
const gcol = std.math.clamp(col -| (r.x + config.GUTTER), 0, pane.cols -| 1);
const grow = std.math.clamp(row -| body_y, 0, pane.rows -| 1);
var buf: [64]u8 = undefined;
- const wheel: panes.terminal.MouseButton = switch (m.button) {
+ const wheel: panes.Term.MouseButton = switch (m.button) {
.wheel_up => .wheel_up,
.wheel_down => .wheel_down,
.wheel_left => .wheel_left,
else => .wheel_right,
};
- const bytes = panes.terminal.wheelBytes(pane, &buf, wheel, gcol, grow, .{ .alt = m.alt, .ctrl = m.ctrl }) orelse return true;
+ const bytes = panes.Term.wheel(pane.terminal.?, &buf, wheel, gcol, grow, .{ .alt = m.alt, .ctrl = m.ctrl }) orelse return true;
for (0..@intCast(config.wheel_rows)) |_| p.emitWrite(id, bytes);
return true;
}
@@ -214,7 +214,7 @@ fn programCell(p: *const Pardes, id: usize, col: u16, row: u16) ?struct { col: i
/// A pane whose program tracks the mouse (1000, 1002, 1003, or X10's 9)
/// and has the keyboard's raw input: its clicks are the program's.
fn tracksMouse(pane: *const Pane) bool {
- return pane.isTerminal() and pane.body.mode == .tty and panes.terminal.reportsMouse(pane);
+ return pane.isTerminal() and pane.body.mode == .tty and panes.Term.modes(pane.terminal).mouse;
}
/// A program that tracks the mouse gets it over its grid, as xterm gives
@@ -265,7 +265,7 @@ pub fn kindLeave(p: *Pardes) void {
fn programMouse(p: *Pardes, m: Mouse) bool {
const v = p.view();
- const button: ?panes.terminal.MouseButton = switch (m.button) {
+ const button: ?panes.Term.MouseButton = switch (m.button) {
.left => .left,
.middle => .middle,
.right => .right,
@@ -274,7 +274,7 @@ fn programMouse(p: *Pardes, m: Mouse) bool {
};
const bit: u3 = if (button) |b| @as(u3, 1) << @intCast(@backingInt(b)) else 0;
const at: struct { col: u16, row: u16 } = .{ .col = @min(m.col, v.screen_w -| 1), .row = @min(m.row, v.screen_h -| 1) };
- var mods: panes.terminal.MouseMods = .{ .shift = m.shift, .alt = m.alt, .ctrl = m.ctrl };
+ var mods: panes.Term.MouseMods = .{ .shift = m.shift, .alt = m.alt, .ctrl = m.ctrl };
var buf: [64]u8 = undefined;
if (v.mouse_grab) |*grab| {
if (grab.unshift) mods.shift = false;
@@ -291,14 +291,14 @@ fn programMouse(p: *Pardes, m: Mouse) bool {
const r = v.rects[grab.id];
const col: i32 = @as(i32, at.col) - @as(i32, r.x + config.GUTTER);
const row: i32 = @as(i32, at.row) - @as(i32, p.bodyTop(pane, r));
- const action: panes.terminal.MouseAction = switch (m.kind) {
+ const action: panes.Term.MouseAction = switch (m.kind) {
.press => .press,
.release => .release,
.drag, .motion => .motion,
};
if (m.kind == .press) grab.held |= bit;
if (m.kind == .release) grab.held &= ~bit;
- const bytes = panes.terminal.mouseBytes(pane, &buf, action, button, mods, col, row, grab.held != 0);
+ const bytes = panes.Term.mouse(pane.terminal.?, &buf, action, button, mods, col, row, grab.held != 0);
if (bytes.len > 0) p.emitWrite(grab.id, bytes);
if (grab.held == 0) v.mouse_grab = null;
return true;
@@ -322,7 +322,7 @@ fn programMouse(p: *Pardes, m: Mouse) bool {
pane.focus = .body;
pane.closePrompt();
v.mouse_grab = .{ .id = id, .serial = pane.serial, .held = bit, .unshift = shifted_to_program };
- const bytes = panes.terminal.mouseBytes(pane, &buf, .press, button, mods, cell.col, cell.row, true);
+ const bytes = panes.Term.mouse(pane.terminal.?, &buf, .press, button, mods, cell.col, cell.row, true);
if (bytes.len > 0) p.emitWrite(id, bytes);
return true;
},
@@ -330,11 +330,11 @@ fn programMouse(p: *Pardes, m: Mouse) bool {
// pardes's.
.release, .drag => return false,
.motion => {
- const bytes = panes.terminal.mouseBytes(pane, &buf, .motion, null, mods, cell.col, cell.row, false);
+ const bytes = panes.Term.mouse(pane.terminal.?, &buf, .motion, null, mods, cell.col, cell.row, false);
if (bytes.len > 0) p.emitWrite(id, bytes);
// Under 1003 the move is the program's; below that pardes
// hovers as ever.
- return panes.terminal.tracksAllMotion(pane);
+ return panes.Term.modes(pane.terminal).all_motion;
},
}
}
@@ -364,7 +364,7 @@ fn headerPoint(p: *Pardes, column: ?usize, mcol: u16, mrow: u16, clamp: bool) ?s
const t = if (column) |c| &v.col_tags[c] else &p.global_tag;
const x = if (column) |c| v.col_x[c] + TAG_TEXT_INSET else TAG_TEXT_INSET;
const focused = v.header != null and p.headerColumn() == column;
- const text = edit.flatSurface(p, t) catch return null;
+ const text = edit.flatSurface(p.editor(), t) catch return null;
const base = if (column != null) p.topBarHeight() else 0;
const rows = if (column != null) layout.columnBarHeight(p) else p.topBarHeight();
const row: u16 = if (clamp) @min(mrow -| base, rows -| 1) else mrow -| base;
@@ -412,10 +412,10 @@ fn chordCutPaste(p: *Pardes, cut: bool) edit.Error!void {
t.nsel = 0;
}
if (cut) {
- if (t.vsel.active) try edit.normalDelete(p, t, true);
+ if (t.vsel.active) try edit.normalDelete(p.editor(), t, true);
} else if (t.vsel.active) {
- try edit.chordReplace(p, t);
- } else try edit.pasteText(p, t, p.registers.text(p.gpa, pardes.Registers.default) orelse return, true, 1);
+ try edit.chordReplace(p.editor(), t);
+ } else try edit.pasteText(p.editor(), t, p.registers.text(p.gpa, pardes.Registers.default) orelse return, true, 1);
return;
}
if (pane.body.mode == .tty) {
@@ -426,13 +426,13 @@ fn chordCutPaste(p: *Pardes, cut: bool) edit.Error!void {
if (cut) return;
const y = p.registers.text(p.gpa, pardes.Registers.default) orelse return;
if (y.len == 0) return;
- if (panes.terminal.reportsMouse(pane)) {
+ if (panes.Term.modes(pane.terminal).mouse) {
// A click where the text goes, so the program's cursor is there.
const col = @max(0, pane.sel[sel_slot].c1);
const row = @max(0, pane.sel[sel_slot].r1 - @as(i32, pane.tag_rows));
var mb: [64]u8 = undefined;
- for ([_]panes.terminal.MouseAction{ .press, .release }) |action| {
- const bytes = panes.terminal.mouseBytes(pane, &mb, action, .left, .{}, col, row, action == .press);
+ for ([_]panes.Term.MouseAction{ .press, .release }) |action| {
+ const bytes = panes.Term.mouse(pane.terminal.?, &mb, action, .left, .{}, col, row, action == .press);
if (bytes.len > 0) p.emitWrite(s.id, bytes);
}
}
@@ -444,7 +444,7 @@ fn chordCutPaste(p: *Pardes, cut: bool) edit.Error!void {
// Everything done while B1 stays down is one undo step, as acme
// marks the file once per B1 hold (text.c:881 textselect, `state`
// and its one filemark): B1-B2 then B1-B3 is a copy.
- try edit.pushUndo(p, &pane.body);
+ try edit.pushUndo(p.editor(), &pane.body);
p.view().chord_hold = true;
const sl = pane.sel[sel_slot];
pane.sel[sel_slot].state = .none;
@@ -455,8 +455,8 @@ fn chordCutPaste(p: *Pardes, cut: bool) edit.Error!void {
const w1 = pane.wrapAt(@max(0, sl.r1 - @as(i32, pane.tag_rows)));
const row0 = w0.line;
const row1 = w1.line;
- const col0 = edit.paneByteAtDisplay(p, &pane.body, w0.line, w0.at, sl.c0 - pfx - w0.pad);
- const col1 = edit.paneByteAtDisplay(p, &pane.body, w1.line, w1.at, sl.c1 - pfx - w1.pad);
+ const col0 = edit.paneByteAtDisplay(p.editor(), &pane.body, w0.line, w0.at, sl.c0 - pfx - w0.pad);
+ const col1 = edit.paneByteAtDisplay(p.editor(), &pane.body, w1.line, w1.at, sl.c1 - pfx - w1.pad);
pane.body.cur_row = row1;
pane.body.cur_col = col1;
pane.body.cur_pinned = true;
@@ -466,16 +466,16 @@ fn chordCutPaste(p: *Pardes, cut: bool) edit.Error!void {
pane.body.nsel = 0;
}
if (cut) {
- if (pane.body.vsel.active) try edit.normalDelete(p, &pane.body, true);
+ if (pane.body.vsel.active) try edit.normalDelete(p.editor(), &pane.body, true);
} else if (pane.body.vsel.active) {
- try edit.chordReplace(p, &pane.body);
+ try edit.chordReplace(p.editor(), &pane.body);
} else if (pane.file) |*f| {
// bare cursor: splice the register in literally (no linewise
// magic) so a paste right after a cut restores the text exactly
const y = p.registers.text(p.gpa, pardes.Registers.default) orelse return;
if (y.len == 0) return;
const at = modal.Cursor{ .row = @intCast(@max(0, pane.body.cur_row)), .col = @intCast(@max(0, pane.body.cur_col)) };
- try edit.pushUndo(p, &pane.body);
+ try edit.pushUndo(p.editor(), &pane.body);
const new = try modal.insertAt(p.gpa, f.content, at, y);
panes.File.setContent(p, f, new);
pane.body.vsel = .{ .active = modal.nextGrapheme(y, 0) < y.len, .row = @intCast(at.row), .col = @intCast(at.col), .explicit = false };
@@ -491,7 +491,7 @@ fn chordCutPaste(p: *Pardes, cut: bool) edit.Error!void {
pane.body.cur_pinned = true;
pane.body.sticky_col = -1;
pane.ensureCursorVisible();
- } else try edit.pasteText(p, &pane.body, p.registers.text(p.gpa, pardes.Registers.default) orelse return, true, 1);
+ } else try edit.pasteText(p.editor(), &pane.body, p.registers.text(p.gpa, pardes.Registers.default) orelse return, true, 1);
}
pub fn handleMouse(p: *Pardes, event: Mouse) void {
@@ -1042,7 +1042,7 @@ fn gestureRange(p: *Pardes, id: usize, text: []const u8, on_tag: bool, operand:
const top = lead[0] - @as(i32, pane.tag_rows);
if (top < 0) break :lead null;
const w = pane.wrapAt(top);
- const col = edit.paneByteAtDisplay(p, &pane.body, w.line, w.at, lead[1] - panes.File.gutterWidth(pane) - w.pad);
+ const col = edit.paneByteAtDisplay(p.editor(), &pane.body, w.line, w.at, lead[1] - panes.File.gutterWidth(pane) - w.pad);
break :lead .{
.row = @intCast(@max(0, w.line)),
.col = @intCast(@max(0, col)),
@@ -1090,7 +1090,7 @@ fn mirrorTtySelection(p: *Pardes, pane: *Pane) void {
const forward = gesture.r1 > gesture.r0 or (gesture.r1 == gesture.r0 and gesture.c1 >= gesture.c0);
const endpoint = rows[if (forward) rows.len - 1 else 0];
const body = body_layer.bodyText(p.scratch.allocator(), pane) catch |err| return p.reportError(p.view().active, "select", err);
- const line = modal.lineSlice(body, @intCast(@max(0, endpoint.row - panes.terminal.gridOffset(pane))));
+ const line = modal.lineSlice(body, @intCast(@max(0, endpoint.row - @as(i32, @intCast(panes.Term.grid(pane.terminal).offset)))));
const byte = if (forward) modal.prevGrapheme(line, @min(endpoint.hi, line.len)) else endpoint.lo;
pane.body.cur_row = pane.surfRow(endpoint.row);
var shown = std.mem.trimEnd(u8, line[@min(endpoint.prompt_bytes, line.len)..], " \t");
@@ -1107,7 +1107,7 @@ fn mirrorTtySelection(p: *Pardes, pane: *Pane) void {
pane.body.restore_cursor = false;
pane.body.sticky_col = -1;
pane.body.normal.clear();
- edit.setYank(p, text) catch |err| p.reportError(p.view().active, "yank", err);
+ edit.setYank(p.editor(), text) catch |err| p.reportError(p.view().active, "yank", err);
}
/// acme's double-click (text.c:881 textselect, plan9port text.c:1407
@@ -1124,7 +1124,7 @@ fn doubleClick(p: *Pardes, id: usize, t: *panes.Text, on_tag: bool, row: i32, co
const c = prev orelse return;
if (c.id != id or c.on_tag != on_tag or c.row != row or c.col != col or now - c.ms > 500) return;
v.last_click = null;
- const text = edit.flatSurface(p, t) catch |err| return p.reportError(v.active, "edit", err);
+ const text = edit.flatSurface(p.editor(), t) catch |err| return p.reportError(v.active, "edit", err);
const q = modal.offsetAt(text, .{ .row = @intCast(@max(0, t.cur_row)), .col = @intCast(@max(0, t.cur_col)) });
const r = edit.doubleClickRange(text, q);
if (r[1] <= r[0]) return;
@@ -1160,7 +1160,7 @@ fn sweepPoint(p: *Pardes, pane: *panes.Pane, r: i32, c: i32) ?modal.Cursor {
if (visible < 0) return null;
const w = pane.wrapAt(visible);
if (w.line < 0) return null;
- const col = edit.paneByteAtDisplay(p, &pane.body, w.line, w.at, c - w.pad - (if (pane.file != null) @as(i32, panes.File.gutterWidth(pane)) else 0));
+ const col = edit.paneByteAtDisplay(p.editor(), &pane.body, w.line, w.at, c - w.pad - (if (pane.file != null) @as(i32, panes.File.gutterWidth(pane)) else 0));
return .{ .row = @intCast(w.line), .col = @intCast(@max(0, col)) };
}
@@ -1220,7 +1220,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void {
const w = pane.wrapAt(body_vis);
pane.body.cur_row = w.line;
pane.body.cur_col = edit.paneByteAtDisplay(
- p,
+ p.editor(),
&pane.body,
w.line,
w.at,
@@ -1384,6 +1384,7 @@ fn layerCenter(layer: *const Layer, col: u16, comptime tag: bool) [2]f32 {
}
test "a pane's last row of text is no resize handle; the rule over the next pane is" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // the classic boot's three shells
const p = try twoColumns(std.testing.allocator);
defer p.deinit();
const seam = seamRowOf(p, 1, 0);
@@ -1409,6 +1410,7 @@ test "the line between two columns is no resize handle: a press there is a sweep
}
test "a pane's grip dragged up or down its own column moves its top, down to the floor of the pane above" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
const p = try twoColumns(std.testing.allocator);
defer p.deinit();
const upper = p.view().cols[1].panes[0];
@@ -1542,6 +1544,7 @@ test "a chorded exec an event reader holds is told with its argument, and writte
}
test "a wheel over a program that owns it is the program's, in the form it asked for; a shell's scrolls" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
const gpa = std.testing.allocator;
const p = try Pardes.init(gpa, .{ .cols = 60, .rows = 16, .tty_only = true });
defer p.deinit();
@@ -1637,6 +1640,7 @@ test "Alt-click is B2 and Super-click B3, kept from the press through the releas
}
test "a program tracking the mouse gets its clicks, drags and moves over its grid as xterm reports them; Shift and chrome stay pardes's" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
const gpa = std.testing.allocator;
const p = try Pardes.init(gpa, .{ .cols = 60, .rows = 16, .tty_only = true });
defer p.deinit();