Re: Yes/No -> Si/No / ixnay / better input routine

From: Alfie Costa ([email protected])
Date: Wed Jun 27 2001 - 07:13:58 CEST


On 25 Jun 2001, at 22:04, Michele Andreoli <[email protected]> wrote:

> Sure. This is a lack in the original muLinux Setup design. A function like
> AskYN(), or something similar, could be better. A function of this kind could
> also handle, in uniform way, input like: y,Y,yes,YES,Yes etc.

The various CHOICE-like programs I've seen usually only take one character as
input.

However, it would be nice having a general routine for taking a particular
string. Suppose a program wishes to torture the user by making them type whole
words.

The current way is:

        InputRoutine "Thou shalt type in YES or NO." A
        ...(logic not shown)...

...and the user sees:

        Thou shalt type in YES or NO. <Yep> # (The user typed "Yep".
        Bad input error! Please do better.
        Thou shalt type in YES or NO. <Yeah>
        Bad input error! Please do better.
        Thou shalt type in YES or NO. <Yeth>
        Bad input error! Please do better.
        Thou shalt type in YES or NO. <Yo>
        Bad input error! Please do better.
        Thou shalt type in YES or NO. <Ya>
        ...
        etc, ad nauseum.

This would be nice:

        InputRoutine -a"y,yes:n,no" "Thou shalt type in YES or NO." A
        # and $A would be magically set to 'y' or 'n' only.

The user would see:

        Thou shalt type in YES or NO.

...and if the first key were anything but yYnN, it wouldn't print and there'd
be a beep.

If the user finally gives up and presses 'n', he can only type 'o', (or
backspace), or the computer will beep.

Or, if the user gave up and typed 'y', he'd only be able to type 'e', (or
backspace), and then 's'.

It'd also be nice if the routine gave some sign of how many characters it's
expecting. So if we wanted a four digit number, here's a movie of what the
user would see...

        Enter a four digit number: ----
        Enter a four digit number: 1--- # user types '1'
        Enter a four digit number: 12-- # user types '2'
        Enter a four digit number: 123- # user types '3'
        Enter a four digit number: 1234 # user types '4'

(NB: this would all take place on a single line, not five lines!)

In the case of the yes or no prompt, there's lots of ways it could go...

        Thou shalt type in YES or NO. :
        Thou shalt type in YES or NO. :Y-- # user types 'Y'
        Thou shalt type in YES or NO. :Ye- # user types 'e'
        Thou shalt type in YES or NO. :Y-- # user types backspace
        Thou shalt type in YES or NO. : # user types backspace
        Thou shalt type in YES or NO. :n- # user types 'n'
        Thou shalt type in YES or NO. :no # user types 'o'

Or, the desired input could be greyed, then highlit as the user types. Since
this is e-mail with no highlighting, imagine capital letters are highlighted
letters, and lower case are grey. I.E. yes=gray, YES=bright white.

        Thou shalt type in YES or NO. :
        Thou shalt type in YES or NO. :Yes # user types 'y'
        Thou shalt type in YES or NO. :YEs # user types 'e'
        Thou shalt type in YES or NO. :YES # user types 's'

--
Though there are many ways to do it, the thing that these methods have in 
common is preventing bad input.  As opposed to letting the user type crazy 
things, then writing code to tell them they're crazy, or worse, letting them 
type something so unexpected the program crashes.
It's strange that video games were doing tricks like this in 1980, and 
"serious" code like Unix scripts (running on much better computers) still don't 
do it.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


This archive was generated by hypermail 2.1.6 : Sat Feb 08 2003 - 15:27:19 CET