我想这样显示:
------------------------------------
| invoke funtion and show some |
| information here |
| --message 1 |
| | |
| |
| |
| | <--- SCREEN
| |
|echo something here |
|hello |
|Linuxsir ----message2 |
|$ |
|-----------------------------------
问题描述
message1 和 message2不能共享一个屏幕阿
就是说,我调用 message1后,在调用message2,
那么屏幕上 message1中信息将不完全显示在一个屏幕了。
我修改 ABS上画盒子的代码,做菜单玩玩的:
可以shell中运行一下。抓图中,上边还有显示一个 MENU 的盒子,但是显示不出来。。。
#!/bin/bash
# Draw-box.sh: Drawing a box using ASCII characters.
# Script by Stefano Palmeri, with minor editing by document author.
# Used in the "ABS Guide" with permission.
######################################################################
### draw_box function doc ###
# The "draw_box" function lets the user
#+ draw a box into a terminal.
#
# Usage: draw_box ROW COLUMN HEIGHT WIDTH [COLOR]
#
# ROW and COLUMN represent the position
#+ of the upper left angle of the box you're going to draw.
# ROW and COLUMN must be greater than 0
#+ and less than current terminal dimension.
# HEIGHT is the number of rows of the box, and must be > 0.
# HEIGHT + ROW must be <= than current terminal height.
# WIDTH is the number of columns of the box and must be > 0.
# WIDTH + COLUMN must be <= than current terminal width.
#
# E.g.: If your terminal dimension is 20x80,
# draw_box 2 3 10 45 is good
# draw_box 2 3 19 45 has bad HEIGHT value (19+2 > 20)
# draw_box 2 3 18 78 has bad WIDTH value (78+3 > 80)
#
# COLOR is the color of the box frame.
# This is the 5th argument and is optional.
# 0=black 1=red 2=green 3=tan 4=blue 5=purple 6=cyan 7=white.
# If you pass the function bad arguments,
#+ it will just exit with code 65,
#+ and no messages will be printed on stderr.
#
# Clear the terminal before you start to draw a box.
# The clear command is not contained within the function.
# This allows the user to draw multiple boxes, even overlapping ones.
### end of draw_box function doc ###
######################################################################
draw_box(){
#=============#
#drwa a box
HORZ="-"
VERT="|"
CORNER_CHAR="+"
#test the number of arguments first
MINARGS=4
E_BADARGS=65
#=============#
if [ $# -lt "$MINARGS" ];
then # If args are less than 4, exit.
exit $E_BADARGS
fi
# Looking for non digit chars in arguments.
# Probably it could be done better (exercise for the reader?).
# as for tr command, please read Unix and linux shell program Chap12
if echo $@ | tr -d [:blank:] | tr -d [:digit:] | grep . &> /dev/null;
then
exit $E_BADARGS
fi
#how to draw
BOX_HEIGHT=`expr $3 - 1` # -1 correction needed because angle char "+" is
BOX_WIDTH=`expr $4 - 1` #+ a part of both box height and width.
T_ROWS=`tput lines` # Define current terminal dimension
T_COLS=`tput cols` #+ in rows and columns.
#---------------------Check each argument ----------------#
if [ $1 -lt 1 ] || [ $1 -gt $T_ROWS ];
then # Start checking if arguments are correct.
exit $E_BADARGS
fi
if [ $2 -lt 1 ] || [ $2 -gt $T_COLS ]; then
exit $E_BADARGS
fi
if [ `expr $1 + $BOX_HEIGHT + 1` -gt $T_ROWS ];
then # as for expr command, please read unix and shell program, chap17.5
exit $E_BADARGS
fi
if [ `expr $2 + $BOX_WIDTH + 1` -gt $T_COLS ]; then
exit $E_BADARGS
fi
if [ $3 -lt 1 ] || [ $4 -lt 1 ]; then
exit $E_BADARGS
fi # End checking arguments.
#-------------------End of checking each argument ----------------#
#-------------plot_char() --------------------------------------#
plot_char()
{ # Function within a function.
echo -e "\E[${1};${2}H"$3 #make the $1 and $2 in some color? yes
# try like this:
# $ echo -e '\E[34;47mThis prints in blue.'; tput sgr0
}
-
echo -ne "\E[3${5}m" # Set box frame color, if defined.
#----------------start drawing the box ---------------------#
count=1 # Draw vertical lines using plot_char function.
#----the Height of box in row-----
for (( r=$1; count<=$BOX_HEIGHT; r++));
do
plot_char $r $2 $VERT #invoke plot_char
let count=count+1
done
#-------the Width of the box in row-----------------#
count=1
c=`expr $2 + $BOX_WIDTH`
for (( r=$1; count<=$BOX_HEIGHT; r++));
do
plot_char $r $c $VERT
let count=count+1
done
-
#----------the width of the box in column ------#
count=1
for (( c=$2; count<=$BOX_WIDTH; c++));
do
plot_char $1 $c $HORZ
let count=count+1
done
# ----------------------------------It is difficult to fix this --My code-------------------Text --------------#
echo -e \+$text # add the text here
-
#----------the height of the box in column ------#
count=1
r=`expr $1 + $BOX_HEIGHT`
for (( c=$2; count<=$BOX_WIDTH; c++)); do
plot_char $r $c $HORZ
let count=count+1
done
# ----------Draw box angles.-------------#
plot_char $1 $2 $CORNER_CHAR
plot_char $1 `expr $2 + $BOX_WIDTH` +
plot_char `expr $1 + $BOX_HEIGHT` $2 +
plot_char `expr $1 + $BOX_HEIGHT` `expr $2 + $BOX_WIDTH` +
# -----------Restore old colors.
echo -ne "\E[0m"
#----------- Put the prompt at bottom of the terminal.------------------------------------>
P_ROWS=`expr $T_ROWS - 1`
echo -e "\E[${P_ROWS};1H"
}
main_menu () { # drawing the main menu
clear # Clear the terminal.
#------------- draw 4 boxes called Menu, Statistic,Tools,Help.
# Now I can set the content. Finally I did it! ------#
# I think I should use it as Main_menu funtion
i=0
R=1 #because i and R will be as loop variable.
while [ $i -lt 4 ] #I will draw 4 boxes for Main Menu
do
C=1 # Column
H=3 # Height
W=13 # Width
col=1 # Color (red)
case "$i" in
0)text=Menu
draw_box $R $C $H $W $col ;;
1)text=1-Statistic
draw_box $R $C $H $W $col ;;
2)text=2-Help
draw_box $R $C $H $W $col ;;
3)text=3-Tools
draw_box $R $C $H $W $col ;;
esac
-
let i+=1
let R+=3
done
}
main_menu
echo "Usage:h for getting information "
echo " t for doing options "
echo " s for makeing statistic"
-