| ... | ... | @@ -25,6 +25,13 @@ terminal: ?std.fs.File = undefined, |
| 25 | 25 | /// Whether the terminal supports ANSI escape codes. |
| 26 | 26 | supports_ansi_escape_codes: bool = false, |
| 27 | 27 | |
| 28 | /// If the terminal is "dumb", don't print output. |
| 29 | /// This can be useful if you don't want to print all |
| 30 | /// the stages of code generation if there are a lot. |
| 31 | /// You should not use it if the user should see output |
| 32 | /// for example showing the user what tests run. |
| 33 | dont_print_on_dumb: bool = false, |
| 34 | |
| 28 | 35 | root: Node = undefined, |
| 29 | 36 | |
| 30 | 37 | /// Keeps track of how much time has passed since the beginning. |
| ... | ... | @@ -141,6 +148,9 @@ pub fn start(self: *Progress, name: []const u8, estimated_total_items: usize) !* |
| 141 | 148 | self.supports_ansi_escape_codes = true; |
| 142 | 149 | } else if (std.builtin.os.tag == .windows and stderr.isTty()) { |
| 143 | 150 | self.terminal = stderr; |
| 151 | } else if (std.builtin.os.tag != .windows) { |
| 152 | // we are in a "dumb" terminal like in acme or writing to a file |
| 153 | self.terminal = stderr; |
| 144 | 154 | } |
| 145 | 155 | self.root = Node{ |
| 146 | 156 | .context = self, |
| ... | ... | @@ -178,6 +188,8 @@ pub fn refresh(self: *Progress) void { |
| 178 | 188 | } |
| 179 | 189 | |
| 180 | 190 | fn refreshWithHeldLock(self: *Progress) void { |
| 191 | const is_dumb = !self.supports_ansi_escape_codes and !(std.builtin.os.tag == .windows); |
| 192 | if (is_dumb and self.dont_print_on_dumb) return; |
| 181 | 193 | const file = self.terminal orelse return; |
| 182 | 194 | |
| 183 | 195 | const prev_columns_written = self.columns_written; |
| ... | ... | @@ -226,7 +238,11 @@ fn refreshWithHeldLock(self: *Progress) void { |
| 226 | 238 | |
| 227 | 239 | if (windows.kernel32.SetConsoleCursorPosition(file.handle, cursor_pos) != windows.TRUE) |
| 228 | 240 | unreachable; |
| 229 | | } else unreachable; |
| 241 | } else { |
| 242 | // we are in a "dumb" terminal like in acme or writing to a file |
| 243 | self.output_buffer[end] = '\n'; |
| 244 | end += 1; |
| 245 | } |
| 230 | 246 | |
| 231 | 247 | self.columns_written = 0; |
| 232 | 248 | } |