aboutsummaryrefslogtreecommitdiff
path: root/std/debug/index.zig
diff options
context:
space:
mode:
authoremekoi <emekankurumeh@outlook.com>2018-11-07 23:36:36 -0600
committerAndrew Kelley <superjoe30@gmail.com>2018-11-08 00:36:36 -0500
commit8e69a18d8c01aaf2bf4f0c0f8495e47cb36c284f (patch)
treec1b44cc9f694148f8ef25b752181c67d59705c15 /std/debug/index.zig
parentac8898e68150fc9cd2bc04ee6c4ef4d3005b8c27 (diff)
downloadzig-8e69a18d8c01aaf2bf4f0c0f8495e47cb36c284f.tar.gz
zig-8e69a18d8c01aaf2bf4f0c0f8495e47cb36c284f.zip
made colored output more consistent (#1706)
* made colored output more consistent * added os.supportsAnsiEscapeCodes
Diffstat (limited to 'std/debug/index.zig')
-rw-r--r--std/debug/index.zig87
1 files changed, 56 insertions, 31 deletions
diff --git a/std/debug/index.zig b/std/debug/index.zig
index 0508c17feb..a0d2f65339 100644
--- a/std/debug/index.zig
+++ b/std/debug/index.zig
@@ -171,7 +171,9 @@ pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, c
os.abort();
}
+const RED = "\x1b[31;1m";
const GREEN = "\x1b[32;1m";
+const CYAN = "\x1b[36;1m";
const WHITE = "\x1b[37;1m";
const DIM = "\x1b[2m";
const RESET = "\x1b[0m";
@@ -454,38 +456,61 @@ const TtyColor = enum.{
/// TODO this is a special case hack right now. clean it up and maybe make it part of std.fmt
fn setTtyColor(tty_color: TtyColor) void {
- const S = struct.{
- var attrs: windows.WORD = undefined;
- var init_attrs = false;
- };
- if (!S.init_attrs) {
- S.init_attrs = true;
- var info: windows.CONSOLE_SCREEN_BUFFER_INFO = undefined;
- // TODO handle error
- _ = windows.GetConsoleScreenBufferInfo(stderr_file.handle, &info);
- S.attrs = info.wAttributes;
- }
+ if (os.supportsAnsiEscapeCodes(stderr_file.handle)) {
+ switch (tty_color) {
+ TtyColor.Red => {
+ stderr_file.write(RED) catch return;
+ },
+ TtyColor.Green => {
+ stderr_file.write(GREEN) catch return;
+ },
+ TtyColor.Cyan => {
+ stderr_file.write(CYAN) catch return;
+ },
+ TtyColor.White, TtyColor.Bold => {
+ stderr_file.write(WHITE) catch return;
+ },
+ TtyColor.Dim => {
+ stderr_file.write(DIM) catch return;
+ },
+ TtyColor.Reset => {
+ stderr_file.write(RESET) catch return;
+ },
+ }
+ } else {
+ const S = struct.{
+ var attrs: windows.WORD = undefined;
+ var init_attrs = false;
+ };
+ if (!S.init_attrs) {
+ S.init_attrs = true;
+ var info: windows.CONSOLE_SCREEN_BUFFER_INFO = undefined;
+ // TODO handle error
+ _ = windows.GetConsoleScreenBufferInfo(stderr_file.handle, &info);
+ S.attrs = info.wAttributes;
+ }
- // TODO handle errors
- switch (tty_color) {
- TtyColor.Red => {
- _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_INTENSITY);
- },
- TtyColor.Green => {
- _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_INTENSITY);
- },
- TtyColor.Cyan => {
- _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY);
- },
- TtyColor.White, TtyColor.Bold => {
- _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY);
- },
- TtyColor.Dim => {
- _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_INTENSITY);
- },
- TtyColor.Reset => {
- _ = windows.SetConsoleTextAttribute(stderr_file.handle, S.attrs);
- },
+ // TODO handle errors
+ switch (tty_color) {
+ TtyColor.Red => {
+ _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_INTENSITY);
+ },
+ TtyColor.Green => {
+ _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_INTENSITY);
+ },
+ TtyColor.Cyan => {
+ _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY);
+ },
+ TtyColor.White, TtyColor.Bold => {
+ _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY);
+ },
+ TtyColor.Dim => {
+ _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_INTENSITY);
+ },
+ TtyColor.Reset => {
+ _ = windows.SetConsoleTextAttribute(stderr_file.handle, S.attrs);
+ },
+ }
}
}