mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
std: rework TTY detection and printing
This commit sketches an idea for how to deal with detection of file streams as being terminals. When a File stream is a terminal, writes through the stream should have their escapes stripped unless the programmer explicitly enables terminal escapes. Furthermore, the programmer needs a convenient API for intentionally outputting escapes into the stream. In particular it should be possible to set colors that are silently discarded when the stream is not a terminal. This commit makes `Io.File.Writer` track the terminal mode in the already-existing `mode` field, making it the appropriate place to implement escape stripping. `Io.lockStderrWriter` returns a `*Io.File.Writer` with terminal detection already done by default. This is a higher-level application layer stream for writing to stderr. Meanwhile, `std.debug.lockStderrWriter` also returns a `*Io.File.Writer` but a lower-level one that is hard-coded to use a static single-threaded `std.Io.Threaded` instance. This is the same instance that is used for collecting debug information and iterating the unwind info.
This commit is contained in:
@@ -755,10 +755,9 @@ fn appendTreeSymbol(symbol: TreeSymbol, buf: []u8, start_i: usize) usize {
|
||||
}
|
||||
}
|
||||
|
||||
fn clearWrittenWithEscapeCodes(w: *Io.Writer) anyerror!void {
|
||||
pub fn clearWrittenWithEscapeCodes(file_writer: *Io.File.Writer) anyerror!void {
|
||||
if (noop_impl or !global_progress.need_clear) return;
|
||||
|
||||
try w.writeAll(clear ++ progress_remove);
|
||||
try file_writer.interface.writeAllUnescaped(clear ++ progress_remove);
|
||||
global_progress.need_clear = false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user