Chinaunix

标题: 一句话实现linux终端清屏(帮忙解释一下这句C语言) [打印本页]

作者: liuxt    时间: 2008-09-12 23:44
标题: 一句话实现linux终端清屏(帮忙解释一下这句C语言)
printf("%s",   "\033[1H\033[2J");


/*file:   clear.c
*compile:   gcc -o clear clear.c
*use:   ./clear
*/
#include <stdio.h>

int main()
{
       printf("%s",   "\033[1H\033[2J");
       return 0;
}


但是我不太明白"\033[1H\033[2J"的意思,如果谁知道,请给我解释一下,本人感恩不尽
作者: MMMIX    时间: 2008-09-12 23:44
这个是  ANSI/VT100 Terminal Control Escape Sequences,见 http://www.termsys.demon.co.uk/vtansi.htm
作者: liuxt    时间: 2008-09-13 01:20
谢谢
Move to Position         ESC[row;colH         Move the cursor to the (col, row) position. Note that the row comes before column; that is, y comes before x. Either col or row can be omitted. Row and column both start with "1," not zero. (1, 1) corresponds to the top-left corner of the screen.

Clear Screen         ESC[2J         Clear the whole screen and position the cursor to the top left corner.


"\033[1H\033[2J"相当于ESC[1H  ESC[2J,就是说把光标移到左上角,然后清屏
作者: jerryjzm    时间: 2008-09-15 20:15
#include <stdio.h>
int main()
{
       printf("%s",   "\033[2J");
       return 0;
}

就这样行不!?  ESC[2J 已经包含这个 \033[1H 的作用了吧!
作者: snow888    时间: 2008-09-17 09:25
末有这么复杂的。


  1. puts("\033[2J");
复制代码


OK! 了。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2