Skip to main content

Crate bun_output

Crate bun_output 

Source

Modules§

ansi
Named ANSI SGR escape sequences. One canonical literal per colour/attribute; every other crate aliases this module rather than re-declaring the bytes.
ansi_b
Byte-slice views of ansi for callers that write into &[u8] buffers (md ANSI renderer, stack-frame colour codes). str::as_bytes is a const fn, so each constant is the same static storage as its &str twin — no second copy of the escape bytes is emitted.
color_map
Lowercase lookup wrapper (Zig: Output.color_map.get(name)). The table itself lives in bun_output_tags (shared with the pretty_fmt! proc-macro so there is exactly one copy); this fn-module mirrors the Zig ComptimeStringMap .get() surface.
debug
Port of the std.debug subset Zig used: SourceLocation/SymbolInfo and the frame-pointer stack unwinder (@frameAddress, MemoryAccessor, StackIterator). Lives in bun_core (libc/std/bun_alloc only) so the crash handler, StoredTrace, and btjs can all share one implementation.
scoped_debug_writer
source
bun.Output.Source.Stdio.restore — restore terminal to cooked mode on exit. Thin alias over crate::output::stdio::restore (the real impl, also in this crate); the indirection exists only because Zig spells the path both Output.Source.Stdio.restore and Output.Stdio.restore.
stdio

Macros§

debug
Print to stdout, but only in debug builds. Text automatically buffers
declare_scope
Declare a scoped logger. Expands to a static SCOPE: ScopedLogger.
define_scoped_log
Declare a scoped logger static and a local forwarding macro in one shot. Replaces the per-file declare_scope!(X, vis); macro_rules! log { … } boilerplate.
pretty_fmt
pretty_fmt!("<red>hi {s}<r>", true)"\u{1b}[31mhi {}\u{1b}[0m" pretty_fmt!("<red>hi {s}<r>", false)"hi {}"
println
Print to stdout This will appear in the terminal, including in production. Text automatically buffers
scoped_log
bun.Output.scoped(.X, vis)("fmt", .{args})scoped_log!(X, "fmt", args...)

Structs§

BufferedStdin
bun.deprecated.BufferedReader(4096, File.Reader) over the process stdin. Layout is local to bun_core; bun_sys never casts into this (it only fills .fd during Windows startup).
DebugTimer
DisableBufferingScope
RAII: disable_buffering() now, enable_buffering() on drop. Covers the Zig Output.disableBuffering(); defer Output.enableBuffering(); pair used around child-process exec where the child writes directly to inherited stdio and Bun’s buffer must not interleave.
ElapsedFormatter
EnableBufferingScope
File
Opaque file handle. Replaces bun_sys::File in this crate. repr matches bun_sys::File (transparent over a single Fd).
FlushGuard
RAII guard that calls flush on Drop.
OutputSink
PrettyBuf
Owned ANSI-rewritten buffer; derefs to [u8] so it can be passed to write_all(&buf) directly, and implements Display so it can be used in write!(w, "{}", pretty_fmt::<true>("…")).
QuietWriter
Opaque handle to a bun_sys::file::QuietWriter. bun_core treats it as a POD blob; bun_sys casts back to the concrete type. TODO(port): bun_sys::file::QuietWriter — size/align must match.
QuietWriterAdapter
Opaque adapter wrapping a QuietWriter and exposing crate::io::Writer. TODO(port): bun_sys::QuietWrite::Adapter — size/align must match.
ScopedLogger
Runtime state for one scoped logger. One static instance per declare_scope!.
Source
StdinReader
Unbuffered stdin byte reader (std.fs.File.stdin().readerStreaming(..) in the Zig). Each take_byte is a 1-byte blocking read on the process stdin.
Synchronized
SysErrInfo
What err() needs from a bun_sys::Error without naming the type. Populated by bun_sys’s ErrName impl (move-in pass).
TemplateDisplay
Display adapter pairing a runtime template with a FmtTuple.

Enums§

ColorDepth
CommandArgv
Argument shape accepted by command/commandOut. Mirrors the Zig anytype switch over [][]const u8 vs []const u8.
Destination
OutputStreamDescriptor
Visibility

Constants§

BOLD
DIM
RESET
SYNCHRONIZED_END
https://gist.github.com/christianparpart/d8a62cc1ab659194337d73e399004036
SYNCHRONIZED_START
https://gist.github.com/christianparpart/d8a62cc1ab659194337d73e399004036

Statics§

ENABLE_ANSI_COLORS_STDERR
ENABLE_ANSI_COLORS_STDOUT
IS_GITHUB_ACTION
TERMINAL_SIZE

Traits§

ErrName
Trait abstracting the @typeInfo switch in Zig err().
FmtTuple
Positional-argument bundle for runtime template substitution.
PrettyFmtInput
Input accepted by [pretty_fmt]: either a &str/&[u8] template or a pre-formatted &fmt::Arguments<'_> (which is first rendered to a string then <tag>-rewritten — used by Custom Inspect-style call sites that build the template via format_args!).
ReadTimer
Minimal timer abstraction so bun_core doesn’t depend on bun_perf. bun_perf::SystemTimer impls this (move-in pass).

Functions§

