Annotation of capa/capa51/CapaTools/CAPAscreen.pl, revision 1.2

1.1       albertel    1: #!/usr/local/bin/perl
                      2: 
                      3: # -----------------------------------------------------------------------------
                      4: #    
                      5: #           Some routines to facilitate creation of 
                      6: #            vt100 pseudo-menu driven interface
1.2     ! albertel    7: #  Copyright (C) 1992-2000 Michigan State University
        !             8: #
        !             9: #  The CAPA system is free software; you can redistribute it and/or
        !            10: #  modify it under the terms of the GNU Library General Public License as
        !            11: #  published by the Free Software Foundation; either version 2 of the
        !            12: #  License, or (at your option) any later version.
        !            13: #
        !            14: #  The CAPA system is distributed in the hope that it will be useful,
        !            15: #  but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            16: #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
        !            17: #  Library General Public License for more details.
        !            18: #
        !            19: #  You should have received a copy of the GNU Library General Public
        !            20: #  License along with the CAPA system; see the file COPYING.  If not,
        !            21: #  write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
        !            22: #  Boston, MA 02111-1307, USA.
        !            23: #
        !            24: #  As a special exception, you have permission to link this program
        !            25: #  with the TtH/TtM library and distribute executables, as long as you
        !            26: #  follow the requirements of the GNU GPL in regard to all of the
        !            27: #  software in the executable aside from TtH/TtM.
