Hi. Perhaps anyone can help me.
Here the ruby test script for me ( If you don't want to copy paste,
here is a link to it on github https://gist.github.com/1345574 and
pastie http://pastie.org/2826323 ).
require 'pp'
require 'readline'
T = true
F = false
@use_readline = T
alias e puts
def show_welcome_message
e 'Hi! Please input something now.'
end
def get_user_input
begin
if @use_readline # Use readline.
@user_input = Readline.readline('',true)
else # Or use gets instead.
@user_input = gets.chomp
end
rescue Interrupt => error
e 'KeyInterrupt -> BYE!'
exit_program
end
end
def exit_program; exit 1; end # Exit here.
def check_against_menu
_ = @user_input
case _
when 'q'
exit_program
else
e 'Not found input `'+_+'`.'
end
end
show_welcome_message
loop {
get_user_input
check_against_menu
}
···
---------------------------------------------
If I use gets() and then hit Ctrl-C, the script will
interrupt immediately.
If I use readline though (by changing the variable
@use_readline from T to F, true to false) and then
hit Ctrl-C, I need to hit the ENTER key before I get
the exception.
Does anyone know why? Can anyone reproduce this?
I use Linux, Knoppix hdinstall (Debian), bash shell
in KDE4 konsole and ruby 1.8.7 (2011-02-18
patchlevel 334) [i686-linux]
--
Posted via http://www.ruby-forum.com/.
I can't reproduce this. Readline works the same way as gets on my desktop. (redhat)
$ uname -a
Linux 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:54 EDT 2009 i686 i686 i386 GNU/Linux
$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]
Best,
Jingjing
···
-----Original Message-----
From: Marc Heiler [mailto:shevegen@linuxmail.org]
Sent: Monday, November 07, 2011 9:25 AM
To: ruby-talk ML
Subject: Readline.readline - Hitting enter key?
Hi. Perhaps anyone can help me.
Here the ruby test script for me ( If you don't want to copy paste,
here is a link to it on github https://gist.github.com/1345574 and
pastie http://pastie.org/2826323 ).
require 'pp'
require 'readline'
T = true
F = false
@use_readline = T
alias e puts
def show_welcome_message
e 'Hi! Please input something now.'
end
def get_user_input
begin
if @use_readline # Use readline.
@user_input = Readline.readline('',true)
else # Or use gets instead.
@user_input = gets.chomp
end
rescue Interrupt => error
e 'KeyInterrupt -> BYE!'
exit_program
end
end
def exit_program; exit 1; end # Exit here.
def check_against_menu
_ = @user_input
case _
when 'q'
exit_program
else
e 'Not found input `'+_+'`.'
end
end
show_welcome_message
loop {
get_user_input
check_against_menu
}
---------------------------------------------
If I use gets() and then hit Ctrl-C, the script will
interrupt immediately.
If I use readline though (by changing the variable
@use_readline from T to F, true to false) and then
hit Ctrl-C, I need to hit the ENTER key before I get
the exception.
Does anyone know why? Can anyone reproduce this?
I use Linux, Knoppix hdinstall (Debian), bash shell
in KDE4 konsole and ruby 1.8.7 (2011-02-18
patchlevel 334) [i686-linux]
--
Posted via http://www.ruby-forum.com/.