作者 Heefan [actionscript] 2007-04-28 14:11 (点击下载)

  1. 我想这样显示:
  2. ------------------------------------
  3. | invoke funtion and show some |
  4. | information here |
  5. | --message 1 |
  6. | | |
  7. | |
  8. | |
  9. | | <--- SCREEN
  10. | |
  11. |echo something here |
  12. |hello |
  13. |Linuxsir ----message2 |
  14. |$ |
  15. |-----------------------------------
  16. 问题描述
  17. message1 和 message2不能共享一个屏幕阿
  18. 就是说,我调用 message1后,在调用message2,
  19. 那么屏幕上 message1中信息将不完全显示在一个屏幕了。
  20.  
  21. 我修改 ABS上画盒子的代码,做菜单玩玩的:
  22. 可以shell中运行一下。抓图中,上边还有显示一个 MENU 的盒子,但是显示不出来。。。
  23.  
  24. #!/bin/bash
  25. # Draw-box.sh: Drawing a box using ASCII characters.
  26. # Script by Stefano Palmeri, with minor editing by document author.
  27. # Used in the "ABS Guide" with permission.
  28.  
  29.  
  30. ######################################################################
  31. ### draw_box function doc ###
  32.  
  33. # The "draw_box" function lets the user
  34. #+ draw a box into a terminal.
  35. #
  36. # Usage: draw_box ROW COLUMN HEIGHT WIDTH [COLOR]
  37. #
  38. # ROW and COLUMN represent the position
  39. #+ of the upper left angle of the box you're going to draw.
  40. # ROW and COLUMN must be greater than 0
  41. #+ and less than current terminal dimension.
  42. # HEIGHT is the number of rows of the box, and must be > 0.
  43. # HEIGHT + ROW must be <= than current terminal height.
  44. # WIDTH is the number of columns of the box and must be > 0.
  45. # WIDTH + COLUMN must be <= than current terminal width.
  46. #
  47. # E.g.: If your terminal dimension is 20x80,
  48. # draw_box 2 3 10 45 is good
  49. # draw_box 2 3 19 45 has bad HEIGHT value (19+2 > 20)
  50. # draw_box 2 3 18 78 has bad WIDTH value (78+3 > 80)
  51. #
  52. # COLOR is the color of the box frame.
  53. # This is the 5th argument and is optional.
  54. # 0=black 1=red 2=green 3=tan 4=blue 5=purple 6=cyan 7=white.
  55. # If you pass the function bad arguments,
  56. #+ it will just exit with code 65,
  57. #+ and no messages will be printed on stderr.
  58. #
  59. # Clear the terminal before you start to draw a box.
  60. # The clear command is not contained within the function.
  61. # This allows the user to draw multiple boxes, even overlapping ones.
  62.  
  63. ### end of draw_box function doc ###
  64. ######################################################################
  65.  
  66. draw_box(){
  67.  
  68. #=============#
  69. #drwa a box
  70. HORZ="-"
  71. VERT="|"
  72. CORNER_CHAR="+"
  73.  
  74. #test the number of arguments first
  75. MINARGS=4
  76. E_BADARGS=65
  77. #=============#
  78.  
  79.  
  80. if [ $# -lt "$MINARGS" ];
  81. then # If args are less than 4, exit.
  82. exit $E_BADARGS
  83. fi
  84.  
  85. # Looking for non digit chars in arguments.
  86. # Probably it could be done better (exercise for the reader?).
  87. # as for tr command, please read Unix and linux shell program Chap12
  88. if echo $@ | tr -d [:blank:] | tr -d [:digit:] | grep . &> /dev/null;
  89. then
  90. exit $E_BADARGS
  91. fi
  92.  
  93. #how to draw
  94. BOX_HEIGHT=`expr $3 - 1` # -1 correction needed because angle char "+" is
  95. BOX_WIDTH=`expr $4 - 1` #+ a part of both box height and width.
  96. T_ROWS=`tput lines` # Define current terminal dimension
  97. T_COLS=`tput cols` #+ in rows and columns.
  98.  
  99. #---------------------Check each argument ----------------#
  100. if [ $1 -lt 1 ] || [ $1 -gt $T_ROWS ];
  101. then # Start checking if arguments are correct.
  102. exit $E_BADARGS
  103. fi
  104.  
  105. if [ $2 -lt 1 ] || [ $2 -gt $T_COLS ]; then
  106. exit $E_BADARGS
  107. fi
  108.  
  109. if [ `expr $1 + $BOX_HEIGHT + 1` -gt $T_ROWS ];
  110. then # as for expr command, please read unix and shell program, chap17.5
  111. exit $E_BADARGS
  112. fi
  113.  
  114. if [ `expr $2 + $BOX_WIDTH + 1` -gt $T_COLS ]; then
  115. exit $E_BADARGS
  116. fi
  117.  
  118. if [ $3 -lt 1 ] || [ $4 -lt 1 ]; then
  119. exit $E_BADARGS
  120. fi # End checking arguments.
  121. #-------------------End of checking each argument ----------------#
  122.  
  123. #-------------plot_char() --------------------------------------#
  124. plot_char()
  125. { # Function within a function.
  126. echo -e "\E[${1};${2}H"$3 #make the $1 and $2 in some color? yes
  127. # try like this:
  128. # $ echo -e '\E[34;47mThis prints in blue.'; tput sgr0
  129. }
  130. echo -ne "\E[3${5}m" # Set box frame color, if defined.
  131.  
  132.  
  133. #----------------start drawing the box ---------------------#
  134.  
  135. count=1 # Draw vertical lines using plot_char function.
  136.  
  137. #----the Height of box in row-----
  138. for (( r=$1; count<=$BOX_HEIGHT; r++));
  139. do
  140. plot_char $r $2 $VERT #invoke plot_char
  141. let count=count+1
  142. done
  143.  
  144. #-------the Width of the box in row-----------------#
  145. count=1
  146. c=`expr $2 + $BOX_WIDTH`
  147.  
  148. for (( r=$1; count<=$BOX_HEIGHT; r++));
  149. do
  150. plot_char $r $c $VERT
  151. let count=count+1
  152. done
  153. #----------the width of the box in column ------#
  154. count=1
  155. for (( c=$2; count<=$BOX_WIDTH; c++));
  156. do
  157. plot_char $1 $c $HORZ
  158. let count=count+1
  159. done
  160.  
  161. # ----------------------------------It is difficult to fix this --My code-------------------Text --------------#
  162. echo -e \+$text # add the text here
  163. #----------the height of the box in column ------#
  164. count=1
  165. r=`expr $1 + $BOX_HEIGHT`
  166. for (( c=$2; count<=$BOX_WIDTH; c++)); do
  167. plot_char $r $c $HORZ
  168. let count=count+1
  169. done
  170.  
  171. # ----------Draw box angles.-------------#
  172. plot_char $1 $2 $CORNER_CHAR
  173. plot_char $1 `expr $2 + $BOX_WIDTH` +
  174. plot_char `expr $1 + $BOX_HEIGHT` $2 +
  175. plot_char `expr $1 + $BOX_HEIGHT` `expr $2 + $BOX_WIDTH` +
  176.  
  177. # -----------Restore old colors.
  178. echo -ne "\E[0m"
  179.  
  180. #----------- Put the prompt at bottom of the terminal.------------------------------------>
  181. P_ROWS=`expr $T_ROWS - 1`
  182.  
  183. echo -e "\E[${P_ROWS};1H"
  184. }
  185.  
  186. main_menu () { # drawing the main menu
  187. clear # Clear the terminal.
  188. #------------- draw 4 boxes called Menu, Statistic,Tools,Help.
  189. # Now I can set the content. Finally I did it! ------#
  190. # I think I should use it as Main_menu funtion
  191.  
  192. i=0
  193. R=1 #because i and R will be as loop variable.
  194. while [ $i -lt 4 ] #I will draw 4 boxes for Main Menu
  195. do
  196. C=1 # Column
  197. H=3 # Height
  198. W=13 # Width
  199. col=1 # Color (red)
  200. case "$i" in
  201. 0)text=Menu
  202. draw_box $R $C $H $W $col ;;
  203. 1)text=1-Statistic
  204. draw_box $R $C $H $W $col ;;
  205. 2)text=2-Help
  206. draw_box $R $C $H $W $col ;;
  207. 3)text=3-Tools
  208. draw_box $R $C $H $W $col ;;
  209. esac
  210. let i+=1
  211. let R+=3
  212. done
  213.  
  214. }
  215.  
  216. main_menu
  217. echo "Usage:h for getting information "
  218. echo " t for doing options "
  219. echo " s for makeing statistic"
  220.  
  221.  
  222.  
Screenshot
   (点击放大)

提交下面的校正或者修改. (点击这里开始一个新的帖子)
姓名: 在 cookie 中记住我的名字

屏幕抓图:(jpeg 或 png)