diff options
Diffstat (limited to 'src/builtins.zig')
| -rw-r--r-- | src/builtins.zig | 92 |
1 files changed, 36 insertions, 56 deletions
diff --git a/src/builtins.zig b/src/builtins.zig index 55253f02..777ad989 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -557,6 +557,10 @@ pub const Exec = struct { // ---- session ---- +/// Which panes a refusal asks about: every one (Exit, Restore), one (Del), +/// or a column's (Delcol). +pub const Asked = union(enum) { all, pane: usize, column: usize }; + /// acme's rowclean (editors/acme/wind.c:511-529, winclean), asked before /// what would throw unsaved text away: each pane holding some nobody has /// been told about is listed in +Unsaved, `<name>: Modified`, under it @@ -568,14 +572,6 @@ pub const Exec = struct { /// Restore a script was refused does not spend the warning an Exit owes /// the person at the keyboard. A scratch of under 100 bytes is no loss /// worth the question, as winclean does not ask for one. -fn warnModified(c: Ctx, asking: Pane.Discarding) bool { - return warnModifiedIn(c, asking, .all); -} - -/// Which panes a refusal asks about: every one (Exit, Restore), one (Del), -/// or a column's (Delcol). -pub const Asked = union(enum) { all, pane: usize, column: usize }; - pub fn warnModifiedIn(c: Ctx, asking: Pane.Discarding, which: Asked) bool { // Every pane asked about is an `unsaved <serial> <name>` record, as // acme's rowclean names them all (wind.c:511); the refusal a write @@ -666,7 +662,7 @@ pub fn warnModifiedIn(c: Ctx, asking: Pane.Discarding, which: Asked) bool { pub const Exit = struct { pub const scope: Scope = .session; pub fn run(c: Ctx) void { - if (warnModified(c, .Exit)) return; + if (warnModifiedIn(c, .Exit, .all)) return; c.p.quit = true; c.p.emit(.quit); } @@ -689,34 +685,28 @@ pub const Kill = struct { var running = false; for (c.p.panes, 0..) |slot, id| { const pane = slot orelse continue; - // A command pane's child is the command: the whole of its - // process group goes, as acme's Kill ends the process. - if (pane.command) |line| if (!pane.command_done) { - running = true; - const said = std.mem.trim(u8, line, " \t"); - const first = said[0 .. std.mem.indexOfAny(u8, said, " \t") orelse said.len]; - if (names.len > 0) { - var words = std.mem.tokenizeAny(u8, names, " \t"); - while (words.next()) |w| { - if (std.mem.eql(u8, w, first)) break; - } else continue; - } - c.p.emit(.{ .signal_pty = .{ .pane = @intCast(id), .serial = pane.serial, .sig = .term } }); - stopped = true; - continue; - }; - if (!panes.terminal.commandRunning(pane)) continue; + const command: ?[]const u8 = if (pane.command) |line| (if (pane.command_done) null else line) else null; + if (command == null and !panes.terminal.commandRunning(pane)) continue; running = true; - const sent = pane.sent_command.?; + const first = if (command) |line| first: { + const said = std.mem.trim(u8, line, " \t"); + break :first said[0 .. std.mem.indexOfAny(u8, said, " \t") orelse said.len]; + } else pane.sent_command.?.word[0..pane.sent_command.?.len]; if (names.len > 0) { var words = std.mem.tokenizeAny(u8, names, " \t"); while (words.next()) |w| { - if (std.mem.eql(u8, w, sent.word[0..sent.len])) break; + if (std.mem.eql(u8, w, first)) break; } else continue; } - // Asked of the host now, not queued: the job the marks say is - // running is the one signalled, not whatever runs by then. - if (c.p.hostKillJob(id)) stopped = true else jobless = true; + // A command pane's child is the command: the whole of its + // process group goes, as acme's Kill ends the process. A + // terminal's job is asked of the host now, not queued: the job + // the marks say is running is the one signalled, not whatever + // runs by then. + if (command != null) { + c.p.emit(.{ .signal_pty = .{ .pane = @intCast(id), .serial = pane.serial, .sig = .term } }); + stopped = true; + } else if (c.p.hostKillJob(id)) stopped = true else jobless = true; } if (stopped) return; if (jobless) return c.p.reportFailure(c.id, "Kill: no job to signal (its shell runs it without job control)"); @@ -775,7 +765,7 @@ pub const Restore = struct { } // acme's Load adds a dump's windows to the ones there; a Restore // replaces them all, so it asks what Exit asks first. - if (warnModified(c, .Restore)) return; + if (warnModifiedIn(c, .Restore, .all)) return; @memcpy(c.p.restore_buf[0..path.len], path); c.p.restore_req = c.p.restore_buf[0..path.len]; } @@ -1738,13 +1728,7 @@ pub const Find = struct { pub const requires_arg = true; pub const output: OutputTraits = .{ .name = config.search_buffer, .steps = true }; pub fn run(c: Ctx) void { - // A query pane under this pane, line 1 `Find ` and the word: bare - // (SPC f f) typed into; with a word (B2, a script) listed, the - // keyboard left where it was, a script told of a miss. - const pat = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); - const had = panes.Query.ofOwner(c.p, c.pane.serial) != null; - panes.Query.open(c.p, c.id, .find, pat, pat.len == 0); - if (pat.len > 0) missed(c, e_search_miss_find, had); + search(c, .find, e_search_miss_find); } }; @@ -1755,23 +1739,25 @@ pub const Grep = struct { pub const requires_arg = true; pub const output: OutputTraits = .{ .name = config.search_buffer, .steps = true, .locations = true }; pub fn run(c: Ctx) void { - const pat = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); - const had = panes.Query.ofOwner(c.p, c.pane.serial) != null; - panes.Query.open(c.p, c.id, .grep, pat, pat.len == 0); - if (pat.len > 0) missed(c, e_search_miss_grep, had); + search(c, .grep, e_search_miss_grep); } }; -/// A script's Find or Grep (a 9P write runs it to its end before it -/// answers) that found nothing fails as one, opening nothing: a query pane -/// it made goes as an Esc takes it, one it reused stays, its count 0; the -/// write hears `not found`. -fn missed(c: Ctx, text: []const u8, reused: bool) void { - if (!c.p.fs.serving) return; +/// Find's and Grep's query pane under this pane, line 1 the source's word +/// and the argument: bare (SPC f f) typed into; with a word (B2, a script) +/// listed, the keyboard left where it was. A script's (a 9P write runs it +/// to its end before it answers) that found nothing fails as one, opening +/// nothing: a query pane it made goes as an Esc takes it, one it reused +/// stays, its count 0; the write hears `not found`. +fn search(c: Ctx, source: panes.Query.Source, miss: []const u8) void { + const pat = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); + const reused = panes.Query.ofOwner(c.p, c.pane.serial) != null; + panes.Query.open(c.p, c.id, source, pat, pat.len == 0); + if (pat.len == 0 or !c.p.fs.serving) return; const qid = panes.Query.ofOwner(c.p, c.pane.serial) orelse return; if (c.p.panes[qid].?.query.?.total != 0) return; if (!reused) panes.Query.cancel(c.p, qid); - c.p.reportFailure(c.id, text); + c.p.reportFailure(c.id, miss); } /// Search in a query pane under this pane, line 1 the argument (`Panes`, @@ -2412,12 +2398,6 @@ const Board = struct { try std.testing.expect(std.mem.indexOf(u8, Header.text, "GPIO 20 | 17 |") != null); try std.testing.expect(std.mem.indexOf(u8, Header.text, "| 8 | --") != null); } - - test "board addresses are hexadecimal and GPIO numbers are decimal" { - try std.testing.expectEqual(@as(u16, 20), try std.fmt.parseInt(u16, "20", 10)); - try std.testing.expectEqual(@as(u32, 0x20), try parseAddr("20")); - try std.testing.expect(20 != 0x20); - } }; test "Exit and Restore name a modified +New scratch as well as files" { |
