io/input.rb in trepanning-0.1.4 vs io/input.rb in trepanning-0.1.6
- old
+ new
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
-# Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
+# Copyright (C) 2010-2012 Rocky Bernstein <rockyb@rubyforge.net>
# Debugger user/command-oriented input possibly attached to IO-style
# input or GNU Readline.
#
@@ -11,10 +11,12 @@
# Debugger user/command-oriented input possibly attached to IO-style
# input or GNU Readline.
class UserInput < Trepan::InputBase
+ attr_reader :use_readline
+
@@readline_finalized = false
def initialize(inp, opts={})
@opts = DEFAULT_OPTS.merge(opts)
@input = inp || STDIN
@@ -34,10 +36,16 @@
raise EOFError if eof?
begin
if @line_edit && @use_readline
line = Readline.readline(prompt, true)
else
+ # Prompt should be empty and should have been
+ # handled by caller.
+ unless prompt.empty?
+ raise RuntimeError,
+ "Internal error: prompt '#{prompt}' should have been handled by caller" unless prompt.empty?
+ end
line = @input.gets
end
rescue Interrupt
return ''
rescue EOFError
@@ -64,20 +72,20 @@
inp.respond_to?(:isatty) && inp.isatty && Trepan::GNU_readline?
self.new(inp, opts)
end
def finalize
- if defined?(RbReadline) && !@@readline_finalized
+ if defined?(RbReadline) && !@@readline_finalized
begin
RbReadline.rl_cleanup_after_signal()
rescue
end
begin
RbReadline.rl_deprep_terminal()
rescue
end
@@readline_finalized = true
- end
+ end
end
end
end
end