HighLine Questions

R

Raymond O'Connor

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
 
A

Axel

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
 
J

James Edward Gray II

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
 
R

Raymond O'Connor

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
 
R

Raymond O'Connor

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

Thanks again for the help,
Ray
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top