home *** CD-ROM | disk | FTP | other *** search
- ;;; -*- Mode: LISP -*- Syntax: AutoLISP (C) Benjamin Olasov 1988, 1989
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; File: MENU.LSP Copyright (C) Benjamin Olasov Graphic Systems, Inc. ;;;
- ;;; Inquiries: ;;;
- ;;; ;;;
- ;;; Benjamin Olasov ;;;
- ;;; Graphic Systems, Inc.: ;;;
- ;;; ;;;
- ;;; New York, NY: PH (212) 725-4617 ;;;
- ;;; Cambridge, MA: PH (617) 492-1148 ;;;
- ;;; MCI-Mail: GSI-NY 344-4003 ;;;
- ;;; Arpanet: olasov@cs.columbia.edu ;;;
- ;;; ;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- ;; This program is provided 'as is' without warranty of any kind, either
- ;; expressed or implied, including, but not limited to the implied warranties of
- ;; merchantability and fitness for a particular purpose. The entire risk as to
- ;; the quality and performance of the program is with the user. Should the
- ;; program prove defective, the user assumes the entire cost of all necessary
- ;; servicing, repair or correction.
- ;; AutoLisp and AutoCad are registered trademarks of AutoDesk, Inc.
-
-
- ;; This function creates menus in text screen mode for AutoLISP.
- ;; It assumes an 80 column textscreen monitor and ANSI.SYS graphics device
- ;; MENU-OPERATION looks for and returns an integer.
-
- ;; In this version, the header, prompt and individual items in the item-list
- ;; MUST all be strings, that is, surrounded by double quotes. ex.: "STRING"
- ;; The syntax is:
- ;;
- ;; (menu-operation "header" '("item-1" "item-2" ... "item-n") "prompt")
-
- (TEXTSCR)
-
- (VMON)
-
- (GC)
-
- (EXPAND 3)
-
- (princ "\nPlease wait- loading")
-
- (DEFUN MENU-OPERATION (HEADER ITEM-LIST PROMPT / HEIGHT WIDTH COUNTER L-COL)
- (TEXTSCR)
- (PRINC "\e[2J")
- (IF (/= (REM (STRLEN HEADER) 2) 0) (SETQ HEADER (STRCAT HEADER " ")))
- (SETQ HEIGHT (+ 9 (LENGTH ITEM-LIST))
- WIDTH (+ 10 (MAX (LONGEST ITEM-LIST) (STRLEN HEADER))))
- (IF (/= (REM HEIGHT 2) 0) (SETQ HEIGHT (1+ HEIGHT)))
- (IF (/= (REM WIDTH 2) 0) (SETQ WIDTH (1+ WIDTH)))
- (SETQ L-COL (- 40 (/ WIDTH 2))
- COUNTER 0)
- (REPEAT (- 12 (/ HEIGHT 2)) (TERPRI))
- (REPEAT L-COL (PRINC " "))
- (PRINC (CHR 201))
- (REPEAT (- WIDTH 2) (PRINC (CHR 205)))
- (PRINC (CHR 187)) (TERPRI)
- (BLANK L-COL WIDTH)
- (REPEAT L-COL (PRINC " "))
- (PRINC (CHR 186))
- (REPEAT (- (- (/ WIDTH 2) (/ (STRLEN HEADER) 2)) 1) (PRINC " "))
- (BOLD)
- (PRINC HEADER)
- (NORMAL)
- (REPEAT (- (- (/ WIDTH 2) (/ (STRLEN HEADER) 2)) 1) (PRINC " "))
- (PRINC (CHR 186)) (TERPRI)
- (BLANK L-COL WIDTH)
- (REPEAT L-COL (PRINC " "))
- (PRINC (CHR 204))
- (REPEAT (- WIDTH 2) (PRINC (CHR 205)))
- (PRINC (CHR 185)) (TERPRI)
- (REPEAT L-COL (PRINC " "))
- (PRINC (CHR 186))
- (REPEAT (- WIDTH 2) (PRINC " "))
- (PRINC (CHR 186))
- (FOREACH ITEM ITEM-LIST
- (SETQ COUNTER (1+ COUNTER))
- (TERPRI)
- (REPEAT L-COL (PRINC " "))
- (PRINC (STRCAT (CHR 186) " " (RTOS (FLOAT COUNTER) 2 0) "] " ITEM))
- (REPEAT (- WIDTH (+ 6 (STRLEN (RTOS (FLOAT COUNTER) 2 0))
- (STRLEN ITEM)))
- (PRINC " "))
- (PRINC (CHR 186)))
- (TERPRI)
- (BLANK L-COL WIDTH)
- (REPEAT L-COL (PRINC " "))
- (PRINC (CHR 200))
- (REPEAT (- WIDTH 2) (PRINC (CHR 205)))
- (PRINC (CHR 188))
- (BOLD)
- (PRINC (STRCAT "\n\n" PROMPT))
- (NORMAL)
- (SETQ CHOICE (GETINT))
- (WHILE (OR (< CHOICE 1) (> CHOICE (LENGTH ITEM-LIST)))
- (SETQ CHOICE (GETINT "Choice is out of range, try again: ")))
- (PRINC "\e[2J") CHOICE)
-
- (princ ".")
-
- ;;length of longest string in a list of strings
- (DEFUN LONGEST (LST)
- (APPLY 'MAX (MAPCAR '(LAMBDA (ITM) (STRLEN ITM)) LST)))
-
- (princ ".")
-
- (DEFUN BLANK (COL WIDTH)
- (REPEAT COL (PRINC " "))
- (PRINC (CHR 186))
- (REPEAT (- WIDTH 2) (PRINC " "))
- (PRINC (CHR 186))
- (TERPRI))
-
- (princ ".")
-
- (DEFUN BOLD ()
- (PRINC "\e[1m"))
-
- (princ ".")
-
- (DEFUN NORMAL ()
- (PRINC "\e[0m"))
-
- (princ ".")
-
- ;; This an an example of using MENU-OPERATION to get a value from the user.
- ;; The first argument must be the header.
- ;; The second argument must be a list of things to be chosen from.
- ;; The third argument must be a prompt [question] to the user.
- ;; MENU-OPERATION looks for and returns an integer.
-
- (defun c:test ()
- (setq woodtype
- (menu-operation "WOOD MENU"
- '("Cedar, western red"
- "Cedar, northern or southern white"
- "Cypress, southern"
- "Douglas fir, western"
- "Douglas fir, Rocky mountain region"
- "Fir, balsam"
- "Fir, golden"
- "Hemlock, eastern"
- "Larch, western"
- "Oak, commerical white or red"
- "Pine, southern yellow"
- "Pine, California, midwestern, or northern"
- "Redwood"
- "Spruce, Engelemann"
- "Tamarack, eastern")
- "Select number corresponding to type of wood to be used: ")))
-
-
- (princ "\e[2J")
- (princ "\nThis menu system is written for the ANSI graphics standard.")
- (princ "\nIf your screen didn't just clear, you must add the line:")
- (princ "\n\nDEVICE=ANSI.SYS\n")
- (princ "\nto your CONFIG.SYS file in order to use MENU-OPERATION.")
- (princ "\n\nThe syntax is: ")
- (princ "\n\n\(menu-operation \"header\" '(\"item-1\" \"item-2\" ... \"item-n\") \"prompt\"\)")
- (princ "\n\nType TEST to try a sample menu.")
- (princ)
-
-