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 {...@@ -1224,41 +1224,39 @@ fn printShell(out: anytype, shell_content: []const u8, escape: bool) !void {
1224 while (iter.next()) |orig_line| {1224 while (iter.next()) |orig_line| {
1225 const line = mem.trimRight(u8, orig_line, " ");1225 const line = mem.trimRight(u8, orig_line, " ");
1226 if (!cmd_cont and line.len > 1 and mem.eql(u8, line[0..2], "$ ") and line[line.len - 1] != '\\') {1226 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>");
1228 const s = std.mem.trimLeft(u8, line[1..], " ");1228 const s = std.mem.trimLeft(u8, line[1..], " ");
1229 if (escape) {1229 if (escape) {
1230 try writeEscaped(out, s);1230 try writeEscaped(out, s);
1231 } else {1231 } else {
1232 try out.writeAll(s);1232 try out.writeAll(s);
1233 }1233 }
1234 try out.writeAll("</kbd>" ++ end_line ++ "\n");1234 try out.writeAll("</kbd>" ++ "\n");
1235 } else if (!cmd_cont and line.len > 1 and mem.eql(u8, line[0..2], "$ ") and line[line.len - 1] == '\\') {1235 } 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>");
1237 const s = std.mem.trimLeft(u8, line[1..], " ");1237 const s = std.mem.trimLeft(u8, line[1..], " ");
1238 if (escape) {1238 if (escape) {
1239 try writeEscaped(out, s);1239 try writeEscaped(out, s);
1240 } else {1240 } else {
1241 try out.writeAll(s);1241 try out.writeAll(s);
1242 }1242 }
1243 try out.writeAll(end_line ++ "\n");1243 try out.writeAll("\n");
1244 cmd_cont = true;1244 cmd_cont = true;
1245 } else if (line.len > 0 and line[line.len - 1] != '\\' and cmd_cont) {1245 } else if (line.len > 0 and line[line.len - 1] != '\\' and cmd_cont) {
1246 try out.writeAll(start_line);
1247 if (escape) {1246 if (escape) {
1248 try writeEscaped(out, line);1247 try writeEscaped(out, line);
1249 } else {1248 } else {
1250 try out.writeAll(line);1249 try out.writeAll(line);
1251 }1250 }
1252 try out.writeAll("</kbd>" ++ end_line ++ "\n");1251 try out.writeAll("</kbd>" ++ "\n");
1253 cmd_cont = false;1252 cmd_cont = false;
1254 } else {1253 } else {
1255 try out.writeAll(start_line);
1256 if (escape) {1254 if (escape) {
1257 try writeEscaped(out, line);1255 try writeEscaped(out, line);
1258 } else {1256 } else {
1259 try out.writeAll(line);1257 try out.writeAll(line);
1260 }1258 }
1261 try out.writeAll(end_line ++ "\n");1259 try out.writeAll("\n");
1262 }1260 }
1263 }1261 }
12641262
...@@ -1511,7 +1509,7 @@ fn genHtml(...@@ -1511,7 +1509,7 @@ fn genHtml(
1511 const colored_stderr = try termColor(allocator, escaped_stderr);1509 const colored_stderr = try termColor(allocator, escaped_stderr);
1512 const colored_stdout = try termColor(allocator, escaped_stdout);1510 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 });
1515 if (exited_with_signal) {1513 if (exited_with_signal) {
1516 try shell_out.print("(process terminated by signal)", .{});1514 try shell_out.print("(process terminated by signal)", .{});
1517 }1515 }
...@@ -1884,7 +1882,7 @@ test "shell parsed" {...@@ -1884,7 +1882,7 @@ test "shell parsed" {
1884 \\$ zig build test.zig1882 \\$ zig build test.zig
1885 ;1883 ;
1886 const expected =1884 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>
1888 \\</samp></pre></figure>1886 \\</samp></pre></figure>
1889 ;1887 ;
18901888
...@@ -1892,7 +1890,6 @@ test "shell parsed" {...@@ -1892,7 +1890,6 @@ test "shell parsed" {
1892 defer buffer.deinit();1890 defer buffer.deinit();
18931891
1894 try printShell(buffer.writer(), shell_out, false);1892 try printShell(buffer.writer(), shell_out, false);
1895 std.log.emerg("{s}", .{buffer.items});
1896 try testing.expectEqualSlices(u8, expected, buffer.items);1893 try testing.expectEqualSlices(u8, expected, buffer.items);
1897 }1894 }
1898 {1895 {
...@@ -1901,8 +1898,8 @@ test "shell parsed" {...@@ -1901,8 +1898,8 @@ test "shell parsed" {
1901 \\build output1898 \\build output
1902 ;1899 ;
1903 const expected =1900 const expected =
1904 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig</kbd></span>1901 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig</kbd>
1905 \\<span class="line">build output</span>1902 \\build output
1906 \\</samp></pre></figure>1903 \\</samp></pre></figure>
1907 ;1904 ;
19081905
...@@ -1919,9 +1916,9 @@ test "shell parsed" {...@@ -1919,9 +1916,9 @@ test "shell parsed" {
1919 \\$ ./test1916 \\$ ./test
1920 ;1917 ;
1921 const expected =1918 const expected =
1922 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig</kbd></span>1919 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig</kbd>
1923 \\<span class="line">build output</span>1920 \\build output
1924 \\<span class="line">$ <kbd>./test</kbd></span>1921 \\$ <kbd>./test</kbd>
1925 \\</samp></pre></figure>1922 \\</samp></pre></figure>
1926 ;1923 ;
19271924
...@@ -1939,10 +1936,10 @@ test "shell parsed" {...@@ -1939,10 +1936,10 @@ test "shell parsed" {
1939 \\output1936 \\output
1940 ;1937 ;
1941 const expected =1938 const expected =
1942 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig</kbd></span>1939 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig</kbd>
1943 \\<span class="line"></span>1940 \\
1944 \\<span class="line">$ <kbd>./test</kbd></span>1941 \\$ <kbd>./test</kbd>
1945 \\<span class="line">output</span>1942 \\output
1946 \\</samp></pre></figure>1943 \\</samp></pre></figure>
1947 ;1944 ;
19481945
...@@ -1959,9 +1956,9 @@ test "shell parsed" {...@@ -1959,9 +1956,9 @@ test "shell parsed" {
1959 \\output1956 \\output
1960 ;1957 ;
1961 const expected =1958 const expected =
1962 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig</kbd></span>1959 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig</kbd>
1963 \\<span class="line">$ <kbd>./test</kbd></span>1960 \\$ <kbd>./test</kbd>
1964 \\<span class="line">output</span>1961 \\output
1965 \\</samp></pre></figure>1962 \\</samp></pre></figure>
1966 ;1963 ;
19671964
...@@ -1980,11 +1977,11 @@ test "shell parsed" {...@@ -1980,11 +1977,11 @@ test "shell parsed" {
1980 \\output1977 \\output
1981 ;1978 ;
1982 const expected =1979 const expected =
1983 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig \</span>1980 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig \
1984 \\<span class="line"> --build-option</kbd></span>1981 \\ --build-option</kbd>
1985 \\<span class="line">build output</span>1982 \\build output
1986 \\<span class="line">$ <kbd>./test</kbd></span>1983 \\$ <kbd>./test</kbd>
1987 \\<span class="line">output</span>1984 \\output
1988 \\</samp></pre></figure>1985 \\</samp></pre></figure>
1989 ;1986 ;
19901987
...@@ -1998,15 +1995,15 @@ test "shell parsed" {...@@ -1998,15 +1995,15 @@ test "shell parsed" {
1998 // intentional space after "--build-option1 \"1995 // intentional space after "--build-option1 \"
1999 const shell_out =1996 const shell_out =
2000 \\$ zig build test.zig \1997 \\$ zig build test.zig \
2001 \\ --build-option1 \1998 \\ --build-option1 \
2002 \\ --build-option21999 \\ --build-option2
2003 \\$ ./test2000 \\$ ./test
2004 ;2001 ;
2005 const expected =2002 const expected =
2006 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig \</span>2003 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig \
2007 \\<span class="line"> --build-option1 \</span>2004 \\ --build-option1 \
2008 \\<span class="line"> --build-option2</kbd></span>2005 \\ --build-option2</kbd>
2009 \\<span class="line">$ <kbd>./test</kbd></span>2006 \\$ <kbd>./test</kbd>
2010 \\</samp></pre></figure>2007 \\</samp></pre></figure>
2011 ;2008 ;
20122009
...@@ -2022,8 +2019,8 @@ test "shell parsed" {...@@ -2022,8 +2019,8 @@ test "shell parsed" {
2022 \\$ ./test2019 \\$ ./test
2023 ;2020 ;
2024 const expected =2021 const expected =
2025 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig \</span>2022 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig \
2026 \\<span class="line">$ ./test</kbd></span>2023 \\$ ./test</kbd>
2027 \\</samp></pre></figure>2024 \\</samp></pre></figure>
2028 ;2025 ;
20292026
...@@ -2040,9 +2037,9 @@ test "shell parsed" {...@@ -2040,9 +2037,9 @@ test "shell parsed" {
2040 \\$12037 \\$1
2041 ;2038 ;
2042 const expected =2039 const expected =
2043 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp><span class="line">$ <kbd>zig build test.zig</kbd></span>2040 \\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig</kbd>
2044 \\<span class="line">$ <kbd>./test</kbd></span>2041 \\$ <kbd>./test</kbd>
2045 \\<span class="line">$1</span>2042 \\$1
2046 \\</samp></pre></figure>2043 \\</samp></pre></figure>
2047 ;2044 ;
20482045
...@@ -2057,7 +2054,7 @@ test "shell parsed" {...@@ -2057,7 +2054,7 @@ test "shell parsed" {
2057 \\$zig build test.zig2054 \\$zig build test.zig
2058 ;2055 ;
2059 const expected =2056 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
2061 \\</samp></pre></figure>2058 \\</samp></pre></figure>
2062 ;2059 ;
20632060