From c7efae34d5aed7a8681114b1cb80c9a877335b1c Mon Sep 17 00:00:00 2001 From: codecolorist Date: Tue, 21 Oct 2025 17:57:47 +0200 Subject: [PATCH] PrettyPrint to stderr instead of stdout Fix the issue that log messages are mixed with json output --- Mist/Helpers/PrettyPrint.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Mist/Helpers/PrettyPrint.swift b/Mist/Helpers/PrettyPrint.swift index 22dbd7e..9c9d7ca 100644 --- a/Mist/Helpers/PrettyPrint.swift +++ b/Mist/Helpers/PrettyPrint.swift @@ -5,6 +5,8 @@ // Created by Nindi Gill on 12/3/21. // +import Foundation + /// Helper Struct used to format printed messages. enum PrettyPrint { enum Prefix: String { @@ -25,7 +27,8 @@ enum PrettyPrint { static func printHeader(_ header: String, noAnsi: Bool) { let horizontal: String = .init(repeating: "─", count: header.count + 2) let string: String = "┌\(horizontal)┐\n│ \(header) │\n└\(horizontal)┘" - Swift.print(noAnsi ? string : string.color(.blue)) + let line: String = noAnsi ? string : string.color(.blue) + FileHandle.standardError.write(Data((line + "\n").utf8)) } /// Prints a string with an optional custom prefix. @@ -39,6 +42,7 @@ enum PrettyPrint { static func print(_ string: String, noAnsi: Bool, prefix: Prefix = .default, prefixColor: String.Color = .green, replacing: Bool = false) { let replacingString: String = replacing && !noAnsi ? "\u{1B}[1A\u{1B}[K" : "" let prefixString: String = "\(noAnsi ? prefix.description : prefix.description.color(prefixColor))" - Swift.print("\(replacingString)\(prefixString)\(string)") + let line: String = "\(replacingString)\(prefixString)\(string)" + FileHandle.standardError.write(Data((line + "\n").utf8)) } }