Android系统shell中的clear命令实现
之前一直不太清楚,当我们在shell命令行输入很多命令,会在屏幕上输出一些信息,为什么一执行clear这个命令以后,所有的信息就没了呢?
现在终于搞明白了,找到了clear命令的源代码clear.c
源码如下:
#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;
}
震惊了!!!就两行代码!!!这里面稀奇古怪的字符串重定向到stdout(标准输出)是什么东西呢?
其实是一串VT100的控制码,那这一串代码什么东西呢?
"\x1b[2J",//清除整个屏幕,行属性变成单宽单高,光标位置不变
"\x1b[H",//光标移动
相关推荐
tianhuak 2020-11-24
huha 2020-10-16
lianshaohua 2020-09-23
laisean 2020-11-11
zhangjie 2020-11-11
大牛牛 2020-10-30
firefaith 2020-10-30
liguojia 2020-10-20
wangzhaotongalex 2020-10-20
以梦为马不负韶华 2020-10-20
CARBON 2020-10-20
彼岸随笔 2020-10-20
lianshaohua 2020-10-20
yutou0 2020-10-17
JohnYork 2020-10-16
xiaonamylove 2020-10-16
Julyth 2020-10-16
applecarelte 2020-10-16
ourtimes 2020-10-16