1. Help wanted!
-- file dialog.e
-- enables simple text input and output
include get.e
include graphics.e
global function input(sequence prompt)
-- print a message and read in a number
-- returns the number, that can either be an integer or an atom(float)
sequence input, curpos
input = {1, 0} -- this initializes the variable input with
-- values that are *not* valid
puts(1, prompt) -- put message on screen
while input[1] do -- repeat until valid number
curpos = get_position() -- read current cursor position
input = get(0) -- read from the keyboard
position(curpos[1], curpos[2]) -- back to position if not valid
end while
puts(1, '\n') -- to start on a new line when back from function
return input[2] -- the second element of input is returned
-- and should contain a valid number
end function -- input()
-- Input of a string with a prompt:
global function prompt_in(sequence prompt)
sequence in_string -- to read in the input
puts(1, prompt) -- put prompt (question) on the screen
in_string = gets(0) -- read string input from the keyboard
puts(1, '\n') -- to start on a new line when back from function
-- return the input string now, but strip off the last character,
-- since that is a 'new line' character (ASCII 10)
return in_string[1..length(in_string) - 1]
end function -- prompt_in()
2. Help wanted!
Hi to all!
In testing the include file that is attached to this message I found
something strange I never noticed before!
It behaves differently started from the Euphoria editor than when it is
started from the DOS prompt. It puts in an extra newline!
I tried removing the '\n' newline characters, but then, when run from the
editor it tabs forward on the new line, without a carriage return.
When run from the DOS prompt it does put this carrige return itself, it
seems.
Has anyone ever experienced this before, and more important, what can be
done to it? I don't know if this is a bug or due to my programming.
Please help!
Ad
3. Help wanted!
- Posted by Robert Craig <robert_craig at COMPUSERVE.COM>
Feb 19, 1997
-
Last edited Feb 20, 1997
Ad Rienks writes:
> It behaves differently started from the Euphoria editor than when it is
> started from the DOS prompt. It puts in an extra newline!
I believe you are seeing a "feature" of DOS. If you type something
on the last line of the screen it will scroll up. This will
make things look different than when you answer a prompt
higher up on the screen. I was annoyed with this too, when I first saw it,
but it would be difficult for Euphoria to always compensate
for this behavior.
Regards,
Rob Craig
Rapid Deployment Software
4. Re: Help wanted!
Robert Craig wrote:
>I believe you are seeing a "feature" of DOS. If you type something
>on the last line of the screen it will scroll up. This will
>make things look different than when you answer a prompt
>higher up on the screen. I was annoyed with this too, when I first saw it,
>but it would be difficult for Euphoria to always compensate
>for this behavior.
Please read this also:
>Your dialog.e solved most of a problem I had been working on. I'm
>prompting the user for numerical input into a amortization program (isn't
>that what novices cut their teeth on?). I wanted to reposition the cursor
>after invalid input. Your routines solve the problem if the input is not
a
>number, but if the return key is hit the cursor falls to the next line.
>However, if I then input a letter it will reposition back to the proper
>position.
This is what another user reported and I think he is experiencing the same
problem. It is not only on the last lines of the screen that this is
happening.
The return key seems to do different things, running from Euphoria or from
DOS.
I tried programming a series of inputs() and puts(), without using '\n'.
Run from ed.ex this behaves as expected, printing everything on one line,
but from DOS the printing starts on a new line.
The question remains:
>Can you tell me how to reposition the cursor after an accidental hit of
the
>return key?
Thanks
Ad Rienks
5. Re: Help wanted!
re: enter key scrolling last line
i'd suggest writing your own input routine, to handle all the keys,
including the Enter key. the initial pain of writing the routine is
compenstated by the fine control that you get in the long run.
it's not that hard to write; something like:
-- CODE BEGINS HERE
include get.e -- wait_key()
constant BACKSPACE = 8, ENTER = 13
function input_at( integer line, integer col, sequence prompt, integer size
)
integer key, n
sequence text
text = ""
-- prompt
position( line, col )
puts( 1, prompt & "[" & repeat( 249, size ) & "]" )
-- input start position
col = col + length(prompt) + 1
while 1 do
-- display the text
position( line, col )
puts( 1, "" & text )
-- pad the remaining
n = length( text )
if n < size then
puts( 1, repeat( 249, size - n ) )
end if
-- position cursor
position( line, col + n )
-- wait for a key
key = wait_key()
if key = ENTER then
exit
elsif key = BACKSPACE then
-- text to remove?
if n > 0 then
text = text[1..n-1]
end if
elsif key >= ' ' then
-- room?
if n < size then
-- add
text = text & key
end if
end if
end while
return text
end function
-- try it out
sequence x
x = input_at( 2, 3, "First Name", 32 )
-- CODE ENDS HERE
hope this helps.
-- david cuny