Module: Ripl::Readline::EmInput
- Defined in:
- lib/ripl/readline/eminput.rb
Instance Method Summary collapse
- #handle_interrupt ⇒ Object
- #handler_install ⇒ Object
- #initialize(opts = {}) ⇒ Object
- #notify_readable ⇒ Object
- #on_exit ⇒ Object
- #receive_line(line) ⇒ Object
- #unbind ⇒ Object
Instance Method Details
#handle_interrupt ⇒ Object
56 57 58 59 60 |
# File 'lib/ripl/readline/eminput.rb', line 56 def handle_interrupt ::Readline.callback_handler_remove puts handler_install end |
#handler_install ⇒ Object
62 63 64 65 66 |
# File 'lib/ripl/readline/eminput.rb', line 62 def handler_install ::Readline.callback_handler_install(Ripl.shell.prompt) do |line| EventMachine.next_tick { receive_line(line) } end end |
#initialize(opts = {}) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/ripl/readline/eminput.rb', line 16 def initialize(opts = {}) super() @on_exit = opts[:on_exit] || proc { EventMachine.stop_event_loop } handler_install Ripl.shell.before_loop trap('SIGINT') { handle_interrupt } end |
#notify_readable ⇒ Object
24 25 26 |
# File 'lib/ripl/readline/eminput.rb', line 24 def notify_readable ::Readline.callback_read_char end |
#on_exit ⇒ Object
35 36 37 |
# File 'lib/ripl/readline/eminput.rb', line 35 def on_exit @on_exit.call if @on_exit end |
#receive_line(line) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ripl/readline/eminput.rb', line 39 def receive_line(line) catch(:normal_exit) do catch(:ripl_exit) do throw :ripl_exit unless line # line = nil implies EOF Ripl.shell.input = line Ripl.shell.loop_once handler_install # EditLine requires handler be # reinstalled for each line. # Seems harmless for Readline throw :normal_exit end detach # :ripl_exit end # :normal_exit end |
#unbind ⇒ Object
28 29 30 31 32 33 |
# File 'lib/ripl/readline/eminput.rb', line 28 def unbind super ::Readline.callback_handler_remove Ripl.shell.after_loop on_exit end |