I am creating this terminal game where for every event (or every move) the screen has to be cleared. It is like a 5x5 board, every time a move is done, the screen is cleared and the cursor is moved to top left. The problem comes when I exit the application (I/O interrupt). When I run the app next time, I see that the contents in size of the terminal is cleared and the board is printed, but the contents from previous run still remains there when I scroll upwards.
What did I try to clear contents from the terminal?
1. I used github/inancgumus/screen:
import (
"fmt"
"github/inancgumus/screen"
)
func ClearTerminal() {
screen.MoveTopLeft()
screen.Clear()
}
2. I used the standard ANSI code. I tried both the codes separately and together.
import (
"fmt"
)
func ClearTerminal() {
fmt.Print("\033[H\033[2J")
fmt.Print("\033c")
}
Both methods do not seem to work.
I found out that this is called scrollback buffer when I did some research. I am looking for solutions using Go.