/* example for a simple yes/no question without loading the dll */ /* REXXUTIL */ /* example call ... */ thisKey = AskUser( "YN", "Enter Y or N: " ) say "You entered '" || thisKey || "'." exit /* ------------------------------------------------------------------ */ /* AskUser - get input from the user */ /* */ /* Usage: AskUser akeys, prompt */ /* */ /* where: */ /* akeys - allowed keys (all keys are translated to */ /* uppercase) */ /* prompt - prompt for the ask */ /* */ /* Returns: the pressed key in uppercase */ /* */ /* note: This routine uses ESC sequences to position the cursor. */ /* This routine only works if you do not use the */ /* last line of the screen for the prompt! */ /* */ AskUser: PROCEDURE parse arg aKeys, prompt aKeys = translate( akeys ) /* set word wrap off */ call CharOut , "1B"x || "[7l" if prompt <> "" then call charout , prompt thisKey = " " do UNTIL pos( thisKey , aKeys ) <> 0 call charOut ,"1B"x || "[s" || "1B"x || "[K" thisKey = translate( charIn() ) call CharOut , "1B"x || "[u" /* delete the CR/LF sequence from */ /* the keyboard buffer! */ dummy = lineIn() end /* do until ... */ /* set word wrap on again */ call CharOut , "1B"x || "[7h" /* do a linefeed */ say "" RETURN thisKey