authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2024-06-02 04:06:49-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-06-02 13:04:25-04:00
log2cf8e73781b81f38c50a40b42cad49242ef7c98b
treeaf8a1ad570f771d7f7ae9723eeac28d9540f5c71
parent5e1ccd96e5dcd2ed2d38d3260edcdd68b4b8da9d

Progress: Emit \r\n on Windows, include new line bytes in line_upper_bound_len

The \r\n is necessary to get the progress tree to work properly in the old console when ENABLE_VIRTUAL_TERMINAL_PROCESSING and DISABLE_NEWLINE_AUTO_RETURN are set. The line_upper_bound_len fix addresses part of #20161

1 files changed, 10 insertions(+), 1 deletions(-)

lib/std/Progress.zig+10-1
...@@ -1133,8 +1133,10 @@ fn computePrefix(...@@ -1133,8 +1133,10 @@ fn computePrefix(
1133 return i;1133 return i;
1134}1134}
11351135
1136// \r\n on Windows, \n otherwise.
1137const nl_len = if (is_windows) 2 else 1;
1136const line_upper_bound_len = @max(TreeSymbol.tee.maxByteLen(), TreeSymbol.langle.maxByteLen()) +1138const line_upper_bound_len = @max(TreeSymbol.tee.maxByteLen(), TreeSymbol.langle.maxByteLen()) +
1137 "[4294967296/4294967296] ".len + Node.max_name_len + (1 + up_one_line.len) + finish_sync.len;1139 "[4294967296/4294967296] ".len + Node.max_name_len + nl_len + (1 + up_one_line.len) + finish_sync.len;
11381140
1139fn computeNode(1141fn computeNode(
1140 buf: []u8,1142 buf: []u8,
...@@ -1183,6 +1185,13 @@ fn computeNode(...@@ -1183,6 +1185,13 @@ fn computeNode(
1183 }1185 }
11841186
1185 i = @min(global_progress.cols + start_i, i);1187 i = @min(global_progress.cols + start_i, i);
1188 if (is_windows) {
1189 // \r\n on Windows is necessary for the old console with the
1190 // ENABLE_VIRTUAL_TERMINAL_PROCESSING | DISABLE_NEWLINE_AUTO_RETURN
1191 // console modes set to behave properly.
1192 buf[i] = '\r';
1193 i += 1;
1194 }
1186 buf[i] = '\n';1195 buf[i] = '\n';
1187 i += 1;1196 i += 1;
1188 nl_n += 1;1197 nl_n += 1;