Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby console input halting at 1024 characters

Tags:

ruby

console

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.

like image 691
Josh Diehl Avatar asked Dec 09 '25 00:12

Josh Diehl


1 Answers

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

like image 117
joelparkerhenderson Avatar answered Dec 10 '25 17:12

joelparkerhenderson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!