Annotation of capa/capa51/CapaTools/CAPAscreen.pl, revision 1.1
1.1 ! albertel 1: #!/usr/local/bin/perl
! 2:
! 3: # -----------------------------------------------------------------------------
! 4: #
! 5: # Some routines to facilitate creation of
! 6: # vt100 pseudo-menu driven interface
! 7: #
! 8: # Works under xterm, shelltool, but not commandtool.
! 9: #
! 10: # by Isaac Tsai
! 11: # -----------------------------------------------------------------------------
! 12: #
! 13: sub C_ClearScreen { print "\e[;H\e[2J"; }
! 14: sub C_EraseLine { print "\e[K"; }
! 15: sub C_MoveTo { local($y,$x)=@_; print "\e[$y;$x"; print "H"; }
! 16: sub C_MakeBox {
! 17: local($y1,$x1,$y2,$x2,$title)=@_;
! 18: local($wd)=$x2-$x1;
! 19: local($j,$tlen);
! 20:
! 21: if(x2 >= 0 && x2 <= 80) {
! 22: C_MoveTo($y1,$x1);
! 23: print "+"; print "-" x ($wd-1); print "+";
! 24: if( $title ne "" ) {
! 25: $tlen = length($title); $j = int($x1+($wd - $tlen)/2);
! 26: C_MoveTo($y1,$j); print $title;
! 27: }
! 28: for ($j=$y1+1;$j<$y2;$j++) {
! 29: C_MoveTo($j,$x1);
! 30: print "|"; print " " x ($wd-1) ; print "|";
! 31: }
! 32: C_MoveTo($y2,$x1);
! 33: print "+"; print "-" x ($wd-1); print "+";
! 34: }
! 35: }
! 36:
! 37: # the coordnate of the upper left corner (y, x)
! 38: # the width of the box
! 39: # one line message appear on a separate top box
! 40: # one line title on top of the choice box
! 41: # choice list
! 42: sub C_MultipleChoice {
! 43: local($y1,$x1,$wd,$msg,$title,@items)=@_;
! 44: local($item_cnt)=$#items;
! 45: local($j,$off_y,$idx,$u_in,$done,$msg_out);
! 46: $idx="1"; $off_y = 0;
! 47:
! 48: C_ClearScreen;
! 49: if( $msg ne "" ) {
! 50: # C_MakeBox($y1,$x1,$y1+2,$x1+length($msg)+2);
! 51: C_MakeBox($y1,$x1,$y1+2,$x1+$wd);
! 52: C_MoveTo($y1+1,$x1+1); print $msg;
! 53: $off_y = 4;
! 54: }
! 55: C_MakeBox($y1+$off_y,$x1,$y1+$off_y+$item_cnt+5,$x1+$wd,$title);
! 56: for ($j=0;$j<=$item_cnt;$j++) {
! 57: C_MoveTo($y1+$off_y+$j+2,$x1+2); printf "%2d: %s", $idx,$items[$j];
! 58: $idx++;
! 59: }
! 60: $off_y = $off_y + 4;
! 61: $done = 0;
! 62: while ( $done ne "y" && $done ne "yes" ) {
! 63: $u_in=0;
! 64: while ($u_in < 1 || $u_in > $item_cnt+1 || $u_in =~ /\D/ || $u_in == "") {
! 65: C_MoveTo($y1+$off_y+$item_cnt,$x1+1); &C_EraseLine;
! 66: C_MoveTo($y1+$off_y+$item_cnt,$x1+1); print "SELECT:" . " " x ($wd-8) . "|";
! 67: C_MoveTo($y1+$off_y+$item_cnt,$x1+8);
! 68: $u_in=<>; chop($u_in);
! 69: }
! 70: $msg_out = "Selected item: " . $u_in . " $items[$u_in-1]" . ", (Y <RETURN>, or N)? ";
! 71: $j = length($msg_out);
! 72: C_MoveTo($y1+$off_y+$item_cnt+2,$x1); &C_EraseLine;
! 73: C_MoveTo($y1+$off_y+$item_cnt+2,$x1);
! 74: print $msg_out;
! 75: C_MoveTo($y1+$off_y+$item_cnt+2,$x1+$j);
! 76: $done=<>; chop($done); $done =~ tr/A-Z/a-z/;
! 77: if( length($done) == 0 ) { $done = 'y'; };
! 78: }
! 79: return $u_in;
! 80: }
! 81:
! 82: sub C_InputData {
! 83: local($y,$x,$wd,$title,$limit_len,$prompt,@msgs)=@_;
! 84: local($line_cnt)=$#msgs;
! 85: local($done);
! 86: local($jj,$prom_length);
! 87: local($input,$in_len,$msgout,$msglen);
! 88:
! 89: C_ClearScreen;
! 90: C_MakeBox($y,$x,$y+$line_cnt+2,$x+$wd,$title);
! 91: for($jj=0;$jj<=$line_cnt;$jj++) {
! 92: C_MoveTo($y+$jj+1,$x+1); print " $msgs[$jj]";
! 93: }
! 94: C_MakeBox($y+$line_cnt+4,$x,$y+$line_cnt+6,$x+$wd,"");
! 95: C_MoveTo($y+$line_cnt+5,$x+1); print $prompt;
! 96: $done = 0; $prom_length = length($prompt);
! 97: while( $done ne "y" && $done ne "yes" ) {
! 98: $in_len = 0;
! 99: while(($in_len < 1) || ($in_len > $limit_len) ) {
! 100: C_MoveTo($y+$line_cnt+5, $x+length($prompt)+1); &C_EraseLine;
! 101: C_MoveTo($y+$line_cnt+5, $x+1);
! 102: print $prompt . " " x ($wd - $prom_length - 1) . "|";
! 103: C_MoveTo($y+$line_cnt+5, $x+length($prompt)+1);
! 104: $input = <>; chop($input); $in_len = length($input);
! 105: }
! 106: $msgout = "You entered:\'" . $input . "\', Are you sure (Y or N)? ";
! 107: C_MoveTo($y+$line_cnt+7,$x); &C_EraseLine;
! 108: C_MoveTo($y+$line_cnt+7,$x); print $msgout;
! 109: $msglen = length($msgout);
! 110: C_MoveTo($y+$line_cnt+7,$x+$msglen);
! 111: $done = <>; chop($done); $done =~ tr/A-Z/a-z/;
! 112: }
! 113: return $input;
! 114: }
! 115:
! 116: sub C_InputSetNum {
! 117: local($y,$x,$wd,$title,$limit_len,$prompt,@msgs)=@_;
! 118: local($line_cnt)=$#msgs;
! 119: local($done);
! 120: local($jj,$prom_length);
! 121: local($input,$in_len,$msgout,$msglen);
! 122:
! 123: C_ClearScreen;
! 124: C_MakeBox($y,$x,$y+$line_cnt+2,$x+$wd,$title);
! 125: for($jj=0;$jj<=$line_cnt;$jj++) {
! 126: C_MoveTo($y+$jj+1,$x+1); print " $msgs[$jj]";
! 127: }
! 128: C_MakeBox($y+$line_cnt+4,$x,$y+$line_cnt+6,$x+$wd,"");
! 129: C_MoveTo($y+$line_cnt+5,$x+1); print $prompt;
! 130: $done = 0; $prom_length = length($prompt);
! 131: while( $done ne "y" && $done ne "yes" ) {
! 132: $in_len = 0;
! 133: while(($in_len < 1) || ($in_len > $limit_len) ) {
! 134: C_MoveTo($y+$line_cnt+5, $x+length($prompt)+1); &C_EraseLine;
! 135: C_MoveTo($y+$line_cnt+5, $x+1);
! 136: print $prompt . " " x ($wd - $prom_length - 1) . "|";
! 137: C_MoveTo($y+$line_cnt+5, $x+length($prompt)+1);
! 138: $input = <>; chop($input); $in_len = length($input);
! 139: }
! 140: $msgout = "You entered:\'" . $input . "\', Confirm (Y <RETURN> or N)? ";
! 141: C_MoveTo($y+$line_cnt+7,$x); &C_EraseLine;
! 142: C_MoveTo($y+$line_cnt+7,$x); print $msgout;
! 143: $msglen = length($msgout);
! 144: C_MoveTo($y+$line_cnt+7,$x+$msglen);
! 145: $done = <>; chop($done); $done =~ tr/A-Z/a-z/;
! 146: if(length($done)==0) { $done = 'y'; }
! 147: }
! 148: return $input;
! 149: }
! 150:
! 151: sub C_InputStudentID {
! 152: local($y,$x,$wd,$title,$limit_len,$prompt,@msgs)=@_;
! 153: local($line_cnt)=$#msgs;
! 154: local($done);
! 155: local($jj,$prom_length);
! 156: local($input,$in_len,$msgout,$msglen,$input_ok);
! 157:
! 158: C_ClearScreen;
! 159: C_MakeBox($y,$x,$y+$line_cnt+2,$x+$wd,$title);
! 160: for($jj=0;$jj<=$line_cnt;$jj++) {
! 161: C_MoveTo($y+$jj+1,$x+1); print " $msgs[$jj]";
! 162: }
! 163: C_MakeBox($y+$line_cnt+4,$x,$y+$line_cnt+6,$x+$wd,"");
! 164: C_MoveTo($y+$line_cnt+5,$x+1); print $prompt;
! 165: $done = 0; $prom_length = length($prompt);
! 166: while( $done ne "y" && $done ne "yes" ) {
! 167: $in_len = 0; $input_ok = 0;
! 168: while( ! $input_ok ) {
! 169: C_MoveTo($y+$line_cnt+5, $x+length($prompt)+1); &C_EraseLine;
! 170: C_MoveTo($y+$line_cnt+5, $x+1);
! 171: print $prompt . " " x ($wd - $prom_length - 1) . "|";
! 172: C_MoveTo($y+$line_cnt+5, $x+length($prompt)+1);
! 173: $input = <>; chop($input); $in_len = length($input);
! 174: if( $in_len <= $limit_len ) { $input_ok = 1; }
! 175: }
! 176: if( $in_len == 0 ) {
! 177: $msgout = "Exit this dialog? Confirm (Y <RETURN> or N)? ";
! 178: } else {
! 179: $msgout = "You entered:\'" . $input . "\', Confirm (Y <RETURN> or N)? ";
! 180: }
! 181: C_MoveTo($y+$line_cnt+7,$x); &C_EraseLine;
! 182: C_MoveTo($y+$line_cnt+7,$x); print $msgout;
! 183: $msglen = length($msgout);
! 184: C_MoveTo($y+$line_cnt+7,$x+$msglen);
! 185: $done = <>; chop($done); $done =~ tr/A-Z/a-z/;
! 186: if(length($done)==0) { $done = 'y'; }
! 187: }
! 188: return $input;
! 189: }
! 190:
! 191:
! 192:
! 193: sub C_InputFromToNum {
! 194: local($y,$x,$wd,$title,$limit_len,$prompt,@msgs)=@_;
! 195: local($line_cnt)=$#msgs;
! 196: local($done);
! 197: local($jj,$prom_length);
! 198: local($input,$in_len,$msgout,$msglen);
! 199:
! 200: C_ClearScreen;
! 201: C_MakeBox($y,$x,$y+$line_cnt+2,$x+$wd,$title);
! 202: for($jj=0;$jj<=$line_cnt;$jj++) {
! 203: C_MoveTo($y+$jj+1,$x+1); print " $msgs[$jj]";
! 204: }
! 205: C_MakeBox($y+$line_cnt+4,$x,$y+$line_cnt+6,$x+$wd,"");
! 206: C_MoveTo($y+$line_cnt+5,$x+1); print $prompt;
! 207: $done = 0; $prom_length = length($prompt);
! 208: while( $done ne "y" && $done ne "yes" ) {
! 209: $in_len = 0;
! 210: while(($in_len < 1) || ($in_len > $limit_len) ) {
! 211: C_MoveTo($y+$line_cnt+5, $x+length($prompt)+1); &C_EraseLine;
! 212: C_MoveTo($y+$line_cnt+5, $x+1);
! 213: print $prompt . " " x ($wd - $prom_length - 1) . "|";
! 214: C_MoveTo($y+$line_cnt+5, $x+length($prompt)+1);
! 215: $input = <>; chop($input); $in_len = length($input);
! 216: }
! 217: $msgout = "You entered:\'" . $input . "\', Confirm (Y <RETURN> or N)? ";
! 218: C_MoveTo($y+$line_cnt+7,$x); &C_EraseLine;
! 219: C_MoveTo($y+$line_cnt+7,$x); print $msgout;
! 220: $msglen = length($msgout);
! 221: C_MoveTo($y+$line_cnt+7,$x+$msglen);
! 222: $done = <>; chop($done); $done =~ tr/A-Z/a-z/;
! 223: if(length($done)==0) { $done = 'y'; }
! 224: }
! 225: return ($input);
! 226: }
! 227:
! 228:
! 229:
! 230: sub C_Warn {
! 231: local($y,$x,$wd,$title,@items)=@_;
! 232: local($item_cnt)=$#items;
! 233: local($j,$done);
! 234:
! 235: $wd = 25 if( $wd < 25 );
! 236: $done = 'n';
! 237: C_ClearScreen;
! 238: C_MakeBox($y,$x,$y+$item_cnt+5,$x+$wd,$title);
! 239: for ($j=0;$j<=$item_cnt;$j++) {
! 240: C_MoveTo($y+$j+2,$x+1); print " $items[$j]";
! 241: }
! 242: while( $done ne 'y' ) {
! 243: C_MoveTo($y+$item_cnt+4,$x+$wd-25); print "press Return to continue";
! 244: $done = <>; $done = 'y';
! 245: }
! 246: C_ClearScreen;
! 247: return 1;
! 248: }
! 249:
! 250:
! 251: sub C_MultilineMsgs {
! 252: local($y,$x,$wd,$title,$prompt,@msgs)=@_;
! 253: local($line_cnt)=$#msgs;
! 254: local($done);
! 255: local($jj);
! 256: local($len);
! 257:
! 258: C_ClearScreen;
! 259: $len = length($prompt);
! 260: C_MakeBox($y,$x,$y+$line_cnt+5,$x+$wd,$title);
! 261: for($jj=0;$jj<=$line_cnt;$jj++) {
! 262: C_MoveTo($y+$jj+2,$x+1); print " $msgs[$jj]";
! 263: }
! 264: C_MoveTo($y+$line_cnt+4,$x+$wd-$len-1); print $prompt;
! 265: $done = <>;
! 266: C_ClearScreen;
! 267: }
! 268:
! 269:
! 270: sub C_Pause {
! 271: local($done);
! 272:
! 273: print "Press RETURN to continue"; $done=<>;
! 274: }
! 275:
! 276:
! 277:
! 278: 1;
! 279:
! 280:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>