| ... | @@ -50,14 +50,10 @@ pub const LineInfo = struct { | ... | @@ -50,14 +50,10 @@ pub const LineInfo = struct { |
| 50 | } | 50 | } |
| 51 | }; | 51 | }; |
| 52 | | 52 | |
| 53 | /// Tries to write to stderr, unbuffered, and ignores any error returned. | | |
| 54 | /// Does not append a newline. | | |
| 55 | var stderr_file: File = undefined; | | |
| 56 | var stderr_file_writer: File.Writer = undefined; | | |
| 57 | | | |
| 58 | var stderr_stream: ?*File.OutStream = null; | | |
| 59 | var stderr_mutex = std.Mutex.init(); | 53 | var stderr_mutex = std.Mutex.init(); |
| 60 | | 54 | |
| | 55 | /// Tries to write to stderr, unbuffered, and ignores any error returned. |
| | 56 | /// Does not append a newline. |
| 61 | pub fn warn(comptime fmt: []const u8, args: var) void { | 57 | pub fn warn(comptime fmt: []const u8, args: var) void { |
| 62 | const held = stderr_mutex.acquire(); | 58 | const held = stderr_mutex.acquire(); |
| 63 | defer held.release(); | 59 | defer held.release(); |
| ... | @@ -65,16 +61,8 @@ pub fn warn(comptime fmt: []const u8, args: var) void { | ... | @@ -65,16 +61,8 @@ pub fn warn(comptime fmt: []const u8, args: var) void { |
| 65 | nosuspend stderr.print(fmt, args) catch return; | 61 | nosuspend stderr.print(fmt, args) catch return; |
| 66 | } | 62 | } |
| 67 | | 63 | |
| 68 | pub fn getStderrStream() *File.OutStream { | 64 | pub fn getStderrStream() File.OutStream { |
| 69 | if (stderr_stream) |st| { | 65 | return io.getStdErr().outStream(); |
| 70 | return st; | | |
| 71 | } else { | | |
| 72 | stderr_file = io.getStdErr(); | | |
| 73 | stderr_file_writer = stderr_file.outStream(); | | |
| 74 | const st = &stderr_file_writer; | | |
| 75 | stderr_stream = st; | | |
| 76 | return st; | | |
| 77 | } | | |
| 78 | } | 66 | } |
| 79 | | 67 | |
| 80 | pub fn getStderrMutex() *std.Mutex { | 68 | pub fn getStderrMutex() *std.Mutex { |
| ... | @@ -99,6 +87,7 @@ pub fn detectTTYConfig() TTY.Config { | ... | @@ -99,6 +87,7 @@ pub fn detectTTYConfig() TTY.Config { |
| 99 | if (process.getEnvVarOwned(allocator, "ZIG_DEBUG_COLOR")) |_| { | 87 | if (process.getEnvVarOwned(allocator, "ZIG_DEBUG_COLOR")) |_| { |
| 100 | return .escape_codes; | 88 | return .escape_codes; |
| 101 | } else |_| { | 89 | } else |_| { |
| | 90 | const stderr_file = io.getStdErr(); |
| 102 | if (stderr_file.supportsAnsiEscapeCodes()) { | 91 | if (stderr_file.supportsAnsiEscapeCodes()) { |
| 103 | return .escape_codes; | 92 | return .escape_codes; |
| 104 | } else if (builtin.os.tag == .windows and stderr_file.isTty()) { | 93 | } else if (builtin.os.tag == .windows and stderr_file.isTty()) { |
| ... | @@ -458,6 +447,7 @@ pub const TTY = struct { | ... | @@ -458,6 +447,7 @@ pub const TTY = struct { |
| 458 | .Reset => out_stream.writeAll(RESET) catch return, | 447 | .Reset => out_stream.writeAll(RESET) catch return, |
| 459 | }, | 448 | }, |
| 460 | .windows_api => if (builtin.os.tag == .windows) { | 449 | .windows_api => if (builtin.os.tag == .windows) { |
| | 450 | const stderr_file = io.getStdErr(); |
| 461 | const S = struct { | 451 | const S = struct { |
| 462 | var attrs: windows.WORD = undefined; | 452 | var attrs: windows.WORD = undefined; |
| 463 | var init_attrs = false; | 453 | var init_attrs = false; |