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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With