mirror of
https://github.com/mas-cli/mas
synced 2024-11-22 03:23:08 +00:00
Merge pull request #355 from mas-cli/print
🖨 Override print only in debug builds
This commit is contained in:
commit
ba4e62f623
1 changed files with 16 additions and 6 deletions
|
@ -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)")
|
||||
|
|
Loading…
Reference in a new issue