random+tput 更改屏幕显示

trap  读取信号量 执行相应的操作

tput  更改终端显示命令 --tput cup 20  30  设置光标显示在20行30列的位置  tput clear 清屏

这个script 完全是出于兴趣 不见得有什么实际用途 

功能说明: 9行设置接受这几项信息量无操作,主要目地是不让ctrl+c  ctrl+z 结束此script

                    12-26一个根据当前屏幕大小自动生成随机数的函数

      read -t 1 设置timeout second 如果一秒用户不输入 还会直接运行

      最后如果执行100次 清屏 再重新输出$ 直到用户输入 ignore 为止

vim chageTerminalstyle.sh

  1 #!/bin/bash
  2
  3 ##
  4 # random to change prompt position  
  5 # not    interrupt
  6 # press  ignore    leave
  7 ##
  8
  9 trap '' 1 2 3 18 20 24
 10
 11 #produce random line or columns of screen
 12 function randomPro()
 13 {
 14   random=$RANDOM;
 15   num=$(date +%s);
 16   ((random=num+random))
 17   column=`tput cols`
 18   line=`tput lines`
 19   ((column=random%column+1))
 20   ((line=random%line+1))
 21   if [ $1 = "line" ] ; then
 22      echo $line
 23   else
 24      echo $column;
 25   fi
 26 }
 27
 28 #hide the prompt
 29 stty -echo
 30 cnt=0;
 31
 32 read -t 1 input
 33 if [ -z "$input" ] ; then
 34    input='xx'
 35 fi
 36
 37 # read ignore then stop
 38 until [ $input = "ignore" ]
 39 do
 40   ((cnt=$cnt+1));
 41   line=$(randomPro line);
 42   column=$(randomPro col);
 43   tput cup $line $column
 44 #sleep 2
 45   echo "$"
 46   read -t 2 input
 47   if [ -z $input ] ; then
 48    input='xx'
 49   fi
 50
 51   if [ "$cnt" -eq 100 ] ; then
 52      tput clear

 53      cnt=1

 54   fi
 55
 56 done
 57 # open the prompt
 58 stty echo

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值