random+tput 更改屏幕显示

来源:互联网 发布:淘宝剑三代练 编辑:程序博客网 时间:2024/05/17 23:54

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