| ... | @@ -171,7 +171,9 @@ pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, c | ... | @@ -171,7 +171,9 @@ pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, c |
| 171 | os.abort(); | 171 | os.abort(); |
| 172 | } | 172 | } |
| 173 | | 173 | |
| | 174 | const RED = "\x1b[31;1m"; |
| 174 | const GREEN = "\x1b[32;1m"; | 175 | const GREEN = "\x1b[32;1m"; |
| | 176 | const CYAN = "\x1b[36;1m"; |
| 175 | const WHITE = "\x1b[37;1m"; | 177 | const WHITE = "\x1b[37;1m"; |
| 176 | const DIM = "\x1b[2m"; | 178 | const DIM = "\x1b[2m"; |
| 177 | const RESET = "\x1b[0m"; | 179 | const RESET = "\x1b[0m"; |
| ... | @@ -454,38 +456,61 @@ const TtyColor = enum.{ | ... | @@ -454,38 +456,61 @@ const TtyColor = enum.{ |
| 454 | | 456 | |
| 455 | /// TODO this is a special case hack right now. clean it up and maybe make it part of std.fmt | 457 | /// TODO this is a special case hack right now. clean it up and maybe make it part of std.fmt |
| 456 | fn setTtyColor(tty_color: TtyColor) void { | 458 | fn setTtyColor(tty_color: TtyColor) void { |
| 457 | const S = struct.{ | 459 | if (os.supportsAnsiEscapeCodes(stderr_file.handle)) { |
| 458 | var attrs: windows.WORD = undefined; | 460 | switch (tty_color) { |
| 459 | var init_attrs = false; | 461 | TtyColor.Red => { |
| 460 | }; | 462 | stderr_file.write(RED) catch return; |
| 461 | if (!S.init_attrs) { | 463 | }, |
| 462 | S.init_attrs = true; | 464 | TtyColor.Green => { |
| 463 | var info: windows.CONSOLE_SCREEN_BUFFER_INFO = undefined; | 465 | stderr_file.write(GREEN) catch return; |
| 464 | // TODO handle error | 466 | }, |
| 465 | _ = windows.GetConsoleScreenBufferInfo(stderr_file.handle, &info); | 467 | TtyColor.Cyan => { |
| 466 | S.attrs = info.wAttributes; | 468 | stderr_file.write(CYAN) catch return; |
| 467 | } | 469 | }, |
| | 470 | TtyColor.White, TtyColor.Bold => { |
| | 471 | stderr_file.write(WHITE) catch return; |
| | 472 | }, |
| | 473 | TtyColor.Dim => { |
| | 474 | stderr_file.write(DIM) catch return; |
| | 475 | }, |
| | 476 | TtyColor.Reset => { |
| | 477 | stderr_file.write(RESET) catch return; |
| | 478 | }, |
| | 479 | } |
| | 480 | } else { |
| | 481 | const S = struct.{ |
| | 482 | var attrs: windows.WORD = undefined; |
| | 483 | var init_attrs = false; |
| | 484 | }; |
| | 485 | if (!S.init_attrs) { |
| | 486 | S.init_attrs = true; |
| | 487 | var info: windows.CONSOLE_SCREEN_BUFFER_INFO = undefined; |
| | 488 | // TODO handle error |
| | 489 | _ = windows.GetConsoleScreenBufferInfo(stderr_file.handle, &info); |
| | 490 | S.attrs = info.wAttributes; |
| | 491 | } |
| 468 | | 492 | |
| 469 | // TODO handle errors | 493 | // TODO handle errors |
| 470 | switch (tty_color) { | 494 | switch (tty_color) { |
| 471 | TtyColor.Red => { | 495 | TtyColor.Red => { |
| 472 | _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_INTENSITY); | 496 | _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_INTENSITY); |
| 473 | }, | 497 | }, |
| 474 | TtyColor.Green => { | 498 | TtyColor.Green => { |
| 475 | _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_INTENSITY); | 499 | _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_INTENSITY); |
| 476 | }, | 500 | }, |
| 477 | TtyColor.Cyan => { | 501 | TtyColor.Cyan => { |
| 478 | _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY); | 502 | _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY); |
| 479 | }, | 503 | }, |
| 480 | TtyColor.White, TtyColor.Bold => { | 504 | TtyColor.White, TtyColor.Bold => { |
| 481 | _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY); | 505 | _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY); |
| 482 | }, | 506 | }, |
| 483 | TtyColor.Dim => { | 507 | TtyColor.Dim => { |
| 484 | _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_INTENSITY); | 508 | _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_INTENSITY); |
| 485 | }, | 509 | }, |
| 486 | TtyColor.Reset => { | 510 | TtyColor.Reset => { |
| 487 | _ = windows.SetConsoleTextAttribute(stderr_file.handle, S.attrs); | 511 | _ = windows.SetConsoleTextAttribute(stderr_file.handle, S.attrs); |
| 488 | }, | 512 | }, |
| | 513 | } |
| 489 | } | 514 | } |
| 490 | } | 515 | } |
| 491 | | 516 | |