Search code examples
rubyjruby

Why backspace key deletes the entire row in JRuby and what can be the fix for it?


I have developed a couple of tools in JRuby. Both the tools prompt for few questions to the user. While answering these questions if the user wants to correct a wrong entry and hits backspace key that deletes the entire line (including the question) instead of deleting just one character.

Below is the piece of code that prompts the questions:

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

I was wondering if anyone of you have seen this kind of problem before and what can be the fix for this? Really appreciate your time and help.

Thanks in advance.


Solution

  • Below is the working piece of the code. I removed \t and changed ch=true to ch.readline=true. Thank for all of your help and guidance.

    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