本文介绍了使用JRuby的Rails控制台问题:没有提示字符,没有制表符完成,箭头键断开等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我在JRuby下的Rails控制台遇到各种问题,包括

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

  • 没有提示字符
  • 完成不起作用(插入了文字标签)
  • 上/下箭头不浏览历史记录(分别插入了^[[A^[[B)
  • 左/右箭头不移动光标(分别插入了^[[D^[[C)
  • /键不能将光标移动到行首/行尾(分别插入了1~4~); + / + 仍然可以工作
  • + 杀死控制台,而不是杀死我要输入的行
  • + 无效,直到我按(然后执行我在和.
  • No prompt character
  • 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)
  • / keys not moving cursor to beginning/end of line (instead 1~ or 4~ inserted, respectively); + / + work though
  • + killing console instead of killing the line I'm entering
  • + not having any effect until I hit (which then executes anything I entered between + and in my Unix shell).

我从rvm安装了我的JRuby解释器,如下所示:

I installed my JRuby interpreter from rvm like so:

rvm install jruby-1.6.8 --1.9

我的Rails项目是使用Bundler(而不是rvm gemsets)管理的,因此我使用bundle exec rails c运行Rails控制台.有趣的是,除了/键和需要输入新的提示行之前,请输入.

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 / keys and + needs an before I get a fresh prompt line.

我可以使用准系统Rails Gemfile复制该问题:

I can replicate the issue with a barebones Rails Gemfile:

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

我的shell是zsh,在Ubuntu 12.04 64位上. $JAVA_HOME/usr/lib/jvm/java-7-openjdk-amd64,但在安装此解释器时,它可能仍然是java-6.

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.

更新:一些修复程序

缺少提示字符显然是由Rails控制台将IRB.conf[:PROMPT_MODE]设置为:NULL引起的.对于常规的irb,我的设置为:RVM(显然rvm在~/.rvm/scripts/irb.rb中执行此操作;我通过注释掉脚本来排除rvm导致此问题).在~/.irbrc中提供:PROMPT_MODE值可解决此问题.我认为可能是类似的问题通过更改:IGNORE_SIGINT导致 + / + 问题和:IGNORE_EOF,但它们均设置为默认值.

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 + / + problems by changing :IGNORE_SIGINT and :IGNORE_EOF, but they are both set to their default values.

通过将:USE_READLINE设置为true,可以固定制表符完成和箭头键.

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

这是我当前的~/.irbrc似乎可以解决上述问题:

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

推荐答案

使用以下命令运行控制台对我来说解决了这些问题:

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

export JRUBY_OPTS=-Xlaunch.inproc=true

然后

rails c

这篇关于使用JRuby的Rails控制台问题:没有提示字符,没有制表符完成,箭头键断开等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 02:12