rubyconsole

Ruby console input halting at 1024 characters


I have a script that takes console input into a variable and requires pasting in a string longer than 1024 characters.

When I try to paste more than 1024 characters it stops accepting input after 1024 and just shows a truncated string. Manually typing characters also hits this limit. How can I get around this?

iTerm doesn't seem to be the problem, I can paste more than 1024 to bash no problem.

irb
2.1.3 :001 > a = STDIN.gets

I have the same symptom when I use the Highline::import gem and the ask method.


Solution

  • Try this:

    gem install rb-readline
    

    In your script:

    require 'rb-readline'
    

    and then, to read a line:

    a = Readline::readline
    

    Does that solve it?

    If so, you may also want to look at compiling your Ruby with readline:

    https://github.com/guard/guard/wiki/Add-Readline-support-to-Ruby-on-Mac-OS-X