Temporarily clear the terminal in Linux

后端 未结 1 903
遇见更好的自我
遇见更好的自我 2021-01-27 12:43

I want to write a GUI/Terminal based application where I would need to clear the terminal and then write out the gui.

But how do I reset the terminal back to normal once

1条回答
  •  有刺的猬
    2021-01-27 13:46

    Terminals (such as xterm and "any" which emulate it) support a feature called the alternate screen. Often, terminal descriptions include switching to/from the alternate screen in the smcup and rmcup capabilities, and it is used by ncurses applications. (The feature is not always used, because some users do not like the feature). Even if it is not part of the terminal description (seen with tgetstr("ti") or tigetstr("smcup")) your application could write the literal escape sequence.

    On switching to the alternate screen, the convention (used in the terminal escape sequences) is to clear the alternate screen, putting the cursor at the upper left corner. Switching back restores the original (normal) screen and cursor location.

    There is some discussion of alternate screen in the xterm FAQ Why doesn't the screen clear when running vi?.

    0 讨论(0)
提交回复
热议问题