Android系统shell中的clear命令实现【转】

本文转载自:http://blog.csdn.net/morixinguan/article/details/73467845

之前一直不太清楚,当我们在shell命令行输入很多命令,会在屏幕上输出一些信息,为什么一执行clear这个命令以后,所有的信息就没了呢?

现在终于搞明白了,找到了clear命令的源代码clear.c

源码如下:

 

[cpp] view plain copy
 
 print?
  1. #include <stdio.h>  
  2.   
  3. int clear_main(int argc, char **argv) {  
  4.     /* This prints the clear screen and move cursor to top-left corner control 
  5.      * characters for VT100 terminals. This means it will not work on 
  6.      * non-VT100 compliant terminals, namely Windows' cmd.exe, but should 
  7.      * work on anything unix-y. */  
  8.     fputs("\x1b[2J\x1b[H", stdout);  
  9.     return 0;  
  10. }  


震惊了!!!就两行代码!!!这里面稀奇古怪的字符串重定向到stdout(标准输出)是什么东西呢?

 

其实是一串VT100的控制码,那这一串代码什么东西呢?

"\x1b[2J",//清除整个屏幕,行属性变成单宽单高,光标位置不变

"\x1b[H",//光标移动

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

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

 

posted @   请给我倒杯茶  阅读(570)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示