为什么退格键会删除JRuby中的整行以及可以解决的问题?

时间:2015-10-06 21:51:18

标签: ruby jruby

我在JRuby中开发了一些工具。这两个工具都向用户提示了几个问题。在回答这些问题时,如果用户想要更正错误的条目并按backspace键删除整行(包括问题)而不是仅删除一个字符。

以下是提示问题的代码:

require highline/import

def prompt
  begin
      input=ask("\t\tEnter user name: ") do |ch|
              ch=true
          end

      input
  rescue => e
       print "Error -"+e
  end

end

我想知道你们之前是否有人见过这种问题,可以解决这个问题的原因是什么?非常感谢您的时间和帮助。

提前致谢。

2 个答案:

答案 0 :(得分:1)

以下是代码的工作部分。我删除了\t并将ch=true更改为ch.readline=true。感谢您的所有帮助和指导。

require highline/import

def prompt
    begin
        input=ask("Enter user name: ") do |ch|
              ch.readline=true
            end

        input
     rescue => e
          print "Error -"+e
      end
end

答案 1 :(得分:0)

如果您使用的是highline gem,那么在阅读输入而不是

,
    "syntax": "Packages/Text/Plain text.tmLanguage"

使用

// standard sublime view settings that will be overwritten on each repl view
// this has to be customized as a whole dictionary
"repl_view_settings": {
    "translate_tabs_to_spaces": false,
    "auto_indent": false,
    "smart_indent": false,
    "spell_check": false,
    "indent_subsequent_lines": false,
    "detect_indentation": false,
    "auto_complete": true,
    "line_numbers": false,
    "gutter": false,
    "syntax": "Packages/Text/Plain text.tmLanguage"
},

来源:https://www.ruby-forum.com/topic/4406162