authorgravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2020-04-29 19:49:02+03:00
committergravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2020-04-29 19:49:02+03:00
log273d2de099491278e7248b791f36395ab1a2e11a
tree73b826135ca21152171922685a36cfe7ab564701
parent15141d865abda09c09d8f6e3385f127527c5232e

Progress will now use ANSI escape codes on windows for terminals that support it


1 files changed, 6 insertions(+), 2 deletions(-)

lib/std/progress.zig+6-2
......@@ -13,6 +13,9 @@ pub const Progress = struct {
1313 /// not print on update()
1414 terminal: ?std.fs.File = undefined,
1515
16 /// Whether the terminal supports ANSI escape codes.
17 supports_ansi_escape_codes: bool = false,
18
1619 root: Node = undefined,
1720
1821 /// Keeps track of how much time has passed since the beginning.
......@@ -103,6 +106,7 @@ pub const Progress = struct {
103106 self.terminal = null;
104107 if (stderr.supportsAnsiEscapeCodes()) {
105108 self.terminal = stderr;
109 self.supports_ansi_escape_codes = true;
106110 } else if (std.builtin.os.tag == .windows and stderr.isTty()) {
107111 self.terminal = stderr;
108112 }
......@@ -138,10 +142,10 @@ pub const Progress = struct {
138142 // restore the cursor position by moving the cursor
139143 // `columns_written` cells to the left, then clear the rest of the
140144 // line
141 if (std.builtin.os.tag != .windows) {
145 if (self.supports_ansi_escape_codes) {
142146 end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[{}D", .{self.columns_written}) catch unreachable).len;
143147 end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[0K", .{}) catch unreachable).len;
144 } else {
148 } else if (std.builtin.os.tag == .windows) {
145149 var info: windows.CONSOLE_SCREEN_BUFFER_INFO = undefined;
146150 if (windows.kernel32.GetConsoleScreenBufferInfo(file.handle, &info) != windows.TRUE)
147151 unreachable;