diff options
Diffstat (limited to 'src/exec.zig')
| -rw-r--r-- | src/exec.zig | 71 |
1 files changed, 37 insertions, 34 deletions
diff --git a/src/exec.zig b/src/exec.zig index 327d4683..c927cb49 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -44,6 +44,7 @@ pub fn takesCommandLine(p: *const Pardes, id: usize) bool { } pub fn chordEachSel(p: *Pardes, pane: *Pane, cmd: Builtin) bool { + const v = p.view(); if (pane.body.nsel == 0) return false; const text = edit.flatSurface(p, &pane.body) catch return false; var ranges: [panes.Text.max_selections]modal.Selection = undefined; @@ -63,7 +64,7 @@ pub fn chordEachSel(p: *Pardes, pane: *Pane, cmd: Builtin) bool { // All or nothing, like the pipe: half a chord is not a chord. if (made != got.n) return false; - const id = p.active; + const id = v.active; const serial = pane.serial; pane.body.vsel.active = false; pane.body.select = false; @@ -73,12 +74,12 @@ pub fn chordEachSel(p: *Pardes, pane: *Pane, cmd: Builtin) bool { for (texts[0..made], 0..) |txt, i| { // Every selection is the body's, each one sent as the first is. runBuiltinFrom(p, cmd, id, "", txt, true); - if (i == got.pri) primary_active = p.active; + if (i == got.pri) primary_active = v.active; const still = p.panes[id] orelse break; if (still.serial != serial) break; } if (primary_active) |a| if (p.panes[a] != null) { - p.active = a; + v.active = a; }; return true; } @@ -259,17 +260,17 @@ fn fileWordCells(pane: *Pane, clicked: Pane.Sel, row: i32, lo: i32, hi: i32) ?Pa fn heldPane(p: *Pardes, first: usize, k: usize) ?*Pane { const i = switch (k) { 0 => first, - 1 => p.active, + 1 => p.view().active, else => k - 2, }; - if (k > 0 and (i == first or (k > 1 and i == p.active))) return null; + if (k > 0 and (i == first or (k > 1 and i == p.view().active))) return null; return p.panes[i]; } pub fn heldSelection(p: *Pardes, first: usize) ?[]const u8 { for (0..p.panes.len + 2) |k| { const t = heldPane(p, first, k) orelse continue; - if (comptime pdf_enabled) if (p.frontend.native_images) if (t.pdf) |pv| { + if (comptime pdf_enabled) if (p.view().frontend.native_images) if (t.pdf) |pv| { if (pv.selection != null and pv.selection_text.len > 0) return pv.selection_text; }; @@ -535,7 +536,7 @@ fn routeToRepl(p: *Pardes, from: usize, text: []const u8) Routed { w.writeAll(" (Esc: none)") catch {}; src.question_len = @intCast(w.buffered().len); src.prompt = .repl_choice; - p.active = from; + p.view().active = from; var rec: [96]u8 = undefined; var rw = std.Io.Writer.fixed(&rec); rw.print("{d} repl", .{src.serial}) catch {}; @@ -960,7 +961,7 @@ fn applyInitText(p: *Pardes, text: []const u8, settings_only: bool) void { // the other has (Font, GripWidth in a terminal) is no failure here. if (setting) |s| if (!s.enabled(builtins.viewCapabilities(p))) continue; const failures = p.fs.failures; - const known = executeBuiltinLine(p, p.active, line); + const known = executeBuiltinLine(p, p.view().active, line); if (known and p.fs.failures == failures) continue; // Never silent: a word it has not, or one that failed, is a notice // on the message row and an err in the log, with its line. @@ -970,7 +971,7 @@ fn applyInitText(p: *Pardes, text: []const u8, settings_only: bool) void { else if (p.fs.said_len > 0) p.fs.said[0..p.fs.said_len] else "failed"; var said: [400]u8 = undefined; const line_said = std.fmt.bufPrint(&said, "init file line {d}: {s}", .{ number, why }) catch "init file: a line failed"; - if (!known) p.reportFailure(p.active, line_said); + if (!known) p.reportFailure(p.view().active, line_said); pardes.ctlfs.events.notePath(p, "err -", line_said); } } @@ -1012,6 +1013,7 @@ pub fn runBuiltinFrom(p: *Pardes, b: Builtin, id: usize, txt: []const u8, arg: ? } pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[]const u8) void { + const v = p.view(); const previous_tagline_percent = p.settings.font.tagline_percent; switch (setting.action) { .theme => { @@ -1025,7 +1027,7 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[] const room = 128 -| ("Theme: no theme \"\"; like it: ; Themes lists all".len + shown.len); var near: [128]u8 = undefined; var text: [256]u8 = undefined; - return p.reportFailure(p.active, std.fmt.bufPrint(&text, "Theme: no theme \"{s}\"; like it: {s}; Themes lists all", .{ shown, colors.themesNear(near[0..@min(room, near.len)], want) }) catch "Theme: no such theme"); + return p.reportFailure(v.active, std.fmt.bufPrint(&text, "Theme: no theme \"{s}\"; like it: {s}; Themes lists all", .{ shown, colors.themesNear(near[0..@min(room, near.len)], want) }) catch "Theme: no such theme"); }, .font => { if (comptime !font_picker) return; @@ -1044,22 +1046,22 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[] p.settings.shell.pending = true; if (!p.announce) return; var said: [320]u8 = undefined; - return p.setMessage(p.active, std.fmt.bufPrint(&said, "Shell: the default again, {s} ($SHELL, else /bin/sh)", .{config.defaultShell()}) catch "Shell: the default again"); + return p.setMessage(v.active, std.fmt.bufPrint(&said, "Shell: the default again, {s} ($SHELL, else /bin/sh)", .{config.defaultShell()}) catch "Shell: the default again"); } var why: [320]u8 = undefined; if (pardes.tape.value(.shell, @import("host_io.zig").Shell.refusal, .{ want[0..@min(want.len, 200)], &why })) |refused| { var text: [340]u8 = undefined; - return p.reportFailure(p.active, std.fmt.bufPrint(&text, "Shell: {s}", .{refused}) catch "Shell: no such shell"); + return p.reportFailure(v.active, std.fmt.bufPrint(&text, "Shell: {s}", .{refused}) catch "Shell: no such shell"); } - if (!p.settings.apply(setting, want)) p.reportFailure(p.active, "Shell: takes " ++ comptime config.Runtime.takes(.shell).?); + if (!p.settings.apply(setting, want)) p.reportFailure(v.active, "Shell: takes " ++ comptime config.Runtime.takes(.shell).?); }, // Bare, each says its value, as acme's Tab says the width. inline .tab, .callstack_depth => |_, tag| if (arg == null) { var said: [40]u8 = undefined; - return p.setMessage(p.active, std.fmt.bufPrint(&said, "{s} {d}", .{ setting.word, @field(p.settings, @tagName(tag)) }) catch setting.word); + return p.setMessage(v.active, std.fmt.bufPrint(&said, "{s} {d}", .{ setting.word, @field(p.settings, @tagName(tag)) }) catch setting.word); } else if (!p.settings.apply(setting, arg)) { var said: [96]u8 = undefined; - p.reportFailure(p.active, std.fmt.bufPrint(&said, "{s}{s}: takes {s}", .{ setting.word, if (tag == .tab) ": invalid tab width" else "", comptime config.Runtime.takes(tag).? }) catch setting.word); + p.reportFailure(v.active, std.fmt.bufPrint(&said, "{s}{s}: takes {s}", .{ setting.word, if (tag == .tab) ": invalid tab width" else "", comptime config.Runtime.takes(tag).? }) catch setting.word); } else if (tag == .tab) { config.tab_now = p.settings.tab; }, @@ -1067,7 +1069,7 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[] else => if (!p.settings.apply(setting, arg)) { var text: [160]u8 = undefined; const why = if (config.Runtime.takes(setting.action)) |values| std.fmt.bufPrint(&text, "{s}: takes {s}", .{ setting.word, values }) else std.fmt.bufPrint(&text, "{s}: does not take that value", .{setting.word}); - p.reportFailure(p.active, why catch "does not take that value"); + p.reportFailure(v.active, why catch "does not take that value"); }, } if (setting.action == .tab) { @@ -1092,12 +1094,13 @@ pub const NewPane = enum { scratch, fs, shell, doc, command, errors }; /// from: null when a column tag, the workspace tag or 9P asked (acme's /// t->w == nil). pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPane) void { + const v = p.view(); // No column left (the last one Delcol'd): a pane made from the workspace // tag opens one to go in. _ = layout.firstColumn(p); const asked = if (p.exec_column != null) null else origin; layout.compute(p); - const before = p.rects; + const before = v.rects; const before_min = layout.minima(p); switch (kind) { // New: the bottom half of the last pane in its own column @@ -1105,8 +1108,8 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan .scratch => layout.acmePlace(p, p.exec_column orelse columnOf(p, from), null, id), // +Errors, a command's output: the last column (util.c:94-98); a // command run from a column's tag, that column. - .command => layout.acmePlace(p, p.exec_column orelse p.ncol - 1, null, id), - .errors => layout.acmePlace(p, p.ncol - 1, null, id), + .command => layout.acmePlace(p, p.exec_column orelse v.ncol - 1, null, id), + .errors => layout.acmePlace(p, v.ncol - 1, null, id), // makenewwindow(nil) for 9P's new (acme.c:877), else (t). .fs => layout.acmePlace(p, acmeColumn(p, from), null, id), .shell, .doc => layout.acmePlace(p, acmeColumn(p, from), asked, id), @@ -1117,12 +1120,12 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan // (Pardes.unplaced) once whatever made it is done with it. if (!layout.placedRoomy(p, id, &before)) if (layout.findPane(p, id)) |f| { layout.removePane(p, id); - for (p.cols[f.col].panes[0..p.cols[f.col].n]) |k| p.rects[k] = before[k]; + for (v.cols[f.col].panes[0..p.view().cols[f.col].n]) |k| v.rects[k] = before[k]; layout.snapColWeights(p, f.col); if (!layout.splitTallest(p, f.col, id) or !layout.placedRoomy(p, id, &before)) { if (layout.findPane(p, id) != null) { layout.removePane(p, id); - for (p.cols[f.col].panes[0..p.cols[f.col].n]) |k| p.rects[k] = before[k]; + for (v.cols[f.col].panes[0..p.view().cols[f.col].n]) |k| v.rects[k] = before[k]; layout.snapColWeights(p, f.col); } // No pane to halve, but the column has the rows for the new @@ -1136,20 +1139,20 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan // the text some other way (appendErrors), and pane/new is // refused. if (layout.takeRoom(p, f.col, id)) {} else if (kind == .errors or kind == .fs) { - var c = p.ncol; + var c = v.ncol; while (c > 0) { c -= 1; if (c == f.col) continue; - for (p.cols[c].panes[0..p.cols[c].n]) |k| p.rects[k] = before[k]; + for (v.cols[c].panes[0..p.view().cols[c].n]) |k| v.rects[k] = before[k]; layout.snapColWeights(p, c); - if (p.cols[c].n == 0) { + if (v.cols[c].n == 0) { layout.insert(p, c, 0, id); break; } if (layout.splitTallest(p, c, id) and layout.placedRoomy(p, id, &before)) break; if (layout.findPane(p, id) != null) layout.removePane(p, id); } else { - layout.insert(p, f.col, p.cols[f.col].n, id); + layout.insert(p, f.col, v.cols[f.col].n, id); p.unplaced.set(id); // Refused holding no weight: its column's rows come // back as they were. @@ -1159,7 +1162,7 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan return; } } else { - layout.insert(p, f.col, p.cols[f.col].n, id); + layout.insert(p, f.col, v.cols[f.col].n, id); // Refused, it closes at the step's end holding no weight, so // its column's rows come back as they were, none rounded off. p.panes[id].?.vweight = 0; @@ -1179,7 +1182,7 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan layout.restoreMinimaFrom(p, &settled, &before_min); if (kind == .command) return; tagline.exitHeader(p); - p.active = id; + v.active = id; if (layout.findPane(p, id)) |f| p.setActiveColumn(f.col); } @@ -1189,12 +1192,12 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan fn acmeColumn(p: *Pardes, from: usize) usize { if (p.exec_column) |c| return c; if (layout.activeColumn(p)) |c| return c; - if (layout.findPane(p, p.active)) |f| return f.col; + if (layout.findPane(p, p.view().active)) |f| return f.col; return columnOf(p, from); } fn columnOf(p: *Pardes, id: usize) usize { - return if (layout.findPane(p, id)) |f| f.col else p.ncol - 1; + return if (layout.findPane(p, id)) |f| f.col else p.view().ncol - 1; } test "the acme chords act once per selection, not once on the primary" { @@ -1212,11 +1215,11 @@ test "the acme chords act once per selection, not once on the primary" { pane.body.setRanges(pane.file.?.content, &ranges, &.{}, 0, true); try std.testing.expectEqual(@as(u16, 1), pane.body.nsel); - const before = p.ncol; + const before = p.view().ncol; p.update(.{ .key = .{ .cp = Key.tab } }); // config.exec_key: Exec // BOTH ran. Before this the chord read the primary range and dropped the // other cursor, so one keystroke over two cursors made one column. - try std.testing.expectEqual(before + 2, p.ncol); + try std.testing.expectEqual(before + 2, p.view().ncol); // ...and the chord consumed the selection exactly as it does with one. try std.testing.expectEqual(@as(u16, 0), p.panes[0].?.body.nsel); } @@ -1226,11 +1229,11 @@ test "a switch clicked with a selection held flips unless the selection says on defer p.deinit(); while (p.nextEffect()) |_| {} const before = p.settings.verbose; - _ = execute(p, p.active, withArg(p, "Verbose", "some selected text")); + _ = execute(p, p.view().active, withArg(p, "Verbose", "some selected text")); try std.testing.expectEqual(!before, p.settings.verbose); - _ = execute(p, p.active, withArg(p, "Verbose", "on")); + _ = execute(p, p.view().active, withArg(p, "Verbose", "on")); try std.testing.expect(p.settings.verbose); - _ = execute(p, p.active, withArg(p, "Verbose", " off\n")); + _ = execute(p, p.view().active, withArg(p, "Verbose", " off\n")); try std.testing.expect(!p.settings.verbose); // A word that takes any argument still gets the selection. try std.testing.expectEqualStrings("Msg some text", withArg(p, "Msg", "some text")); |
