Highline giving EOFERROR, input stream exhausted

R

R.. Kumar

I am first taking multiline input from user. User may end input using
Ctr-d.

Then I use highline's menu and get:
/opt/local/lib/ruby1.9/gems/1.9.1/gems/highline-1.5.2/lib/highline.rb:603:in
`get_line': The input stream is exhausted. (EOFError)

However, experimentally, if I end multiline input on user entering
"bye", then highline works, but with Ctrl-D it bombs.

How can i clear EOF prior to calling highline. I tried:

HighLine.track_eof = false

but it pushes the error further (split on nil).

I've tried reopening stdin with a $stdin.reopen '/dev/tty' but it makes
no difference.

My earlier code is:

def get_lines
lines = nil
#$stdin.flush
$stdin.each_line do |line|
line.chomp!
if line =~ /^bye$/
break
end
if lines
lines << "\n" + line
else
lines = line
end
end
return lines
end

After calling get_lines, I call this method:

def _choice prompt, choices
#HighLine.track_eof = false
puts "got: #{prompt} ::: #{choices} "
#$stdin.flush
STDIN.reopen '/dev/tty'
choose do |menu|
menu.prompt = prompt
menu.choices(choices) do |n| return n; end
end
end
 
J

James Edward Gray II

I am first taking multiline input from user. User may end input using
Ctr-d.
=20
Then I use highline's menu and get:
= /opt/local/lib/ruby1.9/gems/1.9.1/gems/highline-1.5.2/lib/highline.rb:603:=
in
`get_line': The input stream is exhausted. (EOFError)

Interesting. Your code does work for me:

$ cat multi-read.rb=20
#!/usr/bin/env ruby -wKU

require "rubygems"
require "highline/import"

def get_lines
lines =3D nil
$stdin.each_line do |line|
line.chomp!
if line =3D~ /^bye$/
break
end
if lines
lines << "\n" + line
else
lines =3D line
end
end
return lines
end

def _choice prompt, choices
puts "got: #{prompt} ::: #{choices} "
STDIN.reopen '/dev/tty'
choose do |menu|
menu.prompt =3D prompt
menu.choices(choices) do |n| return n; end
end
end

p get_lines
_choice "? ", "A choice"

__END__
$ ruby multi-read.rb=20
one
two
three
"one\ntwo\nthree"
got: ? ::: A choice=20
1. A choice
? 1
"A choice"

I used Control-D to stop the multi-line entry there.

What platform are you on and what version of Ruby are you using?

James Edward Gray II=
 
R

R.. Kumar

I copied your program and ran it:

$ ruby high.rb
/opt/local/lib/ruby1.9/1.9.1/pathname.rb:270: warning: `*' interpreted
as argument prefix
one
two
three
"one\ntwo\nthree"
got: ? ::: A choice
1. A choice
?
/opt/local/lib/ruby1.9/gems/1.9.1/gems/highline-1.5.2/lib/highline.rb:603:in
`get_line': The input stream is exhausted. (EOFError)
from
/opt/local/lib/ruby1.9/gems/1.9.1/gems/highline-1.5.2/lib/highline.rb:624:in
`get_response'
from
/opt/local/lib/ruby1.9/gems/1.9.1/gems/highline-1.5.2/lib/highline.rb:218:in
`ask'
from
/opt/local/lib/ruby1.9/gems/1.9.1/gems/highline-1.5.2/lib/highline.rb:317:in
`choose'
from high.rb:25:in `_choice'
from high.rb:32:in `<main>'


ruby 1.9.1p376 (2009-12-07 revision 26041) [i386-darwin10]

MAC OSX Intel Snow Leopard
Darwin laptop-3.local 10.3.0 Darwin Kernel Version 10.3.0: Fri Feb 26
11:58:09 PST 2010; root:xnu-1504.3.12~1/RELEASE_I386 i386

Thanks.
 
J

James Edward Gray II

/opt/local/lib/ruby1.9/=85

It looks like this is a difference in Ruby 1.9 that isn't related to =
HighLine:

$ cat eof_change.rb=20
puts "Enter multiple lines:"
p $stdin.read

puts "Question?"
p $stdin.gets

__END__
$ ruby -v eof_change.rb=20
ruby 1.8.6 (2010-02-05 patchlevel 399) [i686-darwin10.2.0]
Enter multiple lines:
one
two
three
"one\ntwo\nthree\n"
Question?
answer
"answer\n"
$ rvm use 1.9.2

info: Using ruby 1.9.2 preview3
$ ruby -v eof_change.rb=20
ruby 1.9.2dev (2010-05-31 revision 28117) [x86_64-darwin10.3.0]
Enter multiple lines:
one
two
three
"one\ntwo\nthree\n"
Question?
nil

I can't seem to find a way around it.

James Edward Gray II
 
R

R.. Kumar

James said:
It looks like this is a difference in Ruby 1.9 that isn't related to
HighLine:

$ cat eof_change.rb
puts "Enter multiple lines:"
p $stdin.read

puts "Question?"
p $stdin.gets

Yup.
I ran your snippet with 1.9.1 and with the stock /usr/bin/ruby (ruby
1.8.7 (2009-06-08 patchlevel 173) [universal-darwin10.0]) which I never
use, and I get the same results. 1.9.1 fails, 1.8.7 works :-(

Do you know who to forward this issue to ? Could you possibly inform the
correct person -- I am not familiar with the process.

I have an unrelated question. Some months ago i checked the RVM site and
was frightened off -- it said DO NOT install rvm using gem, and it gave
some complicated procedure.
Did you install the rvm gem ? If not, is there a link for the best
procedure to install. I am now a bit weary of custom installs, it take
too much out of me to keep maintaining them. Thanks.
 
J

James Edward Gray II

Do you know who to forward this issue to ? Could you possibly inform = the=20
correct person -- I am not familiar with the process.

I've asked if this is an intentional change on the Ruby Core mailing =
list.
I have an unrelated question. Some months ago i checked the RVM site = and=20
was frightened off -- it said DO NOT install rvm using gem, and it = gave=20
some complicated procedure.
Did you install the rvm gem ? If not, is there a link for the best=20
procedure to install. I am now a bit weary of custom installs, it take=20=
too much out of me to keep maintaining them. Thanks.

RVM has instructions for how to install it an it is capable of =
maintaining itself:

http://rvm.beginrescueend.com/rvm/install/

It's pretty painless and I highly recommend it.

James Edward Gray II
 

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

HighLine problems 1
[QUIZ] HighLine (#29) 8
[SOLUTION] HighLine (#29) 6
[SOLUTION] Highline (#29) 0
[SUMMARY] HighLine (#29) 0
ANN main-4.4.0 0
Curses about libcurse 6
[ANN] Subversion Handy Backup (SHB) 1

Members online

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top