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