[Thread Prev][Thread Next][Index]

Re: read a keyboard entry ?



> Emilie Vanvyve wrote:
> 
> > Just a short question : is there any way to read an user's "keyboard" 
> > entry from inside Ferret ?
>
On Fri, 9 Apr 2004, Ansley Manke wrote:
> No, there is not such a capability in Ferret.  I wonder if there might
> be a way to do this using SPAWN from ferret and writing the input
> to a  file which Ferret could then read. Not a pretty solution, but if
> anyone has ideas about making it work, send 'em in.

Hi Ansley and Emilie,

To get a line from the keyboard,

   let user_input = "`{spawn:"head -1"}`"

The outer quotes provide a level of safety, in case the user presses
<Enter> without providing any text;  without quotes the command would fail
in this case, but with quotes the USER_INPUT variable would be set to an
empty string.

You can get numbers too, like this:

yes? say "Enter number:"; let user_input = "`{spawn:"head -1"}`"
Enter number:
5
yes? let number = `user_input`  !works only if this is a valid number
yes? say `number-1`
4

You can also get numeric arrays:

yes? say "Enter array:"; let user_input = "`{spawn:"head -1"}`"
Enter array:
{1,2,3,5,7,11}
yes? let array = `user_input`
yes? list array
             VARIABLE : {1,2,3,5,7,11}
             SUBSET   : 6 points (X)
 1   / 1:   1.00
 2   / 2:   2.00
 3   / 3:   3.00
 4   / 4:   5.00
 5   / 5:   7.00
 6   / 6:  11.00

Not sure how to handle a quote character in the input stream, but other
special characters (like "!", the Ferret comment character) can be handled
with backquotes:

yes? let user_input = "`{spawn:"head -1"}`"
hello\\!
yes? say `user_input`
hello!

I hope that helps!

Andrew

+--------------------------------------------------------+
|   Dr. Andrew T. Wittenberg   |        GFDL/NOAA        |
|  Andrew.Wittenberg@noaa.gov  |      Princeton, NJ      |
+--------------------------------------------------------+






[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement