diff options
author | 2022-03-10 06:55:43 -0800 | |
---|---|---|
committer | 2022-03-10 06:55:43 -0800 | |
commit | c8f6337f1f9f22b48286c8bed1e47d44f0657cd0 (patch) | |
tree | 76ed59b14346365ff756bac2d4f491a310d633e7 | |
parent | 7998a43b048d0da8b979248cffa7e1e9344fc27b (diff) | |
download | bun-c8f6337f1f9f22b48286c8bed1e47d44f0657cd0.tar.gz bun-c8f6337f1f9f22b48286c8bed1e47d44f0657cd0.tar.zst bun-c8f6337f1f9f22b48286c8bed1e47d44f0657cd0.zip |
twiddle with formatting
-rw-r--r-- | src/javascript/jsc/bindings/exports.zig | 58 | ||||
-rw-r--r-- | src/javascript/jsc/javascript.zig | 60 | ||||
-rw-r--r-- | src/output.zig | 1 |
3 files changed, 89 insertions, 30 deletions
diff --git a/src/javascript/jsc/bindings/exports.zig b/src/javascript/jsc/bindings/exports.zig index 2963caa7a..75a7c96be 100644 --- a/src/javascript/jsc/bindings/exports.zig +++ b/src/javascript/jsc/bindings/exports.zig @@ -511,6 +511,11 @@ pub const ZigStackFrame = extern struct { root_path: string = "", pub fn format(this: SourceURLFormatter, comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void { + if (this.enable_color) { + try writer.writeAll(Output.prettyFmt("<r><cyan>", true)); + } + + var source_slice = this.source_url.slice(); if (this.origin) |origin| { try writer.writeAll(origin.displayProtocol()); try writer.writeAll("://"); @@ -518,20 +523,47 @@ pub const ZigStackFrame = extern struct { try writer.writeAll(":"); try writer.writeAll(origin.port); try writer.writeAll("/blob:"); - } - var source_slice = this.source_url.slice(); - if (strings.startsWith(source_slice, this.root_path)) { - source_slice = source_slice[this.root_path.len..]; + if (strings.startsWith(source_slice, this.root_path)) { + source_slice = source_slice[this.root_path.len..]; + } } try writer.writeAll(source_slice); + + if (this.enable_color) { + if (this.position.line > -1) { + try writer.writeAll(comptime Output.prettyFmt("<r>", true)); + } else { + try writer.writeAll(comptime Output.prettyFmt("<r>", true)); + } + } + if (this.position.line > -1 and this.position.column_start > -1) { - try std.fmt.format(writer, ":{d}:{d}", .{ this.position.line + 1, this.position.column_start }); + if (this.enable_color) { + try std.fmt.format( + writer, + // : + comptime Output.prettyFmt("<d>:<r><yellow>{d}<r><d>:<yellow>{d}<r>", true), + .{ this.position.line + 1, this.position.column_start }, + ); + } else { + try std.fmt.format(writer, ":{d}:{d}", .{ this.position.line + 1, this.position.column_start }); + } } else if (this.position.line > -1) { - try std.fmt.format(writer, ":{d}", .{ - this.position.line + 1, - }); + if (this.enable_color) { + try std.fmt.format( + writer, + comptime Output.prettyFmt("<d>:<r><yellow>{d}<r>", true), + .{ + this.position.line + 1, + }, + ); + } else { + try std.fmt.format(writer, ":{d}", .{ + this.position.line + 1, + }); + } } } }; @@ -549,13 +581,15 @@ pub const ZigStackFrame = extern struct { try writer.writeAll("(eval)"); }, .Module => { - try writer.writeAll("(esm)"); + // try writer.writeAll("(esm)"); }, .Function => { if (name.len > 0) { - try std.fmt.format(writer, "{s}", .{name}); - } else { - try writer.writeAll("(anonymous)"); + if (this.enable_color) { + try std.fmt.format(writer, comptime Output.prettyFmt("<r><b><i>{s}<r>", true), .{name}); + } else { + try std.fmt.format(writer, "{s}", .{name}); + } } }, .Global => { diff --git a/src/javascript/jsc/javascript.zig b/src/javascript/jsc/javascript.zig index e1065f53b..36c8174ad 100644 --- a/src/javascript/jsc/javascript.zig +++ b/src/javascript/jsc/javascript.zig @@ -3050,22 +3050,42 @@ pub const VirtualMachine = struct { const func = frame.function_name.slice(); if (file.len == 0 and func.len == 0) continue; - try writer.print( - comptime Output.prettyFmt( - "<r> <d>at <r>{any} <d>(<r>{any}<d>)<r>\n", - allow_ansi_colors, - ), - .{ - frame.nameFormatter( + const has_name = std.fmt.count("{any}", .{frame.nameFormatter( + false, + )}) > 0; + + if (has_name) { + try writer.print( + comptime Output.prettyFmt( + "<r> <d>at <r>{any}<d> (<r>{any}<d>)<r>\n", allow_ansi_colors, ), - frame.sourceURLFormatter( - dir, - origin, + .{ + frame.nameFormatter( + allow_ansi_colors, + ), + frame.sourceURLFormatter( + dir, + origin, + allow_ansi_colors, + ), + }, + ); + } else { + try writer.print( + comptime Output.prettyFmt( + "<r> <d>at <r>{any}\n", allow_ansi_colors, ), - }, - ); + .{ + frame.sourceURLFormatter( + dir, + origin, + allow_ansi_colors, + ), + }, + ); + } } } } @@ -3158,7 +3178,11 @@ pub const VirtualMachine = struct { ) catch unreachable; } - const name = exception.name; + var name = exception.name; + if (strings.eqlComptime(exception.name.slice(), "Error")) { + name = ZigString.init("error"); + } + const message = exception.message; var did_print_name = false; if (source_lines.next()) |source| { @@ -3177,7 +3201,7 @@ pub const VirtualMachine = struct { ) catch unreachable; if (name.len > 0 and message.len > 0) { - writer.print(comptime Output.prettyFmt(" <r><red><b>{}<r><d>:<r> <b>{}<r>\n", allow_ansi_color), .{ + writer.print(comptime Output.prettyFmt(" <r><red>{}<r><d>:<r> <b>{}<r>\n", allow_ansi_color), .{ name, message, }) catch unreachable; @@ -3232,7 +3256,7 @@ pub const VirtualMachine = struct { } if (name.len > 0 and message.len > 0) { - writer.print(comptime Output.prettyFmt(" <r><red><b>{s}<r><d>:<r> <b>{s}<r>\n", allow_ansi_color), .{ + writer.print(comptime Output.prettyFmt(" <r><red>{s}<r><d>:<r> <b>{s}<r>\n", allow_ansi_color), .{ name, message, }) catch unreachable; @@ -3246,14 +3270,14 @@ pub const VirtualMachine = struct { if (!did_print_name) { if (name.len > 0 and message.len > 0) { - writer.print(comptime Output.prettyFmt("<r><red><b>{s}<r><d>:<r> <b>{s}<r>\n", true), .{ + writer.print(comptime Output.prettyFmt("<r><red>{s}<r><d>:<r> <b>{s}<r>\n", true), .{ name, message, }) catch unreachable; } else if (name.len > 0) { - writer.print(comptime Output.prettyFmt("<r><b>{s}<r>\n", true), .{name}) catch unreachable; + writer.print(comptime Output.prettyFmt("<r>{s}<r>\n", true), .{name}) catch unreachable; } else if (message.len > 0) { - writer.print(comptime Output.prettyFmt("<r><b>{s}<r>\n", true), .{name}) catch unreachable; + writer.print(comptime Output.prettyFmt("<r>{s}<r>\n", true), .{name}) catch unreachable; } } diff --git a/src/output.zig b/src/output.zig index e4efc423d..8466b88a1 100644 --- a/src/output.zig +++ b/src/output.zig @@ -354,6 +354,7 @@ pub const color_map = ComptimeStringMap(string, .{ &.{ "blue", ED ++ "34m" }, &.{ "b", ED ++ "1m" }, &.{ "d", ED ++ "2m" }, + &.{ "i", ED ++ "3m" }, &.{ "cyan", ED ++ "36m" }, &.{ "green", ED ++ "32m" }, &.{ "magenta", ED ++ "35m" }, |