Clearing the screen by printing a character?

前端 未结 2 1429
借酒劲吻你
借酒劲吻你 2020-12-15 05:58

I\'m using chez-scheme and I can\'t find a way to clear the screen completely. (If someone knows a better way than printing I\'d be interested in that too but it\'s not my q

相关标签:
2条回答
  • 2020-12-15 06:28

    You can print \033c which resets the terminal:

    petite -q <<< '(display "\033c")'
    

    \033 is escape and c is literal c.

    I can't give you any information about how widely this is supported.

    0 讨论(0)
  • 2020-12-15 06:29

    If you want to clear the screen, the "ANSI" sequence in a printf

    \033[2J
    

    clears the entire screen, e.g.,

    printf '\033[2J'
    

    The command-line clear program uses this, along with moving the cursor to the "home" position, again an "ANSI" sequence:

    \033[H
    

    The program gets the information from the terminal database. For example, for TERM=vt100, it might see this (using \E as \033):

    clear=\E[H\E[J$<50>
    

    (the $<50> indicates padding needed for real VT100s). You might notice that the 2 is absent from this string. That is because the cursor is first moved to the home (upper left) position, and the 2 (entire screen) is not necessary. Eliminating that from the string made VT100s a little faster.

    On the other hand, if you just want to reset the terminal, you can use the VT100-style RIS:

    \033c
    

    but that has side-effects, besides not being in ECMA-48. These bug reports were for side-effects of \033c:

    • Debian Bug report logs - #60377 "reset" broken for dumb terminals
    • Debian Bug report logs - #239205 "reset changes a unicode console to non-unicode"

    Further reading:

    • Why doesn't the screen clear when I type control/L?
    • XTerm Control Sequences
    CSI Ps J  Erase in Display (ED).
                Ps = 0  -> Erase Below (default).
                Ps = 1  -> Erase Above.
                Ps = 2  -> Erase All.
                Ps = 3  -> Erase Saved Lines (xterm).
    
    • ECMA-48: Control Functions for Coded Character Sets
    0 讨论(0)
提交回复
热议问题