我现在做一个化工的流程模拟,需要一个程序界面,我选择了ncurse来做。今天是学习的开始,首先搞了一下终端的控制序列。最后参考一个C程序写了这个小脚本,算是学习作业。大家看看。 另外我把终端的转义序列打包放在软件下载里面了,希望要的兄弟自己去下载。
[code:1]#!/bin/bash
# textsysinfo.sh: show the current time and the
# number of process running at this moment
# if press ctrl+c, deal the possible problem
trap "echo -n -e ^[[m^[8 ; clear ; exit 130" 2
# global variable
current_time=
num_of_running_process=
default_row=1
default_col=72
function get_current_time() {
current_time=$(date +%T)
}
row=${1:-${default_row}}
col=${2:-${default_col}}
newrow=$((row+1)) # determine where the clock displayed
while true
do
get_current_time
get_num_of_running_process
echo -n -e "^[7^[[7m"
# save the cursor and reverse vedio on
echo -n -e "^[[${row};${col}H${current_time}^[[K"
# move the cursor, print the current time and
# erase from cursor to the end of the line
echo -n -e "^[[${newrow};${col}H${num_of_running_process} ...^[[K"
# move the cursor, print the number of the running process and
# erase from cursor to the end of line
echo -n -e "^[[m^[8"
# all attributes off and restore the cursor
sleep 1
done
[/code:1]