diff options
Diffstat (limited to 'core/Pick.zig')
| -rw-r--r-- | core/Pick.zig | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/core/Pick.zig b/core/Pick.zig index a7a0d899..6c86cb98 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -46,9 +46,11 @@ const Key = pardes.Key; /// under the asking pane's directory, the lines of them holding the /// query, the files opened lately, the panes, the asking text's /// declarations, the lines holding the query in every open pane (All, its -/// places in each), the jump list, and rows handed over (a language -/// server's answer), titled by their word. -pub const Source = enum { find, grep, recent, panes, symbols, all, jumplist, list, themes }; +/// places in each), the jump list, rows handed over (a language server's +/// answer, SPC e's places), titled by their word, the messages' history +/// (SPC h m), and the themes (SPC t t, the window wearing the one under +/// the cursor). +pub const Source = enum { find, grep, recent, panes, symbols, all, jumplist, list, messages, themes }; /// Each source's word in the tag and the leader keys of the builtin that /// opens it, its key cells (`␣ f Find`). @@ -61,6 +63,7 @@ const words = std.EnumArray(Source, struct { word: []const u8, keys: []const u8 .all = .{ .word = "All", .keys = "" }, .jumplist = .{ .word = "Jumplist", .keys = "j" }, .list = .{ .word = "List", .keys = "l" }, + .messages = .{ .word = "Messages", .keys = "hm" }, .themes = .{ .word = "Themes", .keys = "t" }, }); @@ -290,6 +293,12 @@ fn start(p: *Pardes, pk: *Pick) void { addRows(p, pk, out.written()); }, .list => addRows(p, pk, pk.rows), + .messages => { + var out: std.Io.Writer.Allocating = .init(p.gpa); + defer out.deinit(); + Output.messagesText(p, &out.writer) catch return; + addRows(p, pk, out.written()); + }, .themes => for (pardes.colors.themes, 0..) |t, i| { pk.names.add(p.gpa, t.name, 0, t.name.len, 0, @intCast(i)) catch return; }, @@ -525,6 +534,24 @@ fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) !Row { const path = if (t.path[0] == '/' or t.path[0] == '@') t.path else try std.Io.Dir.path.join(arena, &.{ dir, t.path }); row.target = .{ .place = .{ .path = path, .at = t.at } }; }, + // A message (`✗ 3: words`, Output.messagesText): its cause's pane + // while it is open; a place under it (indented): that place. + .messages => { + const lead = text.len - std.mem.trimStart(u8, text, " ").len; + if (lead == 0) { + const sp = std.mem.indexOfScalar(u8, text, ' ') orelse return row; + const digits = text[sp + 1 ..]; + const n = std.mem.indexOfNone(u8, digits, "0123456789") orelse return row; + if (n == 0 or digits[n] != ':') return row; + const serial = std.fmt.parseInt(u32, digits[0..n], 10) catch return row; + if (p.paneBySerial(serial) != null) row.target = .{ .pane = serial }; + return row; + } + const t = look.parsePathLine(text[lead..]); + row.pre = @intCast(lead + t.end); + if (t.path.len == 0) return row; + row.target = .{ .place = .{ .path = t.path, .at = t.at } }; + }, } return row; } @@ -585,7 +612,7 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { for (acts) |act| if (offered(pk, act)) try text.print(arena, "{s} ", .{act.word}); try text.appendSlice(arena, "|"); var first = false; - inline for (comptime std.enums.values(Source)) |src| if (src != .list and src != .themes) { + inline for (comptime std.enums.values(Source)) |src| if (src != .list and src != .messages and src != .themes) { if (src != pk.source) { if (!first) try text.append(arena, ' '); first = false; @@ -1006,6 +1033,11 @@ fn back(p: *Pardes, pk: *Pick) void { fn keep(p: *Pardes, pk: *Pick) void { const s = &p.view().tag_state; const from = p.paneBySerial(pk.owner) orelse p.view().active; + // The history kept is the +Messages (SPEC §10.4). + if (pk.source == .messages) { + TagState.toRest(p); + return Output.openMessages(p, from) catch |err| p.reportError(.at(from), "messages", err); + } var out: std.Io.Writer.Allocating = .init(p.gpa); defer out.deinit(); var arena = std.heap.ArenaAllocator.init(p.gpa); |
