home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fred Fish Collection 1.5
/
ffcollection-1-5-1992-11.iso
/
ff_disks
/
200-299
/
ff239.lzh
/
JGoodies
/
Brunjes
/
SpaceOrEscape
< prev
next >
Wrap
Text File
|
1989-08-21
|
4KB
|
112 lines
\ Word to pause scrolling output from a program.
\
\ SpaceOrESC? ( -- )
\
\ This word is responsible for handling Space Bar presses to toggle the
\ activity of a program (presumably for stopping the scrolling of text).
\ It also looks for an ESCAPE key press. If it is seen, an ABORT is done.
\ Call this word from inside the loop of a program that prints
\ a long time.
\
\ For example:
\ : LONGPROG ( -- )
\ 200 0 DO i . ." Hello" cr SpaceOrEsc? LOOP
\ ;
\ LONGPROG ( then hit space bar to stop and start output )
\ ( hit ESCAPE to abort )
\
ANEW SpaceOrEscape
Variable Escape.Flag ( Used to tell if we should ABORT when we see ESC )
1 Escape.Flag ! ( By default, we ABORT when user presses ESCAPE )
: ?BL ( n -- )
\
\ This word looks at n (an ASCII character code). If it is a BLANK (space),
\ then this word waits for another space to be pressed and then returns.
\ Note that this word eats the character passed to it!
\
BL = IF ( TRUE if char typed was a BLank )
KEY DROP ( Now throw away the char typed )
THEN
;
: ?ESC ( n -- n F | -- T | -- n | ABORT )
\
\ This word's action depends on the value of the variable Escape.Flag.
\ If this variable is TRUE, then n is compared to ESCAPE (ASCII 27).
\ If n = 27, then an ABORT is executed.
\ If n <> 27, then n is returned.
\ If Escape.Flag is FALSE, then n is compared to ESCAPE (ASCII 27).
\ If n = 27, then TRUE is returned.
\ If n <> 27, then n is returned under 0.
\
DUP
Escape.Flag @
IF ( TRUE if pgmr wants to abort on ESCAPE )
27 =
IF ( TRUE if pgmr wants to abort & ESC pressed )
CR ." Program Aborted by ESCAPE key. " DROP ( drop ESC char )
ABORT
ELSE ( Pgmr wants to abort on ESC, but not pressed )
( Do nothing! ) ( ESC not pressed -- return key struck )
THEN
ELSE ( Pgmr does NOT want to abort on ESCAPE )
27 =
IF ( TRUE if pgmr doesn't want to abort & ESC )
DROP ( pressed )
1 ( Indicate that ESCAPE was pressed )
ELSE
0 ( Indicate that ESCAPE was NOT pressed )
THEN
THEN ;
: CheckItOut ( -- )
\
\ See if char typed demands handling or ignoring.
KEY ?ESC ( only valid to have these two ?ESC and ?BL back to )
?BL ; ( back when Escape.Flag is TRUE, otherwise ?ESC might )
( return TWO values [one of them a flag, on top] )
: SpaceOrESC? ( -- )
\
\ This word is responsible for handling Space Bar presses to toggle the
\ activity of a program (presumably for stopping the scrolling of text).
\ It also looks for an ESCAPE key press. If it is seen, an ABORT is done.
\
?TERMINAL IF CheckItOut THEN ;
( The following three words are for example only and need not be compiled )
( unless you really want them to be. )
\
\ : Test1 ( Immediately abort )
\ 1 Escape.Flag ! ( Abort on ESC )
\ 1000 0 DO I . SpaceorESC? loop ;
\
\ : Test2 ( Completely ignore ABORT signal and continue processing )
\ 0 Escape.Flag ! ( No Abort on ESC )
\ 1000 0 DO I . ?TERMINAL
\ IF
\ KEY
\ ?ESC IF ." Softly Aborting ... " ." Wait! "
\ ELSE
\ ?BL
\ THEN
\ THEN
\ LOOP ;
\
\ : Test3 ( Quickly perform abort, but not immediately )
\ 0 Escape.Flag ! ( No Abort on ESC )
\ 1000 0 DO I . ?TERMINAL
\ IF
\ KEY
\ ?ESC IF ." Softly Aborting ... " ." OK, ready to ABORT. " ABORT
\ ELSE
\ ?BL
\ THEN
\ THEN
\ LOOP ;