1. how do I do a line input in Euphoria?
- Posted by Michael Packard <lgp at EXO.COM> Oct 09, 1997
- 648 views
- Last edited Oct 10, 1997
ya know, up till now I've only needed single character inputs, or have been using specialized libraries for string and number input (like Dave Cuny's GUI and jiri's font package) I'm writing a program in text mode, and I can't find how to do a simple string or numeric input in the manuals. How do I do it? Michael Packard Lord Generic Productions
2. Re: how do I do a line input in Euphoria?
- Posted by Mike Fowler <stoner at NELSUN.GEN.NZ> Oct 10, 1997
- 639 views
-> ya know, up till now I've only needed single character inputs, or have -> been using specialized libraries for string and number input (like Dave -> Cuny's GUI and jiri's font package) I'm writing a program in text mode, -> and I can't find how to do a simple string or numeric input in the -> manuals. How do I do it? this is what I usually do... but it is (i think) bad programming... oh well... i'm only an amatuer :) this code is _totally_ untested... -- code starts here include get.e -- for wait_key() constant EXIT_KEYS = {13} sequence line -- the line we're creating integer char -- the last pushed keyboard character pushed char = wait_key() while find(char, EXIT_KEYS) = 0 do -- should it be 0 or -1 ??? line = append(line, char) -- add the character to the line char = wait_key() -- wait for next keypress end while puts(1, "You Typed:\n" & line) -- end of code yes, its ugly, but it works :) Mike Fowler - mike.fowler at nelsun.gen.nz o__ --- _,>/'_ --- (_) \(_) ---
3. Re: how do I do a line input in Euphoria?
- Posted by Bryan Watts <BWatts1 at COMPUSERVE.COM> Oct 10, 1997
- 611 views
>-> ya know, up till now I've only needed single character inputs, or hav= e >-> been using specialized libraries for string and number input (like Da= ve >-> Cuny's GUI and jiri's font package) I'm writing a program in text mod= e, >-> and I can't find how to do a simple string or numeric input in the >-> manuals. How do I do it? >this is what I usually do... but it is (i think) bad programming... >oh well... i'm only an amatuer :) >this code is _totally_ untested... >-- code starts here >include get.e -- for wait_key() >constant EXIT_KEYS =3D {13} >sequence line -- the line we're creating >integer char -- the last pushed keyboard character pushed >char =3D wait_key() >while find(char, EXIT_KEYS) =3D 0 do -- should it be 0 or -1 ??? > line =3D append(line, char) -- add the character to the li= ne char =3D wait_key() -- wait for next keypress >end while >puts(1, "You Typed:\n" & line) >-- end of code >yes, its ugly, but it works :) Actually Michael, why don't you try using the gets() function? It return= s every key pressed up till and icluding the return key. Here's an example= : sequence input input =3D gets(0) input =3D input[1..length(input)-1] --to get rid of the '\n' If you typed "Euphoria", input would hold a sequence of ASCII values pertaining to each one of the letters. I'm not sure if it's what you wanted, but I hope it helps.. Regards, Bryan Watts
4. Re: how do I do a line input in Euphoria?
- Posted by Mike Fowler <stoner at NELSUN.GEN.NZ> Oct 10, 1997
- 634 views
-> >this code is _totally_ untested... ---8<--- -> >yes, its ugly, but it works :) -> Actually Michael, why don't you try using the gets() function? It -> return= s every key pressed up till and icluding the return key. -> If you typed "Euphoria", input would hold a sequence of ASCII values -> pertaining to each one of the letters. I'm not sure if it's what you -> wanted, but I hope it helps.. Gidday Bryan :) thanks for the suggestion... i sometimes use it, but it is limited to only enter to stop entering data, and the other way is better to use in graphics mode, where you can read the input, then put it to wherever you want on the screen with, say, putsxy(), rather than having to worry about text rows and columns... and also, if you have a field thats, say, 10 characters long, somebody will be able to just keep on typing past those 10 spaces, which can be highly anoying, and looks awful. it also is a bit about personal preference i think... if somebody prefers a simple call to gets() and dosent need any extras, then go for it! Mike Fowler - mike.fowler at nelsun.gen.nz o__ --- _,>/'_ --- (_) \(_) ---
5. Re: how do I do a line input in Euphoria?
- Posted by "Christopher K. Lester" <cklester at FLASH.NET> Oct 10, 1997
- 605 views
At 11:17 PM 10/9/97 -0700, you wrote: > >ya know, up till now I've only needed single character inputs, or have >been using specialized libraries for string and number input (like Dave >Cuny's GUI and jiri's font package) I'm writing a program in text mode, >and I can't find how to do a simple string or numeric input in the >manuals. How do I do it? > Just add up a whole bunch of single character inputs until they press a certain key, say, the "ENTER" key.
6. Re: how do I do a line input in Euphoria?
- Posted by Ad Rienks <Ad_Rienks at COMPUSERVE.COM> Oct 10, 1997
- 627 views
>At 11:17 PM 10/9/97 -0700, you wrote: > >ya know, up till now >I've only needed single character inputs, or have >been using >specialized libraries for string and number input (like Dave >>Cuny's GUI and jiri's font package) I'm writing a program in >text mode, >and I can't find how to do a simple string or >numeric input in the >manuals. How do I do it? > >Just add up a whole bunch of single character inputs until they >press a certain key, say, the "ENTER" key. = Drawback of that method is that there is no editing possible during input= =2E I myself mostly stick to the following: include get.e function input(sequence prompt) -- simple numeric input routine object number puts(1, prompt) number =3D get(0) number =3D number[2] return number end function -- input function input_string(sequence prompt) -- simple string input routine sequence string puts(1, prompt) string =3D gets(0) return string[1..length(string)-1] end function -- input_string Certainly these functions are not foolproof either. Add your own validity= tests and maybe a clear_to_end_of_line() and some loops to check the inpu= t and ask for new input if necessary. Sincerely, Ad Rienks email Ad_Rienks at compuserve.com writing at 1:44 , = on zaterdag 11 oktober 1997 Using EMail Assist for WinCIM
7. Re: how do I do a line input in Euphoria?
- Posted by "Christopher K. Lester" <cklester at FLASH.NET> Oct 11, 1997
- 614 views
At 07:46 PM 10/10/97 -0400, you wrote: > >>Just add up a whole bunch of single character inputs until they >>press a certain key, say, the "ENTER" key. = > > >Drawback of that method is that there is no editing possible during input= >I myself mostly stick to the following: > That's why I add the ability to edit the input (use the 'Delete' key, for instance), accept only "valid" characters as input, etc. But basically all you're doing is accepting single-key inputs to create a multiple-character final input. I've got some code somewhere...
8. Re: how do I do a line input in Euphoria?
- Posted by Ad Rienks <Ad_Rienks at COMPUSERVE.COM> Oct 12, 1997
- 631 views
Christopher Lester wrote (about input routines): >That's why I add the ability to edit the input (use the 'Delete' >key, for instance), accept only "valid" characters as input, >etc. >But basically all you're doing is accepting single-key inputs to >create a multiple-character final input. >I've got some code somewhere... = Yeah, yesterday I saw the input.e file on Einar Mogen's site. These routines have got that. I think Einar won't mind if I copied it here, for= the interested followers of this discussion. --input.e: -- e-mail: nord.staernes at rollag.mail.telia.com -- "safe" routines for input from the keyboard by -- Einar Mogen, uses the standard text routines -- provided with Euphoria -- enter_text_line(text =3D default text, -- text_length =3D max length of input, -- pen_color =3D text color, -- paper_color =3D background color, -- y_pos =3D y position (row) of text on screen, -- x_pos =3D x position (col) of text on screen) -- This routine is for standard line input. -- enter_filename(text =3D default filename, -- pen_color =3D text color, -- paper_color =3D background color, -- y_pos =3D y position (row) of text on screen, -- x_pos =3D x position (col) of text on screen) -- This routine is for filename input WITHOUT extension. -- enter_number(number =3D default number, -- number_length =3D max number of digits -- pen_color =3D text color, -- paper_color =3D background color, -- y_pos =3D y position (row) of text on screen, -- x_pos =3D x position (col) of text on screen) -- This routine is for standard INTEGER input. include graphics.e -- cursor, text_color, bk_color include get.e -- wait_key include file.e -- allow_break constant ENTER=3D13, BACKSPACE=3D8 allow_break(0) global function enter_text_line(sequence text,integer text_length, intege= r pen_color,integer paper_color,integer y_pos,integer x_pos) integer junk bk_color(paper_color) text_color(pen_color) cursor(UNDERLINE_CURSOR) position(y_pos,x_pos) puts(1,repeat('=B1', text_length)) -- should be char 177, I guess(ar)= while 1=3D1 do position(y_pos,x_pos) puts(1,text) junk=3Dwait_key() if junk=3DBACKSPACE and length(text) then text=3Dtext[1..length(text)-1] position(y_pos,x_pos) puts(1,repeat('=B1', text_length)) elsif junk=3DENTER then cursor(NO_CURSOR) return text elsif junk > 31 and junk < 255 and length(text) < text_length the= n text=3Dtext&junk end if end while end function global function enter_filename(sequence text,integer pen_color,integer paper_color,integer y_pos,integer x_pos) integer junk bk_color(paper_color) text_color(pen_color) cursor(UNDERLINE_CURSOR) position(y_pos,x_pos) puts(1,repeat('=B1', 8)) while 1=3D1 do position(y_pos,x_pos) puts(1,text) junk=3Dwait_key() if junk=3DBACKSPACE and length(text) then text=3Dtext[1..length(text)-1] position(y_pos,x_pos) puts(1,repeat('=B1', 8)) elsif junk=3DENTER and length(text) then cursor(NO_CURSOR) return text elsif length(text) < 8 and find(junk, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_") then text=3Dtext&junk end if end while end function global function enter_number(integer number,integer number_length,integer= pen_color,integer paper_color,integer y_pos,integer x_pos) object junk sequence text text =3D sprintf("%d",number) bk_color(paper_color) text_color(pen_color) cursor(UNDERLINE_CURSOR) position(y_pos,x_pos) puts(1,repeat('=B1', number_length)) while 1=3D1 do position(y_pos,x_pos) puts(1,text) junk=3Dwait_key() if junk=3DBACKSPACE and length(text) then text=3Dtext[1..length(text)-1] position(y_pos,x_pos) puts(1,repeat('=B1', number_length)) elsif find(junk,"01234567890") and length(text) < number_length then text=3Dtext&junk elsif junk=3DENTER then junk=3Dvalue(text) cursor(NO_CURSOR) junk=3Djunk[2] return junk end if end while end function Sincerely, Ad Rienks email Ad_Rienks at compuserve.com writing at 8:17 , = on zondag 12 oktober 1997 Using EMail Assist for WinCIM