I am creating a console application (coursework) and it would be nice to clear the console after going to the next screen
For example, after the user has selected 1 case, the console will be cleared and a new menu will appear on the clean console, and not under the previous text
import Foundation
func getValue() -> Int? {
guard let line = readLine(), let value = Int(line) else {
return nil
}
return value
}
question: while true {
print("""
1. Log in
2. Create new user
3. Quit
""")
guard let value = getValue() else {
continue
}
switch value {
case 1:
print("you have selected number one")
case 2:
print("you have selected number two")
case 3:
print("Good bye")
break question
default:
print("Try again")
// print("\u{001B}[2J") //<- Didn't work
}
}
As in this example, I would like the field to be cleared and reappeared after each incorrect input
print("\u{001B}[2J") just get a lot of empty lines