# HighLine Questions

**URL:** <https://www.ruby-forum.com/t/highline-questions/90611>\
**Category:** Ruby\
**Created:** [March 30, 2007, 9:10am UTC](https://www.ruby-forum.com/t/highline-questions/90611 "2007-03-30T09:10:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nappin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f475e1/32.png) [@nappin](https://www.ruby-forum.com/u/nappin)\
**Post date:** [March 30, 2007, 9:10am UTC](https://www.ruby-forum.com/t/highline-questions/90611/1 "2007-03-30T09:10:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nappin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f475e1/32.png) [@nappin](https://www.ruby-forum.com/u/nappin)\
**Post date:** [March 30, 2007, 10:30am UTC](https://www.ruby-forum.com/t/highline-questions/90611/2 "2007-03-30T10:30:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nappin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f475e1/32.png) [@nappin](https://www.ruby-forum.com/u/nappin)\
**Post date:** [March 30, 2007, 2:11pm UTC](https://www.ruby-forum.com/t/highline-questions/90611/3 "2007-03-30T14:11:14Z")

</div>

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 G. II

---

<div class="post-metadata">

**Author:** ![nappin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f475e1/32.png) [@nappin](https://www.ruby-forum.com/u/nappin)\
**Post date:** [April 2, 2007, 7:03am UTC](https://www.ruby-forum.com/t/highline-questions/90611/4 "2007-04-02T07:03:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nappin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f475e1/32.png) [@nappin](https://www.ruby-forum.com/u/nappin)\
**Post date:** [April 2, 2007, 7:13am UTC](https://www.ruby-forum.com/t/highline-questions/90611/5 "2007-04-02T07:13:26Z")

</div>

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

Thanks again for the help,  
Ray

---

<div class="post-metadata">

**Author:** ![nappin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f475e1/32.png) [@nappin](https://www.ruby-forum.com/u/nappin)\
**Post date:** [March 30, 2007, 5:05pm UTC](https://www.ruby-forum.com/t/highline-questions/90611/6 "2007-03-30T17:05:50Z")

</div>

> 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