argv
bun.argv — process argv as borrowed byte slices. Owned by the process.
buffered_stdin
bun.Output.buffered_stdin — raw pointer to the process-global 4 KiB buffered stdin. Used by prompt()/bun init/bun publish line reads.
buffered_stdin_read_until_delimiter
Convenience for bun.Output.buffered_stdin.reader().readUntilDelimiterArrayList.
buffered_stdin_reader
bun.Output.buffered_stdin.reader() — same accessor as buffered_stdin; the Zig spelling exposed the static itself and callers chained .reader().
clear_to_end
command
command_out
debug
Function-form of Output.debug (Zig: pub fn debug(comptime fmt, args)). The macro form is crate::debug!; this fn variant takes a single pre-formatted payload for call sites that build the message dynamically.
debug_warn
bun.Output.debugWarn — yellow debug warn: prefix to stderr in debug builds, through the Bun output sink (so colour/redirect logic applies), followed by an explicit flush. Zig output.zig:1189-1194.
disable_buffering
disable_buffering_scope
disable_scoped_debug_writer
enable_ansi_colors
enable_ansi_colors_stderr
Output.enable_ansi_colors_stderr.
enable_ansi_colors_stdout
Output.enable_ansi_colors_stdout — safe relaxed-load wrapper over the startup-initialized atomic. Mirrors the Zig public-var read.
enable_buffering
enable_buffering_scope
err
Print a red error message. The first argument takes an error_name value, which can be either be a Zig error, or a string or enum. The error name is converted to a string and displayed in place of “error:”, making it useful to print things like “EACCES: Couldn’t open package.json”
err_fmt
Print a red error message with “error: “ as the prefix and a formatted message.
err_generic
Output.errGeneric — function form. <red>error<r>: prefix to stderr with a <tag>-rewritten template + positional args.
err_tag
Output.err(.TAG, fmt, args) with a bare string tag — e.g. Output::err_tag("EACCES", format_args!(...)). Thin sugar over err for call sites that already hold a fully-formatted body (not a positional {} template).
error_writer
error_writer_buffered
flush
Write buffered stdout & stderr to the terminal. Must be called before the process exits or the buffered output will be lost. Bun automatically calls this function in Global.exit().
flush_guard
Returns a guard that flushes buffered stdout & stderr when it goes out of scope. Equivalent to Zig’s defer Output.flush();.
init_test
Test-harness initializer: configure the output sinks without touching the real stdio FDs (Zig: Output.initTest). Safe to call repeatedly.
is_ai_agent
is_github_action
is_stdin_tty
is_stdout_tty
is_verbose
note
bun.Output.note — blue note: prefix to stderr (output.zig:1179).
panic
pretty
bun.Output.pretty(fmt, args) — write to stdout with <tag> color expansion. Function form: performs the <tag> → ANSI rewrite at runtime on the rendered payload (using stdout’s colour state). Prefer the pretty! macro for literal templates so the rewrite stays comptime.
pretty_error
Output.prettyError<tag>-rewritten payload to stderr without a trailing newline.
pretty_errorln
Output.prettyErrorln — function form. Performs <tag> → ANSI rewrite on the rendered payload (using stderr’s colour state), writes to stderr, and appends \n if the rendered output does not already end in one. Macro form: crate::pretty_errorln!.
pretty_fmt
Output.prettyFmt — runtime <tag> → ANSI rewrite. Const-generic ENABLE_ANSI_COLORS mirrors the Zig comptime is_enabled: bool parameter so callers can do Output::pretty_fmt::<ENABLE_ANSI_COLORS>("…").
pretty_fmt_args
Runtime <tag> → ANSI rewrite with a positional-argument tuple substituted at each {} / {s} / {d} placeholder. Returns a Display impl so callers can write!(w, "{}", pretty_fmt_args(fmt, true, (a, b))).
pretty_fmt_rt
Runtime-bool form of [pretty_fmt] for call sites that don’t have a const-generic colour flag (crash handler, dynamic templates).
pretty_fmt_runtime
Runtime mirror of Zig prettyFmt for testing the proc-macro and for the rare dynamic case. Produces the same byte sequence the Zig comptime version would.
prettyln
bun.Output.prettyln(fmt, args)pretty() with a trailing newline. Function form: performs the <tag> → ANSI rewrite at runtime on the rendered payload and appends \n if the result does not already end in one (matches Zig output.zig:1090-1093). Prefer the prettyln! macro for literal templates. inline(always) for the same .text-layout reason as [pretty].
print
print_elapsed
print_elapsed_stdout
print_elapsed_stdout_trim
print_error
Output.printError — function form. No <tag> rewrite; takes anything Display (so both format_args!(..) and bare &str call sites compile) and writes it to stderr without a trailing newline.
print_errorable
print_errorln
Output.printErrorln — function form (the print_errorln! macro at crate root is the comptime-string variant). Takes anything Display so both format_args!(..) and bare &str call sites compile; appends \n.
print_start_end
print_start_end_stdout
print_timer
print_to
println
bun.Output.println(fmt, args)print() with a trailing newline.
raw_error_writer
raw_writer
reset_terminal
reset_terminal_all
set_is_verbose
stderr_descriptor_type
Safe getter (Zig: Output.stderr_descriptor_type).
stdin_reader
std.fs.File.stdin().readerStreaming(&buf) — fresh, unbuffered stdin reader. Used by alert()/confirm() which read a handful of bytes.
stdout_descriptor_type
Safe getter (Zig: Output.stdout_descriptor_type).
synchronized
https://gist.github.com/christianparpart/d8a62cc1ab659194337d73e399004036
up
warn
bun.Output.warn — yellow warn: prefix to stderr.
write_bytes
Single shared write path for pre-formatted bytes. Public so JS-facing sinks (console.*, process.stdout/stderr.write) route through the same buffering/TTY/flush semantics as the rest of the runtime instead of bypassing to raw stdio — byte-exact for non-UTF-8 chunks (Buffer writes).
writer
writer_buffered

Type Aliases§

DescriptorType
Downstream alias (Zig: Output.OutputStreamDescriptor). Several call sites refer to it as Output::DescriptorType for brevity.
LogFunction
Debug-only logs which should not appear in release mode.
StreamType
Source.StreamTypeFile on native, a fixed-buffer stream on WASM.