From 1dd26042cc11e15eb7406e750c9454a2e2289a0f Mon Sep 17 00:00:00 2001 From: Manlio Perillo Date: Sat, 25 Feb 2023 10:41:37 +0100 Subject: [PATCH] docgen: remove line support in printShell Line support in printShell breaks the support to terminal colors, when a color is active over multiple lines. An example is when printing reference traces. Remove line support in printShell, since they are not really necessary like in printSourceBlock. In genHtml, remove an empty line when printing the execution of the executable generated by `zig build-exe`. Update the "shell parsed" tests. Remove the call to log.emerg, since it is no longer supported. Add an extra space after "--build-option1 \", as documented. Fixes #13280 --- doc/docgen.zig | 75 ++++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/doc/docgen.zig b/doc/docgen.zig index 277316dd37..e7663cdfe2 100644 --- a/doc/docgen.zig +++ b/doc/docgen.zig @@ -1224,41 +1224,39 @@ fn printShell(out: anytype, shell_content: []const u8, escape: bool) !void { while (iter.next()) |orig_line| { const line = mem.trimRight(u8, orig_line, " "); if (!cmd_cont and line.len > 1 and mem.eql(u8, line[0..2], "$ ") and line[line.len - 1] != '\\') { - try out.writeAll(start_line ++ "$ "); + try out.writeAll("$ "); const s = std.mem.trimLeft(u8, line[1..], " "); if (escape) { try writeEscaped(out, s); } else { try out.writeAll(s); } - try out.writeAll("" ++ end_line ++ "\n"); + try out.writeAll("" ++ "\n"); } else if (!cmd_cont and line.len > 1 and mem.eql(u8, line[0..2], "$ ") and line[line.len - 1] == '\\') { - try out.writeAll(start_line ++ "$ "); + try out.writeAll("$ "); const s = std.mem.trimLeft(u8, line[1..], " "); if (escape) { try writeEscaped(out, s); } else { try out.writeAll(s); } - try out.writeAll(end_line ++ "\n"); + try out.writeAll("\n"); cmd_cont = true; } else if (line.len > 0 and line[line.len - 1] != '\\' and cmd_cont) { - try out.writeAll(start_line); if (escape) { try writeEscaped(out, line); } else { try out.writeAll(line); } - try out.writeAll("" ++ end_line ++ "\n"); + try out.writeAll("" ++ "\n"); cmd_cont = false; } else { - try out.writeAll(start_line); if (escape) { try writeEscaped(out, line); } else { try out.writeAll(line); } - try out.writeAll(end_line ++ "\n"); + try out.writeAll("\n"); } } @@ -1511,7 +1509,7 @@ fn genHtml( const colored_stderr = try termColor(allocator, escaped_stderr); const colored_stdout = try termColor(allocator, escaped_stdout); - try shell_out.print("\n$ ./{s}\n{s}{s}", .{ code.name, colored_stdout, colored_stderr }); + try shell_out.print("$ ./{s}\n{s}{s}", .{ code.name, colored_stdout, colored_stderr }); if (exited_with_signal) { try shell_out.print("(process terminated by signal)", .{}); } @@ -1884,7 +1882,7 @@ test "shell parsed" { \\$ zig build test.zig ; const expected = - \\
Shell
$ zig build test.zig
+            \\
Shell
$ zig build test.zig
             \\
; @@ -1892,7 +1890,6 @@ test "shell parsed" { defer buffer.deinit(); try printShell(buffer.writer(), shell_out, false); - std.log.emerg("{s}", .{buffer.items}); try testing.expectEqualSlices(u8, expected, buffer.items); } { @@ -1901,8 +1898,8 @@ test "shell parsed" { \\build output ; const expected = - \\
Shell
$ zig build test.zig
-            \\build output
+            \\
Shell
$ zig build test.zig
+            \\build output
             \\
; @@ -1919,9 +1916,9 @@ test "shell parsed" { \\$ ./test ; const expected = - \\
Shell
$ zig build test.zig
-            \\build output
-            \\$ ./test
+            \\
Shell
$ zig build test.zig
+            \\build output
+            \\$ ./test
             \\
; @@ -1939,10 +1936,10 @@ test "shell parsed" { \\output ; const expected = - \\
Shell
$ zig build test.zig
-            \\
-            \\$ ./test
-            \\output
+            \\
Shell
$ zig build test.zig
+            \\
+            \\$ ./test
+            \\output
             \\
; @@ -1959,9 +1956,9 @@ test "shell parsed" { \\output ; const expected = - \\
Shell
$ zig build test.zig
-            \\$ ./test
-            \\output
+            \\
Shell
$ zig build test.zig
+            \\$ ./test
+            \\output
             \\
; @@ -1980,11 +1977,11 @@ test "shell parsed" { \\output ; const expected = - \\
Shell
$ zig build test.zig \
-            \\ --build-option
-            \\build output
-            \\$ ./test
-            \\output
+            \\
Shell
$ zig build test.zig \
+            \\ --build-option
+            \\build output
+            \\$ ./test
+            \\output
             \\
; @@ -1998,15 +1995,15 @@ test "shell parsed" { // intentional space after "--build-option1 \" const shell_out = \\$ zig build test.zig \ - \\ --build-option1 \ + \\ --build-option1 \ \\ --build-option2 \\$ ./test ; const expected = - \\
Shell
$ zig build test.zig \
-            \\ --build-option1 \
-            \\ --build-option2
-            \\$ ./test
+            \\
Shell
$ zig build test.zig \
+            \\ --build-option1 \
+            \\ --build-option2
+            \\$ ./test
             \\
; @@ -2022,8 +2019,8 @@ test "shell parsed" { \\$ ./test ; const expected = - \\
Shell
$ zig build test.zig \
-            \\$ ./test
+            \\
Shell
$ zig build test.zig \
+            \\$ ./test
             \\
; @@ -2040,9 +2037,9 @@ test "shell parsed" { \\$1 ; const expected = - \\
Shell
$ zig build test.zig
-            \\$ ./test
-            \\$1
+            \\
Shell
$ zig build test.zig
+            \\$ ./test
+            \\$1
             \\
; @@ -2057,7 +2054,7 @@ test "shell parsed" { \\$zig build test.zig ; const expected = - \\
Shell
$zig build test.zig
+            \\
Shell
$zig build test.zig
             \\
;