home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / ckscripts / menu < prev    next >
Text File  |  2020-01-01  |  3KB  |  74 lines

  1. #!/usr/local/bin/kermit
  2. #
  3. # MENU
  4. #
  5. # Skeleton of a simple menu program to be executed by C-Kermit 7.0
  6. # or later: http://www.columbia.edu/kermit/
  7. #
  8. # User gets a menu with a numbered list of choices.  User presses a digit
  9. # key to make a choice.  Choice is executed.  Illustrates use of the SCREEN
  10. # command to format the screen and the GETC command to read a single
  11. # character from the keyboard, as well as nested WHILE loops, SWITCH, etc.
  12. #
  13. # Author: F. da Cruz, Columbia University
  14. # V 1.0, 20 Apr 1999
  15. #
  16. local \%c                                 ; Local variable
  17.  
  18. define MSG {
  19.     if > \v(argc) 2 screen move \%2 \%3   ; Move to given row/col (if any)
  20.     screen cleol                          ; Clear to end of line
  21.     if def \%1 xecho \fcontents(\%1)      ; Print message (if any)
  22. }
  23. define BOT {                              ; Put cursor on screen bottom
  24.     screen move \v(rows) 0
  25. }
  26. define CENTER {                           ; Print argument centered
  27.     local \%x                             ; Variable local to this routine
  28.     if not def \%2 def \%2 1              ; Default if no column argument
  29.     .\%x ::= (\v(cols)-\flen(\%1))/2      ; Calculate centered position
  30.     msg {\%1} {\%2} {\%x}                 ; Print arg string centered
  31. }
  32. define PAINT {                            ; Put the menu on the screen
  33.     screen clear                          ; Clear the screen
  34.     center {Welcome to This Menu} 2       ; Print title centered
  35.     msg {Choices:} 4                      ; Print heading
  36.     msg { 1. File} 6                      ; Print choice lines
  37.     msg { 2. Edit} 7
  38.     msg { 3. Exit} 8
  39. }
  40. define DOFILE {                           ; Dummy FILE routine
  41.     msg {Filing... } 12                   ; Fill in as desired...
  42. }
  43. define DOEDIT {                           ; Dummy EDIT routine
  44.     msg {Editing...} 12                   ; Fill in as desired...
  45. }
  46. define DOEXIT {                           ; Dummy EXIT routine
  47.     msg {Exiting...} 12                   ; Fill in as desired...
  48. }
  49.  
  50. def \%c 0                                 ; Menu choice variable
  51. paint                                     ; Display the menu
  52. while ( != \%c 3 ) {                      ; Read and verify choice
  53.     while true {                          ; Loop till we get a good one
  54.     screen move 10                    ; Move to line 10 (left margin)
  55.     screen cleol                      ; Clear this line
  56.     getc \%c {Your choice: }          ; Prompt and get and echo 1 char
  57.     if ( < \fcode(\%c) 32 ) continue  ; Ignore control characters
  58.     xecho \%c                         ; Echo the choice
  59.     if ( not numeric \%c ) {          ; Make sure it's a number
  60.             msg {Not numeric - "\%c"} 12
  61.             continue
  62.         }
  63.     if ( >= \%c 1 && <= \%c 3 ) break ; Range check - break if OK.
  64.     msg {Out of range - "\%c"} 12     ; Keep looping if not OK.
  65.     }
  66.     switch \%c {                          ; Valid choice - execute it.
  67.       :1, dofile, break
  68.       :2, doedit, break
  69.       :3, doexit, break
  70.     }
  71. }
  72. bot                                       ; Leave cursor at screen bottom.
  73. exit 0 Bye                                ; And exit.
  74.