shell中的clear命令实现
clear源码实现:
#include <stdio.h>
int clear_main(int argc, char **argv) {
/* This prints the clear screen and move cursor to top-left corner control
* characters for VT100 terminals. This means it will not work on
* non-VT100 compliant terminals, namely Windows' cmd.exe, but should
* work on anything unix-y. */
fputs("\x1b[2J\x1b[H", stdout);
return 0;
}
fputs("\x1b[2J\x1b[H", stdout)
其实是一串VT100的控制码
\x1b[2
清除整个屏幕,行属性变成单宽单高,光标位置不变
\x1b[H
光标移动到行首