diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/CHANGELOG.md | 8 | ||||
| -rw-r--r-- | src/Output.zig | 3 | ||||
| -rw-r--r-- | src/dump.zig | 1 | ||||
| -rw-r--r-- | src/exec.zig | 50 | ||||
| -rw-r--r-- | src/image.zig | 8 | ||||
| -rw-r--r-- | src/pardes.zig | 159 | ||||
| -rw-r--r-- | src/pdf_view.zig | 18 | ||||
| -rw-r--r-- | src/tagline.zig | 135 | ||||
| -rw-r--r-- | src/terminal.zig | 33 |
9 files changed, 15 insertions, 400 deletions
diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index 50149551..a2f493df 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## Unreleased + +- Dumps and init files from before 0.0.4 no longer load their old tag + formats: a restored pane's tag tail is read only from `tag_tail`, and an old + terminal's `TTY` tag or raw output tail is not replayed. `ThemeSel`, + `FontSel` and `ColumnTags` are no longer recognised in init files or dumps + (`Themes` and `Fonts` are the words). + ## 0.0.5 - Over a slow link the terminal build keeps at most one frame in flight: it diff --git a/src/Output.zig b/src/Output.zig index 8cf57591..5bc1f9fc 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -262,9 +262,6 @@ pub fn fromWord(w: []const u8) ?Origin { if (std.mem.eql(u8, w, config.errors_buffer)) return .errors; if (std.mem.eql(u8, w, config.pdf_links_buffer)) return .pdf_links; if (std.mem.eql(u8, w, config.unsaved_buffer)) return .unsaved; - // A dump from before the rename names them by their old words. - if (std.mem.eql(u8, w, "ThemeSel")) return .{ .cmd = .Themes }; - if (builtins.capabilities.font_picker) if (std.mem.eql(u8, w, "FontSel")) return .{ .cmd = .Fonts }; if (std.meta.stringToEnum(Builtin, w)) |b| if (builtins.registry.outputTraits(b) != null) return .{ .cmd = b }; if (std.meta.stringToEnum(lsp.Kind, w)) |k| return .{ .query = k }; diff --git a/src/dump.zig b/src/dump.zig index 78c2bd7a..2d3c2593 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -905,7 +905,6 @@ fn initDump(gpa: std.mem.Allocator, opts: Options, zon_bytes: []const u8, previo restored.command_done = true; restored.command_status = t.status; } - if (std.mem.startsWith(u8, src.tag, "TTY ")) restored.body.mode = .tty; if (revive) p.emitSpawn(i, restored.serial, t.cwd); break :terminal restored; }, diff --git a/src/exec.zig b/src/exec.zig index 221de105..8c062f66 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -870,58 +870,10 @@ pub fn applyStartupConfig(p: *Pardes) void { defer p.announce = true; var lines = std.mem.splitScalar(u8, p.opts.startup_config orelse return, '\n'); while (lines.next()) |line| { - if (executeBuiltinLine(p, p.active, line)) continue; - // A setting pardes no longer has is said, once, and changes nothing. - const word = commandText(line); - const head = word[0 .. std.mem.indexOfAny(u8, word, " \t") orelse word.len]; - if (std.mem.eql(u8, head, "ColumnTags")) - p.setMessage(p.active, "ColumnTags: column tags are always shown now; the init line is ignored"); - // A word renamed runs as its new name, and says so, once a line. - for ([_][2][]const u8{ .{ "ThemeSel", "Themes" }, .{ "FontSel", "Fonts" } }) |renamed| if (std.mem.eql(u8, head, renamed[0])) { - _ = executeBuiltinLine(p, p.active, renamed[1]); - var said: [64]u8 = undefined; - p.setMessage(p.active, std.fmt.bufPrint(&said, "{s}: renamed to {s}", .{ renamed[0], renamed[1] }) catch "renamed"); - }; + _ = executeBuiltinLine(p, p.active, line); } } -test "an init file's ThemeSel runs as Themes and says it was renamed" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24, .startup_config = "ThemeSel\n" }); - defer p.deinit(); - var listed = false; - for (p.panes) |slot| if (slot) |pane| if (pane.file) |f| if (f.output) |o| { - listed = listed or std.meta.eql(o.from, panes.Output.Origin{ .cmd = .Themes }); - }; - try std.testing.expect(listed); - // In the session's directory, not `/`. - for (p.panes) |slot| if (slot) |pane| if (pane.file) |f| if (f.output != null) - try std.testing.expectEqualStrings(p.sessionDir(), std.fs.path.dirname(f.path).?); - var said = false; - for (p.panes) |slot| if (slot) |pane| { - said = said or std.mem.eql(u8, pane.msg[0..pane.msg_len], "ThemeSel: renamed to Themes"); - }; - try std.testing.expect(said); - // The panes there at boot are the log's first records, before what the - // init file said. - const th = @import("ninep/testing.zig"); - const log = @intFromEnum(pardes.ctlfs.TopFile.log); - const h = th.call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle; - defer _ = th.call(p, .{ .tag = 3, .op = .release, .node = log, .handle = h }); - const text = th.call(p, .{ .tag = 2, .op = .read, .node = log, .handle = h, .size = 1 << 16 }).bytes; - try std.testing.expectStringStartsWith(text, "new "); -} - -test "an init file's retired ColumnTags line is said and ignored" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); - defer p.deinit(); - p.opts.startup_config = "ColumnTags\nWrap off\n"; - applyStartupConfig(p); - try std.testing.expect(!p.settings.wrap); - try std.testing.expect(p.columnBarHeight() > 0); - const pane = p.panes[p.active].?; - try std.testing.expectEqualStrings("ColumnTags: column tags are always shown now; the init line is ignored", pane.msg[0..pane.msg_len]); -} - pub fn runBuiltin(p: *Pardes, b: Builtin, id: usize, txt: []const u8, arg: ?[]const u8) void { runBuiltinFrom(p, b, id, txt, arg, false); } diff --git a/src/image.zig b/src/image.zig index 7b081ec6..936fe19a 100644 --- a/src/image.zig +++ b/src/image.zig @@ -916,14 +916,6 @@ pub fn tagPrefix(arena: std.mem.Allocator, state: *const State) ![]u8 { ); } -pub fn legacySavedPrefix(state: *const State, saved_tag: []const u8) ?[]const u8 { - const lead = config.tag_image ++ " "; - if (!std.mem.startsWith(u8, saved_tag, lead)) return null; - const path_at = lead.len; - if (!std.mem.startsWith(u8, saved_tag[path_at..], state.path)) return null; - return saved_tag[0 .. path_at + state.path.len]; -} - fn ensureDecoded(p: *pardes.Pardes, state: *State) void { if (state.tried) return; state.tried = true; diff --git a/src/pardes.zig b/src/pardes.zig index 3ecc80ae..151fe7b0 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -751,13 +751,6 @@ test "Collapse builtin keeps content and restores the pane from its default tag" p.sync(); try std.testing.expect(!pane.collapsed); try std.testing.expectEqual(height, p.rects[0].h); - - // Unedited defaults from the preceding version gain the new command. - if (pane.tag.own) |own| p.gpa.free(own); - pane.tag.own = null; - tagline.restoreTailAt(p, pane, tagline.pre_collapse_file_pane_tail, "", .file); - try std.testing.expect(pane.tag.own == null); - try std.testing.expectEqualStrings(tagline.file_pane_tail, tagline.curTail(pane)); } test "LocationsConfig command reports partial updates and survives restore" { @@ -985,129 +978,6 @@ test "compact tag commands stay beside their own prefix across layout changes" { try std.testing.expectEqualStrings(above_tag, try tagline.tagText(p, p.scratch.allocator(), above)); } -test "legacy default tag tails upgrade while custom tails remain owned" { - const gpa = std.testing.allocator; - const p = try Pardes.init(gpa, .{}); - defer p.deinit(); - - const terminal = p.panes[0].?; - const terminal_old = try std.fmt.allocPrint(p.scratch.allocator(), "{s}{s}", .{ - try tagline.tagPrefix(p, terminal), - tagline.legacy_pane_tail, - }); - tagline.restoreTail(p, terminal, terminal_old); - try std.testing.expect(terminal.tag.own == null); - try std.testing.expectEqualStrings(tagline.terminal_pane_tail, tagline.curTail(terminal)); - - const terminal_previous = try std.fmt.allocPrint(p.scratch.allocator(), "{s} New Del", .{ - try tagline.tagPrefix(p, terminal), - }); - tagline.restoreTail(p, terminal, terminal_previous); - try std.testing.expect(terminal.tag.own == null); - try std.testing.expectEqualStrings(tagline.terminal_pane_tail, tagline.curTail(terminal)); - - const terminal_prefilter = try std.fmt.allocPrint(p.scratch.allocator(), "{s}{s}", .{ - try tagline.tagPrefix(p, terminal), - tagline.prev_terminal_pane_tail, - }); - tagline.restoreTail(p, terminal, terminal_prefilter); - try std.testing.expect(terminal.tag.own == null); - try std.testing.expectEqualStrings(tagline.terminal_pane_tail, tagline.curTail(terminal)); - - for ([_][]const u8{ tagline.pre_mode_terminal_pane_tail, tagline.pre_tty_first_terminal_pane_tail, tagline.pre_collapse_terminal_pane_tail }) |old_tail| { - const old = try std.fmt.allocPrint(p.scratch.allocator(), "{s}{s}", .{ try tagline.tagPrefix(p, terminal), old_tail }); - tagline.restoreTail(p, terminal, old); - try std.testing.expect(terminal.tag.own == null); - try std.testing.expectEqualStrings(tagline.terminal_pane_tail, tagline.curTail(terminal)); - } - const custom_mode = try std.fmt.allocPrint(p.scratch.allocator(), "{s}{s} Keep", .{ try tagline.tagPrefix(p, terminal), tagline.pre_mode_terminal_pane_tail }); - tagline.restoreTail(p, terminal, custom_mode); - try std.testing.expect(terminal.tag.own != null); - try std.testing.expectEqualStrings(tagline.pre_mode_terminal_pane_tail ++ " Keep", tagline.curTail(terminal)); - - if (terminal.tag.own) |own| p.gpa.free(own); - terminal.tag.own = null; - const terminal_custom = try std.fmt.allocPrint(p.scratch.allocator(), "{s} Keep Del", .{ - try tagline.tagPrefix(p, terminal), - }); - tagline.restoreTail(p, terminal, terminal_custom); - try std.testing.expect(terminal.tag.own != null); - try std.testing.expectEqualStrings(" Keep Del", tagline.curTail(terminal)); - - if (terminal.tag.own) |own| p.gpa.free(own); - terminal.tag.own = null; - tagline.restoreDumpTail(p, terminal, .{ - .kind = .terminal, - .tag = "TTY /historical/cwd Keep Del", - .body = "", - .terminal = .{ .cwd = "/historical/cwd" }, - }); - try std.testing.expect(terminal.tag.own != null); - try std.testing.expectEqualStrings(" Keep Del", tagline.curTail(terminal)); - - if (terminal.tag.own) |own| p.gpa.free(own); - terminal.tag.own = null; - tagline.restoreDumpTail(p, terminal, .{ - .kind = .terminal, - .tag = "TTY /historical/cwd New Del", - .body = "", - .terminal = .{ .cwd = "/historical/cwd" }, - }); - try std.testing.expect(terminal.tag.own == null); - try std.testing.expectEqualStrings(tagline.terminal_pane_tail, tagline.curTail(terminal)); - - // This happens to be the historical FILE default, but on a terminal it is - // user-owned text and must not be swallowed by migration. - if (terminal.tag.own) |own| p.gpa.free(own); - terminal.tag.own = null; - const terminal_fileish = try std.fmt.allocPrint(p.scratch.allocator(), "{s} Save Del", .{ - try tagline.tagPrefix(p, terminal), - }); - tagline.restoreTail(p, terminal, terminal_fileish); - try std.testing.expect(terminal.tag.own != null); - try std.testing.expectEqualStrings(" Save Del", tagline.curTail(terminal)); - - // A savable file has a distinct old default. Save remains first after the - // migration so the tag's established `:w<Tab>` route is unchanged. - const file = try p.setTestFile(""); - const file_old = try std.fmt.allocPrint(p.scratch.allocator(), "{s}{s}", .{ - try tagline.tagPrefix(p, file), - tagline.legacy_file_pane_tail, - }); - tagline.restoreTail(p, file, file_old); - try std.testing.expect(file.tag.own == null); - try std.testing.expectEqualStrings(" Save Tty Collapse Del", tagline.curTail(file)); - - const file_custom = try std.fmt.allocPrint(p.scratch.allocator(), "{s} Save Mine Del", .{ - try tagline.tagPrefix(p, file), - }); - tagline.restoreTail(p, file, file_custom); - try std.testing.expect(file.tag.own != null); - try std.testing.expectEqualStrings(" Save Mine Del", tagline.curTail(file)); - - // Conversely the generic pane's current default is a custom edit on a - // savable file. Legacy recognition is scoped to the source pane class. - if (file.tag.own) |own| p.gpa.free(own); - file.tag.own = null; - const file_generic = try std.fmt.allocPrint(p.scratch.allocator(), "{s} New Del", .{ - try tagline.tagPrefix(p, file), - }); - tagline.restoreTail(p, file, file_generic); - try std.testing.expect(file.tag.own != null); - try std.testing.expectEqualStrings(" New Del", tagline.curTail(file)); - - const image_doc = try panes.Image.create(p, 1, "/tmp/legacy image.ppm", &.{}); - try std.testing.expectEqualStrings(" Tty Collapse Del", tagline.curTail(image_doc)); - tagline.restoreDumpTail(p, image_doc, .{ - .kind = .image, - .tag = "img /tmp/legacy image.ppm Keep Del", - .body = "", - .image = .{ .path = "/tmp/legacy image.ppm" }, - }); - try std.testing.expect(image_doc.tag.own != null); - try std.testing.expectEqualStrings(" Keep Del", tagline.curTail(image_doc)); -} - test "Joincol folds the active column into its right neighbor, keeping its panes" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); @@ -1434,14 +1304,6 @@ test "pane defaults keep creation of scratch panes in column tags" { while (words.next()) |word| try std.testing.expect(!std.mem.eql(u8, word, "New")); } try std.testing.expectEqualStrings("New Tty Find Grep Joincol Delcol", tagline.columnTag(p, 0)); - const terminal = p.panes[0].?; - tagline.restoreTailAt(p, terminal, tagline.pre_column_terminal_pane_tail, "", .terminal); - try std.testing.expect(terminal.tag.own == null); - try std.testing.expectEqualStrings(tagline.terminal_pane_tail, tagline.curTail(terminal)); - const file = try p.setTestFile("unchanged\n"); - tagline.restoreTailAt(p, file, tagline.pre_column_file_pane_tail, "", .file); - try std.testing.expect(file.tag.own == null); - try std.testing.expectEqualStrings(tagline.file_pane_tail, tagline.curTail(file)); } test "an unsaved file's tag is its name alone: the grip, not a mark, says it is unsaved" { @@ -2640,27 +2502,8 @@ test "Save reaches every tagline with text behind it and no other" { out.file.?.output = .{ .from = .search }; try std.testing.expectEqualStrings(tagline.locations_pane_tail, tagline.curTail(out)); - // A dump written before Save reached output buffers carries the generic - // tail. That is a DEFAULT and not something typed, so it upgrades. - const dumped = try std.fmt.allocPrint(p.scratch.allocator(), "{s}{s}", .{ - try tagline.tagPrefix(p, out), - tagline.pane_tail, - }); - tagline.restoreTail(p, out, dumped); - try std.testing.expect(out.tag.own == null); - try std.testing.expectEqualStrings(tagline.locations_pane_tail, tagline.curTail(out)); - - // A scratch is an output buffer that has worn the FILE tails all along, - // so its own older default upgrades from that family too. + // A scratch is an output buffer that wears the FILE tails. out.file.?.output = .{ .from = .{ .cmd = std.meta.stringToEnum(Builtin, "New").? } }; - if (out.tag.own) |own| p.gpa.free(own); - out.tag.own = null; - const scratch_dumped = try std.fmt.allocPrint(p.scratch.allocator(), "{s}{s}", .{ - try tagline.tagPrefix(p, out), - tagline.prev_file_pane_tail, - }); - tagline.restoreTail(p, out, scratch_dumped); - try std.testing.expect(out.tag.own == null); try std.testing.expectEqualStrings(" Save Tty Collapse Del", tagline.curTail(out)); // An image's bytes on disk already are what they are: nothing of the diff --git a/src/pdf_view.zig b/src/pdf_view.zig index 8f842cde..5646a92f 100644 --- a/src/pdf_view.zig +++ b/src/pdf_view.zig @@ -57,24 +57,6 @@ pub const RasterPolicy = struct { match_viewport: bool, }; -pub fn legacySavedPrefix(path: []const u8, saved_tag: []const u8) ?[]const u8 { - if (std.mem.startsWith(u8, saved_tag, path) and std.mem.startsWith(u8, saved_tag[path.len..], " [")) { - const start = path.len + 2; - const end = std.mem.indexOfScalarPos(u8, saved_tag, start, ']') orelse return null; - var parts = std.mem.splitScalar(u8, saved_tag[start..end], '/'); - _ = std.fmt.parseInt(usize, parts.next() orelse return null, 10) catch return null; - _ = std.fmt.parseInt(usize, parts.next() orelse return null, 10) catch return null; - if (parts.next() != null) return null; - return saved_tag[0 .. end + 1]; - } - if (!std.mem.startsWith(u8, saved_tag, "pdf ")) return null; - const marker = " PdfSections "; - const marker_at = std.mem.indexOf(u8, saved_tag, marker) orelse return null; - const path_at = marker_at + marker.len; - if (!std.mem.startsWith(u8, saved_tag[path_at..], path)) return null; - return saved_tag[0 .. path_at + path.len]; -} - pub const TintKey = if (enabled) struct { mode: TintMode, colors: pdf.TintColors, diff --git a/src/tagline.zig b/src/tagline.zig index df093925..1923871a 100644 --- a/src/tagline.zig +++ b/src/tagline.zig @@ -23,43 +23,11 @@ pub const context_pane_tail = file_pane_tail ++ " TreeContext"; pub const locations_pane_tail = file_pane_tail ++ " LocationsConfig"; pub const terminal_pane_tail = " " ++ config.terminal_pane_builtins_str; pub const command_pane_tail = " " ++ config.command_pane_builtins_str; -/// The mark a tag carried after an unsaved file's name before the grip -/// showed it; a dump from then still has it in its saved tags. -const dirty_marker = " *"; - /// A file with changes it has not saved. pub fn dirty(pane: *const panes.Pane) bool { const f = pane.file orelse return false; return panes.Output.fileTraits(f.output).saves and (f.revision != f.saved_revision or f.disk_gone); } -pub const legacy_pane_tail = " Del"; -pub const legacy_file_pane_tail = " Save Del"; -// The defaults from the release before Newtty joined every tagline. Recognized -// so a dump written then upgrades instead of keeping the old word as a tail. -const prev_pane_tail = " New Del"; -pub const prev_file_pane_tail = " Save New Del"; -const legacy_terminal_pane_tail = " New Del Filter"; -// ...and the terminal default from the release before Save reached it, when a -// scrollback was not yet something you could write to a path. -pub const prev_terminal_pane_tail = " New Newtty Del Filter"; -const pre_tty_terminal_pane_tail = " Save New Newtty Del Filter"; -const pre_column_pane_tail = " New Newtty Del"; -pub const pre_column_file_pane_tail = " Save New Newtty Del"; -const pre_column_pdf_pane_tail = " New Newtty Del PdfSections PdfTint"; -pub const pre_column_terminal_pane_tail = " Save New Newtty Del Tty Filter"; -const pre_collapse_pane_tail = " Tty Del"; -pub const pre_collapse_file_pane_tail = " Save Tty Del"; -const pre_collapse_pdf_pane_tail = " Tty Del PdfSections PdfTint"; -pub const pre_collapse_terminal_pane_tail = " Save Tty Del Togglettymode Filter"; -pub const pre_tty_first_terminal_pane_tail = " Save Tty Del Togglettymode Filter Collapse"; -pub const pre_mode_terminal_pane_tail = " Tty Save Del Togglettymode Filter Collapse"; -// ...and the defaults from before the closing word moved to the end of every -// tagline, where a click cannot land on it by overshooting the one before. -const pre_close_last_pane_tail = " Tty Del Collapse"; -const pre_close_last_file_pane_tail = " Save Tty Del Collapse"; -const pre_close_last_pdf_pane_tail = " Tty Del PdfSections PdfTint Collapse"; -const pre_close_last_terminal_pane_tail = " Tty Save Del Mode Filter Collapse"; - /// What a column's tag says until someone edits it. pub const column_tag_default = "New Tty Find Grep Joincol Delcol"; @@ -420,106 +388,11 @@ pub fn enterHeader(p: *Pardes, column: ?usize) void { t.normal.clear(); } +/// A dump's tag tail, what was typed after the name: a dump from 0.0.4 on +/// writes it, and an older one's saved tag is not read. pub fn restoreDumpTail(p: *Pardes, pane: *Pane, src: dump.Pane) void { - if (src.tag_tail) |tail| { - pane.tag.own = p.gpa.dupe(u8, tail) catch return; - return; - } - const tail_class = tailClass(pane); - if (src.kind == .image and panes.Pdf.isPath(src.image.?.path)) { - if (panes.Pdf.legacySavedPrefix(src.image.?.path, src.tag)) |prefix| - return restoreTailAt(p, pane, src.tag, prefix, .generic); - } - if (src.kind == .terminal and std.mem.startsWith(u8, src.tag, "TTY ")) { - const legacy = std.fmt.allocPrint(p.scratch.allocator(), "TTY {s}", .{src.terminal.?.cwd}) catch return; - if (std.mem.startsWith(u8, src.tag, legacy)) - return restoreTailAt(p, pane, src.tag, legacy, .terminal); - } - const current = tagPrefix(p, pane) catch return; - if (std.mem.startsWith(u8, src.tag, current)) - return restoreTailAt(p, pane, src.tag, savedPrefix(src.tag, current, tail_class), tail_class); - if (src.kind != .image) return; - const saved = src.image.?; - if (pane.image) |*state| if (panes.Image.legacySavedPrefix(state, src.tag)) |legacy| - return restoreTailAt(p, pane, src.tag, legacy, .generic); - if (panes.Pdf.isPath(saved.path)) if (panes.Pdf.legacySavedPrefix(saved.path, src.tag)) |legacy| - restoreTailAt(p, pane, src.tag, legacy, .generic); -} - -pub fn restoreTail(p: *Pardes, pane: *Pane, saved_tag: []const u8) void { - const pfx = tagPrefix(p, pane) catch return; - const class = tailClass(pane); - restoreTailAt(p, pane, saved_tag, savedPrefix(saved_tag, pfx, class), class); -} - -const TailClass = enum { generic, file, output, terminal }; - -fn tailClass(pane: *const Pane) TailClass { - if (pane.file) |f| return if (f.output == null) .file else .output; - if (pane.isTerminal()) return .terminal; - return .generic; -} - -fn savedPrefix(saved_tag: []const u8, live: []const u8, class: TailClass) []const u8 { - if (class == .generic or class == .terminal) return live; - if (!std.mem.startsWith(u8, saved_tag, live)) return live; - const marked_len = live.len + dirty_marker.len; - if (saved_tag.len >= marked_len and std.mem.eql(u8, saved_tag[live.len..marked_len], dirty_marker)) - return saved_tag[0..marked_len]; - return live; -} - -pub fn restoreTailAt( - p: *Pardes, - pane: *Pane, - saved_tag: []const u8, - pfx: []const u8, - class: TailClass, -) void { - if (!std.mem.startsWith(u8, saved_tag, pfx)) return; - const rest = saved_tag[pfx.len..]; - const said = std.mem.trimStart(u8, rest, " "); - const defaults: []const []const u8 = switch (class) { - .generic => &.{ pdf_pane_tail, pane_tail, pre_close_last_pdf_pane_tail, pre_close_last_pane_tail, pre_collapse_pdf_pane_tail, pre_collapse_pane_tail, pre_column_pdf_pane_tail, pre_column_pane_tail, prev_pane_tail, legacy_pane_tail }, - .file => &.{ context_pane_tail, file_pane_tail, pre_close_last_file_pane_tail, pre_collapse_file_pane_tail, pre_column_file_pane_tail, prev_file_pane_tail, legacy_file_pane_tail }, - .output => &.{ - locations_pane_tail, - file_pane_tail, - pre_close_last_file_pane_tail, - pre_close_last_pane_tail, - prev_file_pane_tail, - legacy_file_pane_tail, - pane_tail, - prev_pane_tail, - legacy_pane_tail, - pre_column_file_pane_tail, - pre_column_pane_tail, - pre_collapse_file_pane_tail, - pre_collapse_pane_tail, - }, - .terminal => &.{ terminal_pane_tail, pre_close_last_terminal_pane_tail, pre_close_last_pane_tail, pre_mode_terminal_pane_tail, pre_tty_first_terminal_pane_tail, pre_collapse_terminal_pane_tail, pre_column_terminal_pane_tail, pre_tty_terminal_pane_tail, prev_terminal_pane_tail, legacy_terminal_pane_tail, pane_tail, pre_collapse_pane_tail, pre_column_pane_tail, prev_pane_tail, legacy_pane_tail }, - }; - // A terminal's saved tag carries what was live about it -- the REPL id - // after its directory, the shell in its Tty word -- which is neither - // dumped nor true of the new shell: its tail is still the default. - var plain = said; - var plain_buf: [256]u8 = undefined; - if (class == .terminal) { - const first = plain[0 .. std.mem.indexOfScalar(u8, plain, ' ') orelse plain.len]; - if (std.mem.lastIndexOfScalar(u8, first, '-')) |dash| if (dash + 2 == first.len and first[dash + 1] >= 'a' and first[dash + 1] <= 'z') { - for (@import("grammar_manifest.zig").all) |g| if (std.mem.eql(u8, g.name, first[0..dash])) { - plain = std.mem.trimStart(u8, plain[first.len..], " "); - break; - }; - }; - if (std.mem.startsWith(u8, plain, "Tty+")) { - const word_end = std.mem.indexOfScalar(u8, plain, ' ') orelse plain.len; - plain = std.fmt.bufPrint(&plain_buf, "Tty{s}", .{plain[word_end..]}) catch plain; - } - } - for (defaults) |default| - if (std.mem.eql(u8, plain, std.mem.trimStart(u8, default, " "))) return; - pane.tag.own = p.gpa.dupe(u8, rest) catch return; + const tail = src.tag_tail orelse return; + pane.tag.own = p.gpa.dupe(u8, tail) catch return; } /// The span a header's selection covers on line `row` of its text, in diff --git a/src/terminal.zig b/src/terminal.zig index c99a92a6..6bf46bef 100644 --- a/src/terminal.zig +++ b/src/terminal.zig @@ -509,13 +509,7 @@ pub fn restore(p: *Pardes, src: dump.Pane, live: bool) !*Pane { pane.ovl = .{ .row = 0, .rows = 1, .text = try p.gpa.dupe(u8, terminal.stream) }; return pane; } - // An older dump's raw output tail cannot come back live: cut off mid - // redraw, or written at sizes the pane no longer has, it replays as - // garbage. Its rendered text can. - const legacy_text = live and !terminal.stream_is_screen and terminal.stream.len > 0; - const bytes = if (legacy_text) - try std.mem.replaceOwned(u8, p.scratch.allocator(), terminal.stream, "\n", "\r\n") - else if (terminal.stream_b64.len > 0) + const bytes = if (terminal.stream_b64.len > 0) try dump.decodeBytes(p.scratch.allocator(), terminal.stream_b64) else &.{}; @@ -759,31 +753,6 @@ test "a restored terminal keeps its history above a marker and gets a shell wher try std.testing.expect(old_at < mark_at); } -test "an older dump comes back live from its rendered text, not its raw output tail" { - if (comptime !enabled) return error.SkipZigTest; - const gpa = std.testing.allocator; - const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 }); - defer p.deinit(); - // A tail cut mid-redraw: relative moves from a cursor it never set. - const tail = try dump.encodeBytes(gpa, "\x1b[7A\x1b[2Kgarbage\x1b[3B\x1b[9Gmore"); - defer gpa.free(tail); - const restored = try restore(p, .{ - .kind = .terminal, - .tag = "", - .body = "", - .cols = 40, - .rows = 12, - .terminal = .{ .stream = "$ ls\na.txt b.txt\n$ ", .stream_b64 = tail }, - }, true); - defer gpa.destroy(restored); - defer deinitEmulator(restored, gpa); - defer deinitPendingCommand(restored); - const text = try screenTextAlloc(restored, gpa); - defer gpa.free(text); - try std.testing.expect(std.mem.indexOf(u8, text, "$ ls\na.txt b.txt") != null); - try std.testing.expect(std.mem.indexOf(u8, text, "garbage") == null); -} - /// Record and parse one live pty read, invalidate its motion surface, and /// follow it only when the body (possibly parked under a tag edit) is raw. pub fn feedOutput(p: *Pardes, pane: *Pane, bytes: []const u8) void { |
