aboutsummaryrefslogtreecommitdiff
path: root/src/global.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-06-09 13:26:30 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-06-09 13:26:30 -0700
commitecda693e3844511644a177a0bcb146bda07effb9 (patch)
treee032597bdae3e8229a88042d1ae2b978ef63e056 /src/global.zig
parent6a4712f4c90ef7f1bb858ea81fe3d11ea60b036e (diff)
downloadbun-ecda693e3844511644a177a0bcb146bda07effb9.tar.gz
bun-ecda693e3844511644a177a0bcb146bda07effb9.tar.zst
bun-ecda693e3844511644a177a0bcb146bda07effb9.zip
lots
Former-commit-id: 7346cdaa5a32ade26821ed97ef07f7c9ae87c0c2
Diffstat (limited to 'src/global.zig')
-rw-r--r--src/global.zig39
1 files changed, 36 insertions, 3 deletions
diff --git a/src/global.zig b/src/global.zig
index bc0ab3ee3..6610abafd 100644
--- a/src/global.zig
+++ b/src/global.zig
@@ -104,6 +104,7 @@ pub const Output = struct {
}
pub fn disableBuffering() void {
+ Output.flush();
enable_buffering = false;
}
@@ -285,14 +286,18 @@ pub const Output = struct {
printer(new_fmt[0..new_fmt_i], args);
}
- pub fn pretty(comptime fmt: string, args: anytype) void {
+ pub fn prettyWithPrinter(comptime fmt: string, args: anytype, printer: anytype) void {
if (enable_ansi_colors) {
- _pretty(fmt, args, print, true);
+ _pretty(fmt, args, printer, true);
} else {
- _pretty(fmt, args, print, false);
+ _pretty(fmt, args, printer, false);
}
}
+ pub fn pretty(comptime fmt: string, args: anytype) void {
+ prettyWithPrinter(fmt, args, print);
+ }
+
pub fn prettyln(comptime fmt: string, args: anytype) void {
if (enable_ansi_colors) {
_pretty(fmt, args, println, true);
@@ -309,6 +314,26 @@ pub const Output = struct {
return printError(fmt, args);
}
+ pub fn prettyError(comptime fmt: string, args: anytype) void {
+ prettyWithPrinter(fmt, args, printError);
+ }
+
+ pub fn prettyErrorln(comptime fmt: string, args: anytype) void {
+ if (fmt[fmt.len - 1] != '\n') {
+ return prettyWithPrinter(
+ fmt ++ "\n",
+ args,
+ printError,
+ );
+ }
+
+ return prettyWithPrinter(
+ fmt,
+ args,
+ printError,
+ );
+ }
+
pub fn errorLn(comptime fmt: string, args: anytype) void {
return printErrorln(fmt, args);
}
@@ -329,8 +354,10 @@ pub const Global = struct {
pub fn panic(comptime fmt: string, args: anytype) noreturn {
if (isWasm) {
Output.print(fmt, args);
+ Output.flush();
@panic(fmt);
} else {
+ Output.flush();
std.debug.panic(fmt, args);
}
}
@@ -338,6 +365,12 @@ pub const Global = struct {
pub fn notimpl() noreturn {
Global.panic("Not implemented yet!!!!!", .{});
}
+
+ // Make sure we always print any leftover
+ pub fn crash() noreturn {
+ Output.flush();
+ std.os.exit(1);
+ }
};
pub const FileDescriptorType = if (isBrowser) u0 else std.os.fd_t;