| ... | ... | @@ -13,6 +13,9 @@ pub const Progress = struct { |
| 13 | 13 | /// not print on update() |
| 14 | 14 | terminal: ?std.fs.File = undefined, |
| 15 | 15 | |
| 16 | /// Whether the terminal supports ANSI escape codes. |
| 17 | supports_ansi_escape_codes: bool = false, |
| 18 | |
| 16 | 19 | root: Node = undefined, |
| 17 | 20 | |
| 18 | 21 | /// Keeps track of how much time has passed since the beginning. |
| ... | ... | @@ -103,6 +106,7 @@ pub const Progress = struct { |
| 103 | 106 | self.terminal = null; |
| 104 | 107 | if (stderr.supportsAnsiEscapeCodes()) { |
| 105 | 108 | self.terminal = stderr; |
| 109 | self.supports_ansi_escape_codes = true; |
| 106 | 110 | } else if (std.builtin.os.tag == .windows and stderr.isTty()) { |
| 107 | 111 | self.terminal = stderr; |
| 108 | 112 | } |
| ... | ... | @@ -138,10 +142,10 @@ pub const Progress = struct { |
| 138 | 142 | // restore the cursor position by moving the cursor |
| 139 | 143 | // `columns_written` cells to the left, then clear the rest of the |
| 140 | 144 | // line |
| 141 | | if (std.builtin.os.tag != .windows) { |
| 145 | if (self.supports_ansi_escape_codes) { |
| 142 | 146 | end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[{}D", .{self.columns_written}) catch unreachable).len; |
| 143 | 147 | end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[0K", .{}) catch unreachable).len; |
| 144 | | } else { |
| 148 | } else if (std.builtin.os.tag == .windows) { |
| 145 | 149 | var info: windows.CONSOLE_SCREEN_BUFFER_INFO = undefined; |
| 146 | 150 | if (windows.kernel32.GetConsoleScreenBufferInfo(file.handle, &info) != windows.TRUE) |
| 147 | 151 | unreachable; |
| ... | ... | @@ -174,7 +178,7 @@ pub const Progress = struct { |
| 174 | 178 | |
| 175 | 179 | if (windows.kernel32.SetConsoleCursorPosition(file.handle, cursor_pos) != windows.TRUE) |
| 176 | 180 | unreachable; |
| 177 | | } |
| 181 | } else unreachable; |
| 178 | 182 | |
| 179 | 183 | self.columns_written = 0; |
| 180 | 184 | } |