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

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

问题描述

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

据我所知,通过 ^L (control-L) 清除屏幕或给出 clear 命令(至少在 bash 中)相当于输出 ASCII 字符 12:Form feed.但是,打印它没有任何作用.如果我使用 (display (integer->char 12)) 它只是打印一个 newline.另一种编码此字符的方法是 f(类似于 for newline),但在 Python 中 print("f") 以及在 Scheme (display "f") 中只是一个 newline.

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

有什么方法可以清除应该跨语言工作的屏幕,类似于 newline 吗?

解决方案

如果你想清除屏幕,printf

中的ANSI"序列>

33[2J

清除整个屏幕,例如

printf '33[2J'

命令行clear程序使用这个,同时将光标移动到home"位置,同样是一个ANSI"序列:

33[H

程序从终端数据库中获取信息.例如,对于 TERM=vt100,它可能会看到这个(使用 E 作为 33):

clear=E[HE[J$<50>

($<50> 表示实际 VT100 所需的填充).您可能会注意到该字符串中没有 2.那是因为光标是first移动到home(左上)位置的,而2(整个屏幕)不是必须的.从字符串中消除它使 VT100s 一点更快.

另一方面,如果您只想重置终端,您可以使用VT100 风格的 RIS:

33c

但这有副作用,除了不在 ECMA-48 中.这些错误报告是针对 33c副作用:

进一步阅读:

<前>CSI Ps J 擦除显示 (ED).Ps = 0 -> 擦除下方(默认).Ps = 1 -> 擦除上面.Ps = 2 -> 全部擦除.Ps = 3 -> 擦除保存的行 (xterm).

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)

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 for newline), but in Python print("f") as well as in Scheme (display "f") is just a newline.

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

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

解决方案

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

33[2J

clears the entire screen, e.g.,

printf '33[2J'

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

33[H

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

clear=E[HE[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:

33c

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

Further reading:

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).

这篇关于通过打印字符清除屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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