最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to delete scrollback buffer in terminal in Go(lang)? - Stack Overflow

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论