REM >UI REM Set of user interface functions, particularly parameter input. REM ======================================================================== DEF FNget_num_param(prompt$, default, min, max) REM ======================================================================== REM *** Changed, 9 May 99 - no longer allows default outside min-max range. LOCAL x%,y%,r$,val PRINTprompt$;" [";default;"]: "; x%=POS:y%=VPOS REPEAT PRINTTAB(x%,y%);SPC(80-x%);TAB(x%,y%); INPUT""r$ IF r$="" THEN val=default ELSE val=VAL(r$) UNTIL val>=min AND val<=max =val REM ======================================================================== DEF FNget_str_param(prompt$, default$) REM ======================================================================== LOCAL r$ PRINTprompt$;" [";default$;"]: "; INPUT""r$ IF r$="" THEN =default$ ELSE =r$ REM ======================================================================== DEF FNask_yes_no(prompt$) REM ======================================================================== REM Returns 1 for yes (rather than -1); 0 for no REM Single keypress required. LOCAL g% PRINTprompt$; REPEAT g%=GET IF g%>=ASC"a" AND g%<=ASC"z" THEN g%-=32 UNTIL g%=ASC"Y" OR g%=ASC"N" VDU g% IF g%=ASC"Y" =1 =0 REM ======================================================================== DEF FNget_letter_param(prompt$, valid$, default$) REM ======================================================================== REM Returns a single upper-case letter that is within valid$ REM The default is taken as the (upper-case) first letter of default$ REM The default *must* be in valid$ for it to succeed. REM Allows editing of string, i.e. requires Enter to confirm. LOCAL g$, v$, x%, y%, r$ v$ = FNuppercase_string(valid$) d$ = FNuppercase_char(LEFT$(default$,1)) PRINTprompt$;" [";d$;"]: "; x%=POS:y%=VPOS REPEAT PRINTTAB(x%,y%);SPC(80-x%);TAB(x%,y%); INPUT""r$ IF r$="" THEN g$ = d$ ELSE g$ = FNuppercase_char(LEFT$(r$,1)) UNTIL LEN(r$)<2 AND LEN(g$)=1 AND INSTR(v$,g$)>0 =g$ REM ======================================================================== DEF FNget_letter_param_as_num(prompt$, valid$, default$) REM ======================================================================== REM As for FNget_letter_param, but returns an integer (1...) REM based upon the ordered position of the response in valid$. LOCAL v$ v$ = FNuppercase_string(valid$) =INSTR(v$, FNget_letter_param(prompt$, v$, default$)) DEF FNuppercase_ascii(c%) IF c%>=ASC"a" AND c%<=ASC"z" THEN c%-=32 =c% DEF FNuppercase_char(c$) IF LEN(c$)=0 THEN ="" IF LEN(c$)>1 THEN c$=LEFT$(c$,1) =CHR$(FNuppercase_ascii(ASC(c$))) DEF FNuppercase_string(s$) LOCAL t$, i% IF LEN(s$)=0 THEN ="" FOR i%=1 TO LEN(s$) t$ += FNuppercase_char(MID$(s$,i%,1)) NEXT =t$ REM ======================================================================== DEF PROCprint_centered(s$) REM ======================================================================== REM Assumes 80-column display and doesn't do much about >80-character strings. PRINTTAB(80-LEN(s$)/2);s$ ENDPROC REM ======================================================================== DEF PROCdefine_colours REM ======================================================================== REM Assumes 16-colour mode (mode 12, or whatever it is). black%=0 red%=1 green%=2 yellow%=3 blue%=4 magenta%=5 cyan%=6 white%=7 ENDPROC