shell隐藏显示光标脚本 (转)

#!/bin/bash
#cursor on|off
#turns the cursor on or off for the vt100,200,220,meth220
#note: will work no normal tty connec.. if'ie on some win emulations
#check TERM evn for your type!
_OPT=$1
if [ $# -ne 1 ];then
    echo "Usage:`basename $0` cursor [on|off]"
    exit 1;
fi

case "$_OPT" in
on|ON|On)
    #turn it on (cursor)
    ON=`echo ^[[?25h`
    echo $ON
    ;;
off|OFF|Off)
    #turn it off(cursor)
    OFF=`echo ^[[?25l`
    echo $OFF
    ;;
*)echo "Usage:cursor on|off"
    exit 1
    ;;
esac

^[[?25h和^[[?25l中
l,h为字母, <ctrl+v>是按下ctrl键不放,然后按下V, <ESC>就是按一下键盘上的ESC键

即^[是用<ctrl+v><ESC>得到的,直接输入^[无效

更简单一点的方法
echo -e "\033[?25l" 隐藏光标
echo -e "\033[?25h" 显示光标
其实\033(八进制,相当于10进制的27)就是<ctrl+v><ESC>所输入字符的值.

echo -ne "\33[32m" 可以将字符的显示颜色改为绿色
echo -ne "\33[3;1H" 可以将光标移到第3行第1列处
具体的摘抄一些如下:
\33[0m 关闭所有属性
\33[1m 设置高亮度
\33[4m 下划线
\33[5m 闪烁
\33[7m 反显
\33[8m 消隐
\33[30m -- \33[37m 设置前景色
\33[40m -- \33[47m 设置背景色
\33[nA 光标上移n行
\33[nB 光标下移n行
\33[nC 光标右移n行
\33[nD 光标左移n行
\33[y;xH设置光标位置
\33[2J 清屏
\33[K 清除从光标到行尾的内容
\33[s 保存光标位置
\33[u 恢复光标位置
\33[?25l 隐藏光标
\33[?25h 显示光标

不要忘了-e   和"",否则是起不了作用的.


部分参考:http://alwaysgo.blog.hexun.com/5226886_d.html

 

原帖:http://hi.baidu.com/snailzzz/blog/item/ac56ffec0520c034279791d9.html

posted @ 2011-09-23 09:18  zhjb616  阅读(1584)  评论(0编辑  收藏  举报