Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Mist/Helpers/PrettyPrint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
Expand All @@ -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))
}
}