diff options
author | 2023-02-24 15:53:26 +0200 | |
---|---|---|
committer | 2023-02-24 05:53:26 -0800 | |
commit | e887a064fb63347b4a4b21c282c1db01dfee98b1 (patch) | |
tree | 6270a7ce5527ea06d709d4b92e14623518e0f5b5 /src/output.zig | |
parent | 6e4908e51793d82d3b6924b2ede9a02f1e95bf37 (diff) | |
download | bun-e887a064fb63347b4a4b21c282c1db01dfee98b1.tar.gz bun-e887a064fb63347b4a4b21c282c1db01dfee98b1.tar.zst bun-e887a064fb63347b4a4b21c282c1db01dfee98b1.zip |
prefer `bun.copy()` over `std.mem.copy()` (#2152)
Diffstat (limited to 'src/output.zig')
-rw-r--r-- | src/output.zig | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/src/output.zig b/src/output.zig index e46e824e0..cb57343ad 100644 --- a/src/output.zig +++ b/src/output.zig @@ -419,7 +419,7 @@ pub fn scoped(comptime tag: @Type(.EnumLiteral), comptime disabled: bool) _log_f }.log; } -// Valid colors: +// Valid "colors": // <black> // <blue> // <cyan> @@ -432,7 +432,7 @@ pub fn scoped(comptime tag: @Type(.EnumLiteral), comptime disabled: bool) _log_f // <d> - dim // </r> - reset // <r> - reset -pub const ED = "\x1b["; +const ED = "\x1b["; pub const color_map = ComptimeStringMap(string, .{ &.{ "black", ED ++ "30m" }, &.{ "blue", ED ++ "34m" }, @@ -446,7 +446,7 @@ pub const color_map = ComptimeStringMap(string, .{ &.{ "white", ED ++ "37m" }, &.{ "yellow", ED ++ "33m" }, }); -pub const RESET = "\x1b[0m"; +const RESET: string = "\x1b[0m"; pub fn prettyFmt(comptime fmt: string, comptime is_enabled: bool) string { comptime var new_fmt: [fmt.len * 4]u8 = undefined; comptime var new_fmt_i: usize = 0; @@ -505,20 +505,11 @@ pub fn prettyFmt(comptime fmt: string, comptime is_enabled: bool) string { @compileError("Invalid color name passed: " ++ color_name); } }; - var orig = new_fmt_i; if (is_enabled) { - if (!is_reset) { - orig = new_fmt_i; - new_fmt_i += color_str.len; - std.mem.copy(u8, new_fmt[orig..new_fmt_i], color_str); - } - - if (is_reset) { - const reset_sequence = RESET; - orig = new_fmt_i; - new_fmt_i += reset_sequence.len; - std.mem.copy(u8, new_fmt[orig..new_fmt_i], reset_sequence); + for (if (is_reset) RESET else color_str) |ch| { + new_fmt[new_fmt_i] = ch; + new_fmt_i += 1; } } }, |