Reputation: 2060
I'm building CLI app (on Linux) where user has to choose something and then I have to clear last line.
I tried several things:
fmt.Print("\r")
fmt.Print("\033[1")
And the cursor goes back to beginning of line, but do not clear the text from the last line.
What am I missing here?
Upvotes: 4
Views: 1309
Reputation: 5369
You can use it that way
fmt.Printf("\033[1A\033[K")
\033[1A
- one line up
\033[K
- delete the line
For example
fmt.Println("hello")
fmt.Println("world")
fmt.Printf("\033[1A\033[K")
will output only hello
as the world will be deleted
You can read more about ascii escaping here https://tldp.org/HOWTO/Bash-Prompt-HOWTO/x361.html
Upvotes: 3