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 {...@@ -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,
1515
16 /// Whether the terminal supports ANSI escape codes.
17 supports_ansi_escape_codes: bool = false,
18
16 root: Node = undefined,19 root: Node = undefined,
1720
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 cursor142 // restore the cursor position by moving the cursor
139 // `columns_written` cells to the left, then clear the rest of the143 // `columns_written` cells to the left, then clear the rest of the
140 // line144 // 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;