Android系统shell中的clear命令实现

来源:互联网 发布:淘宝九块九包邮网址 编辑:程序博客网 时间:2024/06/05 05:54

之前一直不太清楚,当我们在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",//光标移动

更加详细的命令可以参考以下博文:

http://blog.sina.com.cn/s/blog_7347cd380100upwj.html



原创粉丝点击