通过打印字符来清除屏幕? [英] Clearing the screen by printing a character?

查看:93
本文介绍了通过打印字符来清除屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用chez-scheme,但找不到完全清除屏幕的方法. (如果有人知道比打印更好的方法,我也会对此感兴趣,但这不是我的问题)

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 question here)

根据我发现,用^ L(control-L)清除屏幕或给出clear命令(至少以bash表示),等同于输出ASCII字符12:Form feed. 但是,打印此操作无济于事.如果我使用(display (integer->char 12)),它只会打印一个newline.编码此字符的另一种方法是\f(类似于newline\n),但是在Python print("\f")和Scheme (display "\f")中只是一个newline.

From what I can find clearing the screen by ^L (control-L) or giving the clear command (in bash at least) is equivalent to outputting ASCII character 12: Form feed. However, printing this does nothing. If I use (display (integer->char 12)) it just prints a newline. Another way to encode this character is \f (analogous to \n for newline), but in Python print("\f") as well as in Scheme (display "\f") is just a newline.

我对ASCII 12的含义的理解是错误的,还是缺乏实现?

Is my understanding of the meaning of ASCII 12 just wrong, or are implementations lacking?

是否有任何方法可以清除应该跨语言使用的屏幕,类似于newline\n?

Is there any way to clear the screen that should work across languages, analogous to \n for a newline?

推荐答案

如果要清除屏幕,则printf

\033[2J

清除整个屏幕,例如

printf '\033[2J'

命令行 clear 程序将其与将光标移到起始"位置,再次是"ANSI"序列:

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

\033[H

程序从终端数据库获取信息.例如,对于 TERM=vt100 ,它可能会看到以下内容(使用\E作为\033):

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>

($<50>表示实际VT100所需的 padding ).您可能会注意到,该字符串中没有2.这是因为光标 first 首先移动到起始位置(左上角),并且2(整个屏幕)不是必需的.从字符串中消除它使VT100的速度变得.

(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

但这有副作用,除了没有出现在ECMA-48中.这些错误报告是针对>的副作用:

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

进一步阅读:

  • 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:编码字符集的控制功能
    • ECMA-48: Control Functions for Coded Character Sets
    • 这篇关于通过打印字符来清除屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