Color ouput with Swift command line tool
Swift has built in unicode support. This invalidates using of back slash. So that I use color codes with "\u{}" syntax. Here is a println code which works perfectly on terminal.
// \u{001B}[\(attribute code like bold, dim, normal);\(color code)m
// Color codes
// black 30
// red 31
// green 32
// yellow 33
// blue 34
// magenta 35
// cyan 36
// white 37
println("\u{001B}[0;33myellow")
Hope it helps.
print() to console log with color
Nowadays, Xcode debugging console doesn't support coloring.
Update current line with command line tool in Swift
Your example will only work on the actual command line, not in the debugger console. And you also need to flush stdout for every iteration, like this:
var logString = String(format: "%2i%% %.2fM \r", 10, 5)
print(logString)
fflush(__stdoutp)
Replace printed out text
If the output goes to the Terminal then you can use the fact that\r
(Carriage Return) moves the "cursor" to the start of the current
line, without advancing to the next line:
print("10% done ", terminator: "\r")
print("20% done ", terminator: "\r")
print("100% done")
(But note that this does not work in the Xcode debugger console.)
Related Topics
Why Won't My Collection View Cells Display in the iPhone Simulator
Structuring Data for Chat App in Firebase
How to Use Core Data Value from Picker? #Swiftui #Coredata
Var Declaration with Type VS Without
Finding All Types That Conform to a Protocol
Can't Append Value to My Nsarray Variable
Ios8: Auto-Layout and Gradient
Swift Optional Variable Assignment with Default Value (Double Question Marks)
What Does Cloning a Github Repository Mean
Swiftui: Stop an Animation That Repeats Forever
Swift - Associated Value or Extension for an Enum
How to Implement Multiple Pangestures (Draggable Views)
Swiftui Tabview Gives an Error Message During Add/Delete the Element of Coredata
Nsurl Fail Able Initialiser Initwithstring: Does Not Return Nil on Empty String in Swift
Swift Why Isn't My Date Object That's (Equatable) Equal After Converting It to a String and Back
How to Give Dynamic Height to Uitableview