[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Typing 'Input' on Displayed Text

woodyee

11/28/2006 1:35:00 PM

Hi! While shopping this weekend, I noticed lots of department stores
using an older 'template' on the checkout registers which had info
displaying and they simply typed in the info and entered or tabbed to
the next field, sorta like this:

First Name: Last Name:
Street: Town:
City: State:

How can I do this in Ruby? I can do simple "Your name? (user writes
name), then another question/user replies, another question/user
replies" but how can I display text and have the user go through to the
end? Hope this makes sense. Thanks!

4 Answers

Bira

11/28/2006 1:53:00 PM

0

On 11/28/06, woodyee <wood_yee12@hotmail.com> wrote:

>
> How can I do this in Ruby? I can do simple "Your name? (user writes
> name), then another question/user replies, another question/user
> replies" but how can I display text and have the user go through to the
> end? Hope this makes sense. Thanks!

You can do this sort of "fancy text terminal" in Ruby using libraries
such as "curses" or "ncurses", which are written in C and possess Ruby
bindings. There's a more elaborate library written in Ruby called
Highline, IIRC, which seems to handle most of the fiddly detail for
you. I also want to try this out some day, but I haven't got around to
it yet :).


--
Bira
http://compexplicita.bl...
http://sinfoniaferida.bl...

Paul Lutus

11/28/2006 4:23:00 PM

0

woodyee wrote:

> Hi! While shopping this weekend, I noticed lots of department stores
> using an older 'template' on the checkout registers which had info
> displaying and they simply typed in the info and entered or tabbed to
> the next field, sorta like this:
>
> First Name: Last Name:
> Street: Town:
> City: State:
>
> How can I do this in Ruby? I can do simple "Your name? (user writes
> name), then another question/user replies, another question/user
> replies" but how can I display text and have the user go through to the
> end? Hope this makes sense. Thanks!

------------------------------------------

#!/usr/bin/ruby -w

class UserInterface
def process_item(s)
begin
print "Please enter your #{s}:"
reply = STDIN.readline.chomp
end while(reply.length == 0)
return reply
end
def get_user_data()
name = process_item("name")
address = process_item("address")
zip_code = process_item("zip code")
return name,address, zip_code
end
end

ui = UserInterface.new

name, address, zip_code = ui.get_user_data()

puts name, address, zip_code

------------------------------------------

--
Paul Lutus
http://www.ara...

woodyee

11/28/2006 9:21:00 PM

0

Hi! This example was what I've been getting myself. What I want is when
you run the program, you have the 'questions' already displayed on the
screen.

Ex:
c:\ ruby test.rb
First Name: Last Name:
Town: City:

Thanks!


> #!/usr/bin/ruby -w
>
> class UserInterface
> def process_item(s)
> begin
> print "Please enter your #{s}:"
> reply = STDIN.readline.chomp
> end while(reply.length == 0)
> return reply
> end
> def get_user_data()
> name = process_item("name")
> address = process_item("address")
> zip_code = process_item("zip code")
> return name,address, zip_code
> end
> end
>
> ui = UserInterface.new
>
> name, address, zip_code = ui.get_user_data()
>
> puts name, address, zip_code
>
> ------------------------------------------
>
> --
> Paul Lutus
> http://www.ara...

Paul Lutus

11/29/2006 12:28:00 AM

0

woodyee wrote:

> Hi! This example was what I've been getting myself. What I want is when
> you run the program, you have the 'questions' already displayed on the
> screen.

In that case, learn how to design graphical user interfaces. They come in
several varieties. An increasingly popular form is an HTML page that talks
to server-side code to process user entries.

--
Paul Lutus
http://www.ara...