Merge pull request #355 from mas-cli/print

🖨 Override print only in debug builds
This commit is contained in:
Ben Chatelain 2021-05-03 20:48:36 -06:00 committed by GitHub
commit ba4e62f623
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,23 +13,33 @@ import Foundation
/// Terminal Control Sequence Indicator
let csi = "\u{001B}["
#if DEBUG
var printObserver: ((String) -> Void)?
// Override global print for testability.
// See MasKitTests/OutputListener.swift.
func print(_ items: Any..., separator: String = " ", terminator: String = "\n") {
if let observer = printObserver {
let output = items
.map { "\($0)" }
.joined(separator: separator)
.appending(terminator)
if let observer = printObserver {
observer(output)
}
Swift.print(output)
var prefix = ""
for item in items {
Swift.print(prefix, terminator: "")
Swift.print(item, terminator: "")
prefix = separator
}
Swift.print(terminator, terminator: "")
}
#endif
func printInfo(_ message: String) {
guard isatty(fileno(stdout)) != 0 else {
print("==> \(message)")