From 3e3c07619e4c06ec5d3df4e5d1db288b79abf1ec Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 19 Jan 2024 18:58:06 -0800 Subject: [PATCH] terminal: soft-wrap inherits semantic prompt status of previous line Fixes #1334 --- src/terminal/Terminal.zig | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 6e8d18ec8..2f87ae0d5 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -1025,6 +1025,10 @@ fn printWrap(self: *Terminal) !void { // Move to the next line try self.index(); self.screen.cursor.x = self.scrolling_region.left; + + // New line must inherit semantic prompt of the old line + const new_row = self.screen.getRow(.{ .active = self.screen.cursor.y }); + new_row.setSemanticPrompt(row.getSemanticPrompt()); } fn clearWideSpacerHead(self: *Terminal) void { @@ -2507,6 +2511,23 @@ test "Terminal: soft wrap" { } } +test "Terminal: soft wrap with semantic prompt" { + var t = try init(testing.allocator, 3, 80); + defer t.deinit(testing.allocator); + + t.markSemanticPrompt(.prompt); + for ("hello") |c| try t.print(c); + + { + const row = t.screen.getRow(.{ .active = 0 }); + try testing.expect(row.getSemanticPrompt() == .prompt); + } + { + const row = t.screen.getRow(.{ .active = 1 }); + try testing.expect(row.getSemanticPrompt() == .prompt); + } +} + test "Terminal: print writes to bottom if scrolled" { var t = try init(testing.allocator, 5, 2); defer t.deinit(testing.allocator);