在 Windows 中的 Swipl prolog 中清除屏幕

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16908764/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:34:20  来源:igfitidea点击:

Clearing Screen in Swipl prolog in windows

windowsshellcommand-lineprolog

提问by Ishan

When you are running command prompt in windows you can type the clearcommand to clear the screen. How do you do the same thing when you are running swipl prolog (by typing swiplin the command prompt) in windows?

当您在 Windows 中运行命令提示符时,您可以键入clear命令来清除屏幕。当您swipl在 Windows中运行 swipl prolog(通过在命令提示符下键入)时,您如何做同样的事情?

回答by Orbling

On unix terminals, there is the library(tty)resource and that has tty_clear/0, but windows terminals do not support the terminal library. However, they do support ANSI Escape Codes.

在 unix 终端上,有library(tty)资源并且有tty_clear/0,但 windows 终端不支持终端库。但是,它们确实支持ANSI 转义码

Escape codes are character sequences starting with the ESC(escape) character, ASCII 0x1B = 27. Most start with the control sequence introducer, which is the escape followed by a left bracker: ESC [, known as the CSI.

转义码是以ESC(转义)字符ASCII 0x1B = 27.开头的字符序列。大多数以控制序列引入器开始,即转义符后跟左括号: ESC [,称为CSI.

So you can issue the code sequence for a screen clear, which is the ED (Erase Data) command, which takes the form:

因此,您可以发出清除屏幕的代码序列,即 ED(擦除数据)命令,其形式为:

CSI 2 J   -- which expands to: ESC [ 2 J

From SWI-Prolog this can be issued using the format/2primitive.

从 SWI-Prolog 这可以使用format/2原语发出。

format('~c~s', [0x1b, "[2J"]). % issue CSI 2 J

The ED 2 command, full terminal clear, on the MSDOS ANSI handling resets the cursor to top-left, but that is not necessarily the case on all terminals, so best to combine with the CUP (Cursor Position) command, which as a reset to home is simply: CSI H.

ED 2 命令,全终端清除,在 MSDOS ANSI 处理中将光标重置到左上角,但不一定在所有终端上都是这种情况,因此最好与 CUP(光标位置)命令结合使用,作为重置到家很简单:CSI H

format('~c~s~c~s', [0x1b, "[H", 0x1b, "[2J"]). % issue CSI H CSI 2 J


Update: Simplification

更新:简化

Thanks to @CapelliCfor an alternate and clearer form, using the \eescape code for escape!

感谢@CapelliC提供了另一种更清晰的形式,使用\e转义码进行转义!

Plain clear screen:

纯清屏:

cls :- write('\e[2J').

Or with home reset:

或家庭重置:

cls :- write('\e[H\e[2J').