Rails console issues using JRuby: no prompt character, no tab completion, broken arrow keys, etc

帅比萌擦擦* 提交于 2019-12-05 17:01:06

问题


I'm having various issues with my Rails console under JRuby, including

  • No prompt character
  • Tab completion not working (literal tab gets inserted)
  • Up/down arrows not browsing history (^[[A or ^[[B gets inserted, respectively)
  • Left/right arrows not moving cursor (^[[D or ^[[C gets inserted, respectively)
  • Home/End keys not moving cursor to beginning/end of line (instead 1~ or 4~ inserted, respectively); Ctrl+a / Ctrl+e work though
  • Ctrl+c killing console instead of killing the line I'm entering
  • Ctrl+d not having any effect until I hit Enter (which then executes anything I entered between Ctrl+d and Enter in my Unix shell).

I installed my JRuby interpreter from rvm like so:

rvm install jruby-1.6.8 --1.9

My Rails project is managed using Bundler (not rvm gemsets), so I run my Rails console using bundle exec rails c. Interestingly, raw irb as well as bundle exec irb don't have most of the above issues, except the Home/End keys and Ctrl+c needs an Enter before I get a fresh prompt line.

I can replicate the issue with a barebones Rails Gemfile:

source 'https://rubygems.org'
gem 'rails', '3.2.6'
gem 'sqlite3'

My shell is zsh, on Ubuntu 12.04 64-bit. $JAVA_HOME is /usr/lib/jvm/java-7-openjdk-amd64, but it might have still been java-6 when I installed this interpreter, if that matters.

Update: Some fixes

The missing prompt character is apparently caused by the IRB.conf[:PROMPT_MODE] getting set to :NULL by the Rails console. For regular irb, mine gets set to :RVM (apparently rvm does this in ~/.rvm/scripts/irb.rb; I ruled out rvm causing this issue by commenting out the script). Providing a :PROMPT_MODE value in ~/.irbrc fixes this. I thought maybe a similar issue was causing the Ctrl+c / Ctrl+d problems by changing :IGNORE_SIGINT and :IGNORE_EOF, but they are both set to their default values.

Tab completion and arrow keys get fixed by setting :USE_READLINE to true.

Here's my current ~/.irbrc that seems to fix said issues:

require 'irb/completion'

IRB.conf[:PROMPT_MODE]  = :SIMPLE
IRB.conf[:USE_READLINE] = true
IRB.conf[:AUTO_INDENT]  = true

回答1:


Running the console with the following fixed these sorts of problems for me:

jruby -Xlaunch.inproc=true -S rails c

If you don't like running that command every time, you can set an environment variable:

set JRUBY_OPTS=-Xlaunch.inproc=true

or

export JRUBY_OPTS=-Xlaunch.inproc=true

then

rails c



回答2:


I had this issue with Windows and the fix was to increase the "Number of Buffers" in the Command prompt settings. Command Prompt -> Properties -> Options -> Number of Buffers Default is 4, I changed to 8 and all worked well (I think 5 would work though)



来源:https://stackoverflow.com/questions/13649437/rails-console-issues-using-jruby-no-prompt-character-no-tab-completion-broken

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!