From 768a81e2bdac45038ba553389be821783967aace Mon Sep 17 00:00:00 2001 From: torque Date: Wed, 8 Nov 2023 22:52:28 -0800 Subject: [PATCH] help: hack in support for preformatted lines This works, but there are probably interesting edge cases around how it works when directly adjacent to other paragraphs. I will have to think about it a bit. This wrapping code in general would benefit from term queries. Perhaps violating the principle of least astonishment quite severely is the fact that "> a" and ">" are detected as preformatted, but ">a" is normal wrapped text. Supporting both ">a" and "> a" leads to nonobvious whitespace behavior, but this code should not be able to runtime error outside of the writer dying. This may be reevaluated in the future, but I will leave it as-is for now. --- source/help.zig | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/source/help.zig b/source/help.zig index 7ccd8d3..2dd157a 100644 --- a/source/help.zig +++ b/source/help.zig @@ -65,6 +65,17 @@ pub fn StructuredPrinter(comptime Writer: type) type { // we have a trailing line that needs to be cleaned up if (location > indent) _ = try self.clearLine(indent); + + location = try self.clearLine(indent); + continue; + } + + if (line[0] == '>') maybe: { + if (line.len > 1) { + if (line[1] == ' ') { + try self.writer.writeAll(line[2..]); + } else break :maybe; + } location = try self.clearLine(indent); continue; } @@ -101,6 +112,7 @@ pub fn StructuredPrinter(comptime Writer: type) type { } if (location > indent) try self.writer.writeByte(' '); + try self.writer.writeAll(choppee[0..split]); location = try self.clearLine(indent); choppee = choppee[split + 1 ..];