[英]Form feed does not clear the screen
I've discovered the Ada programming language recently, but the problem exists in the C programming language as well. 我最近发现了Ada编程语言,但是C编程语言中也存在该问题。 The form feed does not work as expected.
换页不能正常工作。
Ada Example: Ada示例:
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
begin
New_Page;
end Main;
Same in C: 在C中也一样:
#include <stdio.h>
int main (void) {
printf ("\f");
return 0;
}
Both result only in a new line on XTerm as well as Linux console (both with zsh). 两者都只会在XTerm和Linux控制台(均带有zsh)上产生新的一行。 They should clear instead the screen as an Ctrl-L does.
他们应该像按Ctrl-L一样清除屏幕。
When called with 当与
# ./main | cat -A
I get a 我得到一个
^L
But if I type a 但是如果我输入
# cat -A
and type a 然后输入
Ctrl-L
I get a 我得到一个
^L
too. 太。
Does anyone know how to make the form feed work as a Ctrl-L? 有谁知道如何使换页功能像Ctrl-L一样工作?
Thanks for your help! 谢谢你的帮助!
According to this article the proper way to clear the screen is printf("\\033[2J");
根据本文 ,清除屏幕的正确方法是
printf("\\033[2J");
(provided your terminal supports ANSI escape sequences and is VT100 -compatible). (前提是您的终端支持ANSI转义序列并且与VT100兼容)。 I can confirm that this works on Linux Mint using GNOME Terminal, and on Windows using xterm and PuTTY.
我可以确认这在使用GNOME Terminal的Linux Mint上以及在使用xterm和PuTTY的Windows上均有效。
^L
clearing the screen doesn't look like a portable convention. ^L
清除屏幕看起来并不像便携式惯例。 For example on HP-UX with the POSIX shell, passing ^L
to the shell doesn't do anything. 例如,在具有POSIX外壳的HP-UX上,将
^L
传递到外壳不会执行任何操作。 This seems more like a bash
occurrence. 这似乎更像是重
bash
。
Printing \\f
will clear the screen with some terminals but not others. 打印
\\f
将清除某些终端的屏幕,而不清除其他终端的屏幕。 For example logging to a Red Hat host from Windows, I can clear the screen with printf("\\f");
例如,从Windows登录到Red Hat主机,我可以使用
printf("\\f");
清除屏幕printf("\\f");
in PuTTY but not in xterm (I get a blank line in the latter case). 在PuTTY中,但不在xterm中(在后一种情况下,我得到一个空白行)。
I tried to edit @Nobilis' answer to add an Ada version, but I think my edit got lost when the screen was cleared, so here's another try: 我尝试编辑@Nobilis的答案以添加Ada版本,但是我认为在清除屏幕后我的编辑丢失了,所以这是另一种尝试:
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
begin
Put (ASCII.ESC & "[2J");
end Main;
In a larger program, you might need to follow it with a "Flush;" 在较大的程序中,可能需要在其后加上“ Flush;”。 call since the above could get buffered by the I/O packages, which probably won't realize this is a special terminal command.
调用,因为上述内容可能会被I / O包缓冲,这可能不会意识到这是一个特殊的终端命令。 (Same in C, I think:
fflush(stdout);
.) (与C相同,我认为:
fflush(stdout);
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.