设为首页 加入收藏

TOP

Android系统shell中的clear命令实现
2017-06-22 10:23:59 】 浏览:315
Tags: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",//光标移动


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Alsa音频子系统Codec---al5623.c.. 下一篇Android编译系统产品线(基于友善..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目