[Ignore anti-bulk-email From: line. Email address below]
I wonder if anyone has done what I am trying to do and got it to work.
It is often useful for a program to get some input from the user. For
many purposes readline works very nicely.
Alternatively, under X, you can invoke a pop_up window which asks you to
type some text into a text field. This is possible with propsheet, but
horrible. See, for example,
ftp://ftp.cs.bham.ac.uk/pub/dist/poplog/pui/auto/pui_getinput.p
In many contexts it would be much nicer to be able to get the input via
VED since then you'd be able to use normal editing commands to correct
mistakes, and you could even use VED to interrogate other files to help
you get the answer, etc.
So I thought I would write a program to open a ved buffer and wait till
you've hit return in that buffer and then take the line you've typed and
make a list of text items. This works just fine, as follows, using the
procedure veddiscin
define veddiscin(filename) -> repeater;
;;; Get a character repeater for the VED file with the name.
lvars dev = consveddevice(sysfileok(filename), 0, true);
define lconstant newcharin(dev) -> char;
lconstant string = '0';
sysread(dev, string, 1) ->;
fast_subscrs(1, string) -> char
enddefine;
newcharin(%dev%) -> repeater;
enddefine;
define vedreadlinefrom(filename, defaults, save) -> list;
;;; filename: a string
;;; defaults: false or vedhelpdefaults, or vedveddefaults ,etc.
;;; save: if true, then save the buffer, otherwise quit
unless defaults then vedhelpdefaults -> defaults endunless;
vededit(filename, defaults);
lvars item, list,
newcharin = veddiscin(filename),
procedure rep = incharitem(newcharin); ;;; item repeater
dlocal popnewline = true, popprompt = pop_readline_prompt;
;;; Make a list items to next newline
[% until (rep() ->> item) == newline do item enduntil %] -> list;
unless save then
if vedwriteable then ved_wq() else ved_q() endif;
endunless;
enddefine;
;;; test it
vedreadlinefrom('INTERACT', false, false) =>
That works fine in a normal program. But if it is invoked by a
mouse-selected button, i.e. in a callback I find that it produces errors
of this form:
;;; MISHAP - NUMBER(S) NEEDED
;;; INVOLVING: <false> 1
;;; DOING : sysprmishap vedprmishap prmishap mishap - sysread
newcharin (Sys$-Incharitem) vedreadlinefrom <false>
I.e. it appears to be trying to subtract 1 from FALSE inside sysread.
This happens even if I use external_defer_apply in the callback, so that
in theory the procedure should be invoked in a "safe" context.
It turns out that if I am running Xved I can get round this by putting
the procedure to be run in VED's input stream using vedinput. The
procedure is then run immediately. However if I try to do this in
ordinary Ved (which I normally prefer) nothing happens until I next
try to do something in VED.
Note that printing into a VED buffer in a similar callback context
causes no problems.
Thus there are two questions:
1. Why does the vedreadline procedure work normally outside the event
handling callback yet produce the bizarre error in sysread if invoked in
the callback using external_defer_apply.
2. If I am not using XVed how can I make procedures invoked via a
callback run as soon as the context is safe for them to do so, which is
what I thought external_defer_apply was supposed to do?
And my original question
3. Is there a better way to use Ved/Xved to get textual input from
a program invoked via the mouse.
[A generalisation of vedreadlinefrom would endable you to read a whole
bufferful of text instead of only one line, but that's a longer story.]
I've tested this both in Poplog V15.01 on a Sparc and V15.5 on a DEC
Alpha.
Suggestions welcome.
Aaron
--
Aaron Sloman, ( http://www.cs.bham.ac.uk/~axs )
School of Computer Science, The University of Birmingham, B15 2TT, England
EMAIL A. Sloman @ cs. bham.ac.in uk(||| MAKE UNSOLICITED EMAIL ADVERTS ILLEGAL |||)
Phone: +44-121-414-4775 (Sec 3711) Fax: +44-121-414-4281
|