为什么“清除”不清除整个屏幕?

欧根·康科夫(Eugen Konkov)

当我使用clear命令清除屏幕时。它没有清除(命令完成后我向上滚动一点,请参见屏幕截图)

在此处输入图片说明

因此,我将命令加倍以得到正确的行为:

$ clear && clear && DD=0 ...

在此处输入图片说明

为什么我需要加倍命令才能清除屏幕?

UPD

实际上,如果我只是clear清除了屏幕。但我可以向上滚动并查看最后25行(如果屏幕为80x25)。当我跑步时,clear;clear我清除了这些线条。

JdeBP

The important thing to note here is the tag on the question. This behaviour is specific to GNOME Terminal and any other terminal emulators that are built upon libvte. You won't see this in Xterm, or in Unicode RXVT, or in the terminal emulator built into the Linux kernel, or on the FreeBSD console.

What happens in general is this.

  1. The clear command looks at terminfo/termcap and issues appropriate control sequences.
    1. If the terminfo/termcap entry has an E3 capability it, it first writes out that. This issues control sequences to clear the scrollback buffer. This and the history behind it are documented in detail in the Dickey ncurses manual page for the clear command.
    2. It then uses the clear capability to clear the visible screen.
  2. The control sequences in the terminfo/termcap entry are determined by the terminal type; but, with the exceptions of the (nowadays rare) terminals that use FormFeed to clear the screen (which DEC VTs and their imitators do not), they are either just plain old ECMA-48 control sequences or extensions thereto. For examples:
  3. The terminal emulator acts upon the control sequences. As defined by ECMA-48 and the Xterm extension to it:
    • CSI H (CUP) homes the cursor.
    • CSI 0 J (ED 0) or just CSI J erases from the current cursor position to the end of the screen.
    • CSI 2 J (ED 2) erases the whole screen.
    • CSI 3 J (ED 3) erases the scrollback buffer.

When it comes to GNOME Terminal in particular:

  1. The terminal type is properly gnome, but some people leave it erroneously set to xterm.
  2. The gnome terminfo entry does not define an E3 capability, and on many systems — still! — neither does the xterm entry as this has not percolated down from Dickey terminfo. So clear just writes out the contents of the clear capability.
  3. The contents of the clear capability for those terminfo entries are the control sequences to home the cursor followed by erase the whole screen.
  4. But GNOME Terminal does not implement erase the whole screen correctly. More specifically, the library that it is based upon, libvte, does not do that in the code of its VteTerminalPrivate::seq_clear_screen() function. Rather, libvte scrolls the screen down an entire screen's worth of blank lines, and moves the cursor position to the first of those blank lines.

This is why you see what you see. libvte is not erasing the whole screen when told to. Rather it is doing something that has a superficial resemblance to that, until one does exactly what the questioner has done here: scroll the terminal window back to look at the scroll back buffer. Then the difference is blatant.

On other terminal emulators such as Xterm and Unicode RXVT, the ED 2 control sequence really does erase the screen, erasing every position on the screen in place, from the top down, and not altering the scrollback buffer. But on libvte terminal emulators, it just pushes the current screen up into the scrollback buffer and adds a screen's worth of blank lines. The prior screen contents are not erased but shifted into the scrollback buffer.

And if you run the clear command twice, it adds two screen's worth of blank lines. If your scroll back buffer is large enough, you can still find the original screen contents, simply further up in the scrollback buffer.

Further reading

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

为什么清除不清除?

来自分类Dev

为什么不清除模型值?

来自分类Dev

为什么flock不清除锁定文件?

来自分类Dev

为什么数组保存最后的数据却不清除?

来自分类Dev

为什么os.system('cls')不清除最近的输出?

来自分类Dev

为什么不清除我的div?(JavaScript和Jquery)

来自分类Dev

为什么数组保存最后的数据却不清除?

来自分类Dev

清除或不清除

来自分类Dev

有什么方法可以在不清除屏幕的情况下退出“较少”状态?

来自分类Dev

为什么RenderingContext.drawElements在绘制之前清除屏幕?

来自分类Dev

为什么“ \ b”不清除左侧的一个字符?

来自分类Dev

在不清除屏幕的情况下显示javascript变量

来自分类Dev

clearInterval不清除setInterval

来自分类Dev

clearRect不清除

来自分类Dev

clearRect不清除

来自分类Dev

UIRefreshControl 不清除 tableview

来自分类Dev

如果我不清除stringstream,会发生什么?

来自分类Dev

将文本设置为字符串后,为什么我的文本框不清除文本?

来自分类Dev

为什么系统还原会清除整个桌面以及主分区上的许多文件?

来自分类Dev

MySQL临时表不清除

来自分类Dev

淘汰JS不清除组件

来自分类Dev

不清除董事会

来自分类Dev

Control + L不清除画面

来自分类Dev

Django不清除数据

来自分类Dev

特定的ServiceControl不清除消息

来自分类Dev

如何清除批处理中的选定行而不是整个屏幕?

来自分类Dev

清除整个根

来自分类Dev

如何减少寻呼机对滚轮的响应并不清除屏幕

来自分类Dev

在不清除屏幕的情况下在linux终端中读取特殊键