From: Marc Heiler Date: 2011-11-08T02:24:45+09:00 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/.