1.1       albertel   28: # 
                     29: #  Works under xterm, shelltool, but not commandtool. 
                     30: #   
                     31: #  by Isaac Tsai
                     32: # -----------------------------------------------------------------------------
                     33: #  
                     34: sub  C_ClearScreen { print "\e[;H\e[2J"; }
                     35: sub  C_EraseLine   { print "\e[K"; }
                     36: sub  C_MoveTo      { local($y,$x)=@_; print "\e[$y;$x"; print "H"; }
                     37: sub  C_MakeBox     { 
                     38:     local($y1,$x1,$y2,$x2,$title)=@_;
                     39:     local($wd)=$x2-$x1;	
                     40:     local($j,$tlen);
                     41: 
                     42:     if(x2 >= 0 && x2 <= 80) {
                     43:       C_MoveTo($y1,$x1);
                     44:       print "+"; print "-" x ($wd-1); print "+";
                     45:       if( $title ne "" ) {
                     46:         $tlen = length($title); $j = int($x1+($wd - $tlen)/2);
                     47:         C_MoveTo($y1,$j); print $title;
                     48:       }
                     49:       for ($j=$y1+1;$j<$y2;$j++) { 
                     50:         C_MoveTo($j,$x1);
                     51:         print "|"; print " " x ($wd-1) ;  print "|"; 
                     52:       }
                     53:       C_MoveTo($y2,$x1);
                     54:       print "+"; print "-" x ($wd-1); print "+";
                     55:     }
                     56:  }
                     57: 
                     58: # the coordnate of the upper left corner (y, x)
                     59: # the width of the box
                     60: # one line message appear on a separate top box
                     61: # one line title on top of the choice box
                     62: # choice list
                     63: sub  C_MultipleChoice {
                     64:     local($y1,$x1,$wd,$msg,$title,@items)=@_;
                     65:     local($item_cnt)=$#items;
                     66:     local($j,$off_y,$idx,$u_in,$done,$msg_out);
                     67:     $idx="1"; $off_y = 0;
                     68: 
                     69:     C_ClearScreen;
                     70:     if( $msg ne "" ) {
                     71:       # C_MakeBox($y1,$x1,$y1+2,$x1+length($msg)+2);
                     72:       C_MakeBox($y1,$x1,$y1+2,$x1+$wd);
                     73:       C_MoveTo($y1+1,$x1+1); print $msg;
                     74:       $off_y = 4;
                     75:     }
                     76:     C_MakeBox($y1+$off_y,$x1,$y1+$off_y+$item_cnt+5,$x1+$wd,$title);
                     77:     for ($j=0;$j<=$item_cnt;$j++) {
                     78:       C_MoveTo($y1+$off_y+$j+2,$x1+2); printf "%2d: %s", $idx,$items[$j];
                     79:       $idx++;
                     80:     }
                     81:     $off_y = $off_y + 4;
                     82:     $done = 0;
                     83:     while ( $done ne "y" && $done ne "yes" ) {
                     84:       $u_in=0; 
                     85:       while ($u_in < 1 || $u_in > $item_cnt+1 || $u_in =~ /\D/ || $u_in == "") { 
                     86:         C_MoveTo($y1+$off_y+$item_cnt,$x1+1); &C_EraseLine;
                     87:         C_MoveTo($y1+$off_y+$item_cnt,$x1+1); print "SELECT:" . " " x ($wd-8) . "|";
                     88:         C_MoveTo($y1+$off_y+$item_cnt,$x1+8);
                     89:         $u_in=<>; chop($u_in); 
                     90:       }
                     91:       $msg_out = "Selected item: " . $u_in . " $items[$u_in-1]" . ", (Y <RETURN>, or N)? ";
                     92:       $j = length($msg_out);
                     93:       C_MoveTo($y1+$off_y+$item_cnt+2,$x1); &C_EraseLine;
                     94:       C_MoveTo($y1+$off_y+$item_cnt+2,$x1);
                     95:       print $msg_out;
                     96:       C_MoveTo($y1+$off_y+$item_cnt+2,$x1+$j);
                     97:       $done=<>; chop($done); $done =~ tr/A-Z/a-z/;
                     98:       if( length($done) == 0 ) { $done = 'y'; };
                     99:     }
                    100:   return $u_in;
                    101:  }
                    102: 
                    103: sub  C_InputData {
                    104:     local($y,$x,$wd,$title,$limit_len,$prompt,@msgs)=@_;
                    105:     local($line_cnt)=$#msgs;
                    106:     local($done);
                    107:     local($jj,$prom_length);
                    108:     local($input,$in_len,$msgout,$msglen);
                    109:     
                    110:     C_ClearScreen;
                    111:     C_MakeBox($y,$x,$y+$line_cnt+2,$x+$wd,$title);
                    112:     for($jj=0;$jj<=$line_cnt;$jj++) {
                    113:       C_MoveTo($y+$jj+1,$x+1); print " $msgs[$jj]";
                    114:     }
                    115:     C_MakeBox($y+$line_cnt+4,$x,$y+$line_cnt+6,$x+$wd,"");
                    116:     C_MoveTo($y+$line_cnt+5,$x+1); print $prompt;
                    117:     $done = 0; $prom_length = length($prompt);
                    118:     while( $done ne "y" && $done ne "yes" ) {
                    119:       $in_len = 0;
                    120:       while(($in_len < 1) || ($in_len > $limit_len) ) {
                    121:         C_MoveTo($y+$line_cnt+5, $x+length($prompt)+1); &C_EraseLine;
                    122:         C_MoveTo($y+$line_cnt+5, $x+1); 
                    123:         print $prompt . " " x ($wd - $prom_length - 1) . "|";
                    124:         C_MoveTo($y+$line_cnt+5, $x+length($prompt)+1);
                    125:         $input = <>; chop($input); $in_len = length($input);
                    126:       }
                    127:       $msgout = "You entered:\'" . $input . "\', Are you sure (Y or N)? ";
                    128:       C_MoveTo($y+$line_cnt+7,$x); &C_EraseLine;
                    129:       C_MoveTo($y+$line_cnt+7,$x); print $msgout;
                    130:       $msglen = length($msgout);
                    131:       C_MoveTo($y+$line_cnt+7,$x+$msglen);
                    132:       $done = <>; chop($done); $done =~ tr/A-Z/a-z/;
                    133:     }
                    134:     return $input;
                    135:  }
                    136: 
                    137: sub  C_InputSetNum {
                    138:     local($y,$x,$wd,$title,$limit_len,$prompt,@msgs)=@_;
                    139:     local($line_cnt)=$#msgs;
                    140:     local($done);
                    141:     local($jj,$prom_length);
                    142:     local($input,$in_len,$msgout,$msglen);
                    143:     
                    144:     C_ClearScreen;
                    145:     C_MakeBox($y,$x,$y+$line_cnt+2,$x+$wd,$title);
                    146:     for($jj=0;$jj<=$line_cnt;$jj++) {
                    147:       C_MoveTo($y+$jj+1,$x+1); print " $msgs[$jj]";
                    148:     }
                    149:     C_MakeBox($y+$line_cnt+4,$x,$y+$line_cnt+6,$x+$wd,"");
                    150:     C_MoveTo($y+$line_cnt+5,$x+1); print $prompt;
                    151:     $done = 0; $prom_length = length($prompt);
                    152:     while( $done ne "y" && $done ne "yes" ) {
                    153:       $in_len = 0;
                    154:       while(($in_len < 1) || ($in_len > $limit_len) ) {
                    155:         C_MoveTo($y+$line_cnt+5, $x+length($prompt)+1); &C_EraseLine;
                    156:         C_MoveTo($y+$line_cnt+5, $x+1); 
                    157:         print $prompt . " " x ($wd - $prom_length - 1) . "|";
                    158:         C_MoveTo($y+$line_cnt+5, $x+length($prompt)+1);
                    159:         $input = <>; chop($input); $in_len = length($input);
                    160:       }
                    161:       $msgout = "You entered:\'" . $input . "\', Confirm (Y <RETURN> or N)? ";
                    162:       C_MoveTo($y+$line_cnt+7,$x); &C_EraseLine;
                    163:       C_MoveTo($y+$line_cnt+7,$x); print $msgout;
                    164:       $msglen = length($msgout);
                    165:       C_MoveTo($y+$line_cnt+7,$x+$msglen);
                    166:       $done = <>; chop($done); $done =~ tr/A-Z/a-z/;
                    167:       if(length($done)==0) { $done = 'y'; }
                    168:     }
                    169:     return $input;
                    170:  }
                    171: 
                    172: sub  C_InputStudentID {
                    173:     local($y,$x,$wd,$title,$limit_len,$prompt,@msgs)=@_;
                    174:     local($line_cnt)=$#msgs;
                    175:     local($done);
                    176:     local($jj,$prom_length);
                    177:     local($input,$in_len,$msgout,$msglen,$input_ok);
                    178:     
                    179:     C_ClearScreen;
                    180:     C_MakeBox($y,$x,$y+$line_cnt+2,$x+$wd,$title);
                    181:     for($jj=0;$jj<=$line_cnt;$jj++) {
                    182:       C_MoveTo($y+$jj+1,$x+1); print " $msgs[$jj]";
                    183:     }
                    184:     C_MakeBox($y+$line_cnt+4,$x,$y+$line_cnt+6,$x+$wd,"");
                    185:     C_MoveTo($y+$line_cnt+5,$x+1); print $prompt;
                    186:     $done = 0; $prom_length = length($prompt);
                    187:     while( $done ne "y" && $done ne "yes" ) {
                    188:       $in_len = 0; $input_ok = 0;
                    189:       while( ! $input_ok ) {
                    190:         C_MoveTo($y+$line_cnt+5, $x+length($prompt)+1); &C_EraseLine;
                    191:         C_MoveTo($y+$line_cnt+5, $x+1); 
                    192:         print $prompt . " " x ($wd - $prom_length - 1) . "|";
                    193:         C_MoveTo($y+$line_cnt+5, $x+length($prompt)+1);
                    194:         $input = <>; chop($input); $in_len = length($input);
                    195:         if( $in_len <= $limit_len ) { $input_ok = 1; }
                    196:       }
                    197:       if( $in_len == 0 ) {
                    198:         $msgout = "Exit this dialog? Confirm (Y <RETURN> or N)? ";
                    199:       } else {
                    200:         $msgout = "You entered:\'" . $input . "\', Confirm (Y <RETURN> or N)? ";
                    201:       }
                    202:       C_MoveTo($y+$line_cnt+7,$x); &C_EraseLine;
                    203:       C_MoveTo($y+$line_cnt+7,$x); print $msgout;
                    204:       $msglen = length($msgout);
                    205:       C_MoveTo($y+$line_cnt+7,$x+$msglen);
                    206:       $done = <>; chop($done); $done =~ tr/A-Z/a-z/;
                    207:       if(length($done)==0) { $done = 'y'; }
                    208:     }
                    209:     return $input;
                    210:  }
                    211: 
                    212: 
                    213: 
                    214: sub  C_InputFromToNum {
                    215:     local($y,$x,$wd,$title,$limit_len,$prompt,@msgs)=@_;
                    216:     local($line_cnt)=$#msgs;
                    217:     local($done);
                    218:     local($jj,$prom_length);
                    219:     local($input,$in_len,$msgout,$msglen);
                    220:     
                    221:     C_ClearScreen;
                    222:     C_MakeBox($y,$x,$y+$line_cnt+2,$x+$wd,$title);
                    223:     for($jj=0;$jj<=$line_cnt;$jj++) {
                    224:       C_MoveTo($y+$jj+1,$x+1); print " $msgs[$jj]";
                    225:     }
                    226:     C_MakeBox($y+$line_cnt+4,$x,$y+$line_cnt+6,$x+$wd,"");
                    227:     C_MoveTo($y+$line_cnt+5,$x+1); print $prompt;
                    228:     $done = 0; $prom_length = length($prompt);
                    229:     while( $done ne "y" && $done ne "yes" ) {
                    230:       $in_len = 0;
                    231:       while(($in_len < 1) || ($in_len > $limit_len) ) {
                    232:         C_MoveTo($y+$line_cnt+5, $x+length($prompt)+1); &C_EraseLine;
                    233:         C_MoveTo($y+$line_cnt+5, $x+1); 
                    234:         print $prompt . " " x ($wd - $prom_length - 1) . "|";
                    235:         C_MoveTo($y+$line_cnt+5, $x+length($prompt)+1);
                    236:         $input = <>; chop($input); $in_len = length($input);
                    237:       }
                    238:       $msgout = "You entered:\'" . $input . "\', Confirm (Y <RETURN> or N)? ";
                    239:       C_MoveTo($y+$line_cnt+7,$x); &C_EraseLine;
                    240:       C_MoveTo($y+$line_cnt+7,$x); print $msgout;
                    241:       $msglen = length($msgout);
                    242:       C_MoveTo($y+$line_cnt+7,$x+$msglen);
                    243:       $done = <>; chop($done); $done =~ tr/A-Z/a-z/;
                    244:       if(length($done)==0) { $done = 'y'; }
                    245:     }
                    246:     return ($input);
                    247:  }
                    248: 
                    249: 
                    250: 
                    251: sub  C_Warn {
                    252:    local($y,$x,$wd,$title,@items)=@_;
                    253:    local($item_cnt)=$#items;
                    254:    local($j,$done);
                    255:    
                    256:    $wd = 25 if( $wd < 25 );
                    257:    $done = 'n';
                    258:    C_ClearScreen;
                    259:    C_MakeBox($y,$x,$y+$item_cnt+5,$x+$wd,$title);
                    260:     for ($j=0;$j<=$item_cnt;$j++) {
                    261:       C_MoveTo($y+$j+2,$x+1); print " $items[$j]";
                    262:     }
                    263:    while( $done ne 'y' ) {
                    264:      C_MoveTo($y+$item_cnt+4,$x+$wd-25); print "press Return to continue";
                    265:      $done = <>; $done = 'y';
                    266:    }
                    267:    C_ClearScreen;
                    268:    return 1;
                    269:  }
                    270: 
                    271: 
                    272: sub  C_MultilineMsgs {
                    273:     local($y,$x,$wd,$title,$prompt,@msgs)=@_;
                    274:     local($line_cnt)=$#msgs;
                    275:     local($done);
                    276:     local($jj);
                    277:     local($len);
                    278:     
                    279:     C_ClearScreen;
                    280:     $len = length($prompt);
                    281:     C_MakeBox($y,$x,$y+$line_cnt+5,$x+$wd,$title);
                    282:     for($jj=0;$jj<=$line_cnt;$jj++) {
                    283:       C_MoveTo($y+$jj+2,$x+1); print " $msgs[$jj]";
                    284:     }
                    285:     C_MoveTo($y+$line_cnt+4,$x+$wd-$len-1); print $prompt;
                    286:     $done = <>;
                    287:     C_ClearScreen;
                    288:  }
                    289: 
                    290: 
                    291: sub  C_Pause {
                    292:     local($done);
                    293:     
                    294:     print "Press RETURN to continue"; $done=<>;
                    295:  }
                    296: 
                    297: 
                    298: 
                    299: 1;
                    300: 
                    301: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>