From: R.. Kumar on 25 Jun 2010 06:36 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 -- Posted via http://www.ruby-forum.com/.
From: James Edward Gray II on 25 Jun 2010 10:52 On Jun 25, 2010, at 5:36 AM, R.. Kumar wrote: > 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) Interesting. Your code does work for me: $ cat multi-read.rb #!/usr/bin/env ruby -wKU require "rubygems" require "highline/import" def get_lines lines = nil $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 def _choice prompt, choices puts "got: #{prompt} ::: #{choices} " STDIN.reopen '/dev/tty' choose do |menu| menu.prompt = prompt menu.choices(choices) do |n| return n; end end end p get_lines _choice "? ", "A choice" __END__ $ ruby multi-read.rb one two three "one\ntwo\nthree" got: ? ::: A choice 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
From: R.. Kumar on 26 Jun 2010 06:36 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. -- Posted via http://www.ruby-forum.com/.
From: James Edward Gray II on 26 Jun 2010 11:46 On Jun 26, 2010, at 5:36 AM, R.. Kumar wrote: > /opt/local/lib/ruby1.9/ 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 __END__ $ ruby -v eof_change.rb 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 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
From: R.. Kumar on 26 Jun 2010 14:22
James Edward Gray II wrote: > On Jun 26, 2010, at 5:36 AM, R.. Kumar wrote: > >> /opt/local/lib/ruby1.9/� > > 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. -- Posted via http://www.ruby-forum.com/. |