[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

HighLine Questions

Raymond O'connor

3/30/2007 7:11:00 AM

Hi all,
A few quick questions out there for people using HighLine. I've been
looking at the examples and the readline one looks similar to what I
want to do. Basically, I'd like the user to be able to type commands
and then have my program execute them. However, I'm trying to work with
the example but can't figure out how to take it to the next step.
Here's the example:
loop do
cmd = ask("Enter command: ", %w{save load reset quit}) do |q|
q.readline = true
end
say("Executing \"#{cmd}\"...")
break if cmd == "quit"
end

I'd like to be able to type a command such as load foobar or save foo
where the command takes a second parameter that isn't explicitely known
beforehand. Is there anyway to do that? I tried passing in regular
expressions but couldn't get anywhere.


Also, another question about highline. I have a list that's several
rows and columns. I'd like the current list to update with new values
instead of printing a new list. I looked at the overwrite example but
it only seems to work with one line. Is this possible at all?

Thanks!
Ray

--
Posted via http://www.ruby-....

5 Answers

Axel

3/30/2007 8:27:00 AM

0

This way?:


$stdout.sync = true
$stderr.sync = true

require 'highline'
require 'highline/import'

loop do
cmd = ask('Enter "save load reset quit ... something" :') do |q|
q.validate = /^ \s* (save|load|reset|quit) (.*) /ix
end
puts "-- Got: #{cmd}\n\n"
end


Regards,
Axel

James Gray

3/30/2007 12:11:00 PM

0

On Mar 30, 2007, at 2:10 AM, Raymond O'Connor wrote:

> A few quick questions out there for people using HighLine. I've been
> looking at the examples and the readline one looks similar to what I
> want to do. Basically, I'd like the user to be able to type commands
> and then have my program execute them.

Have a look at menus.rb in HighLine's examples directory. The last
example in that file is almost exactly what you want to do.

> Also, another question about highline. I have a list that's several
> rows and columns. I'd like the current list to update with new values
> instead of printing a new list. I looked at the overwrite example but
> it only seems to work with one line. Is this possible at all?

HighLine doesn't currently support anything that would help you here,
no. It might be worth adding a cross-platform clear method, which
sounds like it would serve here...

James Edward Gray II

Axel

3/30/2007 3:02:00 PM

0


> Have a look at menus.rb in HighLine's examples directory. The last
> example in that file is almost exactly what you want to do.

Very nice!
- Axel

Raymond O'connor

4/2/2007 5:03:00 AM

0

Thanks for the help! I have a nice shell working now. I've run into
another snag though. Is there anyway to print out nicely formatted
tables? Ive tried just doing consecutive lists but even though they
have the same number of columns they don't really line up all that well.
Thanks,
Ray

--
Posted via http://www.ruby-....

Raymond O'connor

4/2/2007 5:13:00 AM

0

nevermind, I think I can get the effect I want by playing around with
String#ljust/center/rjust

Thanks again for the help,
Ray

--
Posted via http://www.ruby-....