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