authorgravatar for manlio.perillo@gmail.comManlio Perillo <manlio.perillo@gmail.com> 2023-02-25 10:41:37+01:00
committergravatar for manlio.perillo@gmail.comManlio Perillo <manlio.perillo@gmail.com> 2023-03-27 12:10:49+02:00
log1dd26042cc11e15eb7406e750c9454a2e2289a0f
tree56b3a3fae31179db879bddf4ab0a108ba720207e
parent1de64dba236d9496ae5f31b59b7a4947ff4d90be

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

1 files changed, 36 insertions(+), 39 deletions(-)

doc/docgen.zig+36-39
......@@ -1224,41 +1224,39 @@ fn printShell(out: anytype, shell_content: []const u8, escape: bool) !void {
12241224 while (iter.next()) |orig_line| {
12251225 const line = mem.trimRight(u8, orig_line, " ");
12261226 if (!cmd_cont and line.len > 1 and mem.eql(u8, line[0..2], "$ ") and line[line.len - 1] != '\\') {
1227 try out.writeAll(start_line ++ "$ <kbd>");
1227 try out.writeAll("$ <kbd>");
12281228 const s = std.mem.trimLeft(u8, line[1..], " ");
12291229 if (escape) {
12301230 try writeEscaped(out, s);
12311231 } else {
12321232 try out.writeAll(s);
12331233 }
1234 try out.writeAll("</kbd>" ++ end_line ++ "\n");
1234 try out.writeAll("</kbd>" ++ "\n");
12351235 } else if (!cmd_cont and line.len > 1 and mem.eql(u8, line[0..2], "$ ") and line[line.len - 1] == '\\') {
1236 try out.writeAll(start_line ++ "$ <kbd>");
1236 try out.writeAll("$ <kbd>");
12371237 const s = std.mem.trimLeft(u8, line[1..], " ");
12381238 if (escape) {
12391239 try writeEscaped(out, s);
12401240 } else {
12411241 try out.writeAll(s);
12421242 }
1243 try out.writeAll(end_line ++ "\n");
1243 try out.writeAll("\n");
12441244 cmd_cont = true;
12451245 } else if (line.len > 0 and line[line.len - 1] != '\\' and cmd_cont) {
1246 try out.writeAll(start_line);
12471246 if (escape) {
12481247 try writeEscaped(out, line);
12491248 } else {
12501249 try out.writeAll(line);
12511250 }
1252 try out.writeAll("</kbd>" ++ end_line ++ "\n");
1251 try out.writeAll("</kbd>" ++ "\n");
12531252 cmd_cont = false;
12541253 } else {
1255 try out.writeAll(start_line);
12561254 if (escape) {
12571255 try writeEscaped(out, line);
12581256 } else {
12591257 try out.writeAll(line);
12601258 }
1261 try out.writeAll(end_line ++ "\n");
1259 try out.writeAll("\n");
12621260 }
12631261 }
12641262
......@@ -1511,7 +1509,7 @@ fn genHtml(
15111509 const colored_stderr = try termColor(allocator, escaped_stderr);
15121510 const colored_stdout = try termColor(allocator, escaped_stdout);
15131511
1514 try shell_out.print("\n$ ./{s}\n{s}{s}", .{ code.name, colored_stdout, colored_stderr });
1512 try shell_out.print("$ ./{s}\n{s}{s}", .{ code.name, colored_stdout, colored_stderr });
15151513 if (exited_with_signal) {
15161514 try shell_out.print("(process terminated by signal)", .{});
15171515 }
......@@ -1884,7 +1882,7 @@ test "shell parsed" {
18841882 \\$ zig build test.zig
18851883 ;
18861884 const expected =
1887 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig</kbd></span>
1885 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig</kbd>
18881886 \\</samp></pre></figure>
18891887 ;
18901888
......@@ -1892,7 +1890,6 @@ test "shell parsed" {
18921890 defer buffer.deinit();
18931891
18941892 try printShell(buffer.writer(), shell_out, false);
1895 std.log.emerg("{s}", .{buffer.items});
18961893 try testing.expectEqualSlices(u8, expected, buffer.items);
18971894 }
18981895 {
......@@ -1901,8 +1898,8 @@ test "shell parsed" {
19011898 \\build output
19021899 ;
19031900 const expected =
1904 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig</kbd></span>
1905 \\<span class="line">build output</span>
1901 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig</kbd>
1902 \\build output
19061903 \\</samp></pre></figure>
19071904 ;
19081905
......@@ -1919,9 +1916,9 @@ test "shell parsed" {
19191916 \\$ ./test
19201917 ;
19211918 const expected =
1922 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig</kbd></span>
1923 \\<span class="line">build output</span>
1924 \\<span class="line">$ <kbd>./test</kbd></span>
1919 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig</kbd>
1920 \\build output
1921 \\$ <kbd>./test</kbd>
19251922 \\</samp></pre></figure>
19261923 ;
19271924
......@@ -1939,10 +1936,10 @@ test "shell parsed" {
19391936 \\output
19401937 ;
19411938 const expected =
1942 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig</kbd></span>
1943 \\<span class="line"></span>
1944 \\<span class="line">$ <kbd>./test</kbd></span>
1945 \\<span class="line">output</span>
1939 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig</kbd>
1940 \\
1941 \\$ <kbd>./test</kbd>
1942 \\output
19461943 \\</samp></pre></figure>
19471944 ;
19481945
......@@ -1959,9 +1956,9 @@ test "shell parsed" {
19591956 \\output
19601957 ;
19611958 const expected =
1962 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig</kbd></span>
1963 \\<span class="line">$ <kbd>./test</kbd></span>
1964 \\<span class="line">output</span>
1959 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig</kbd>
1960 \\$ <kbd>./test</kbd>
1961 \\output
19651962 \\</samp></pre></figure>
19661963 ;
19671964
......@@ -1980,11 +1977,11 @@ test "shell parsed" {
19801977 \\output
19811978 ;
19821979 const expected =
1983 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig \</span>
1984 \\<span class="line"> --build-option</kbd></span>
1985 \\<span class="line">build output</span>
1986 \\<span class="line">$ <kbd>./test</kbd></span>
1987 \\<span class="line">output</span>
1980 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig \
1981 \\ --build-option</kbd>
1982 \\build output
1983 \\$ <kbd>./test</kbd>
1984 \\output
19881985 \\</samp></pre></figure>
19891986 ;
19901987
......@@ -1998,15 +1995,15 @@ test "shell parsed" {
19981995 // intentional space after "--build-option1 \"
19991996 const shell_out =
20001997 \\$ zig build test.zig \
2001 \\ --build-option1 \
1998 \\ --build-option1 \
20021999 \\ --build-option2
20032000 \\$ ./test
20042001 ;
20052002 const expected =
2006 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig \</span>
2007 \\<span class="line"> --build-option1 \</span>
2008 \\<span class="line"> --build-option2</kbd></span>
2009 \\<span class="line">$ <kbd>./test</kbd></span>
2003 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig \
2004 \\ --build-option1 \
2005 \\ --build-option2</kbd>
2006 \\$ <kbd>./test</kbd>
20102007 \\</samp></pre></figure>
20112008 ;
20122009
......@@ -2022,8 +2019,8 @@ test "shell parsed" {
20222019 \\$ ./test
20232020 ;
20242021 const expected =
2025 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig \</span>
2026 \\<span class="line">$ ./test</kbd></span>
2022 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig \
2023 \\$ ./test</kbd>
20272024 \\</samp></pre></figure>
20282025 ;
20292026
......@@ -2040,9 +2037,9 @@ test "shell parsed" {
20402037 \\$1
20412038 ;
20422039 const expected =
2043 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig</kbd></span>
2044 \\<span class="line">$ <kbd>./test</kbd></span>
2045 \\<span class="line">$1</span>
2040 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig</kbd>
2041 \\$ <kbd>./test</kbd>
2042 \\$1
20462043 \\</samp></pre></figure>
20472044 ;
20482045
......@@ -2057,7 +2054,7 @@ test "shell parsed" {
20572054 \\$zig build test.zig
20582055 ;
20592056 const expected =
2060 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$zig build test.zig</span>
2057 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$zig build test.zig
20612058 \\</samp></pre></figure>
20622059 ;
20632060