lib/textbringer/controller.rb in textbringer-0.1.6 vs lib/textbringer/controller.rb in textbringer-0.1.7
- old
+ new
@@ -26,17 +26,20 @@
@this_command = nil
@last_command = nil
@overriding_map = nil
@prefix_arg = nil
@current_prefix_arg = nil
+ @echo_immediately = false
end
def command_loop(tag)
catch(tag) do
loop do
begin
+ echo_input
c = read_char
+ break if c.nil?
Window.echo_area.clear_message
@last_key = c
@key_sequence << @last_key
cmd = key_binding(@key_sequence)
if cmd.is_a?(Symbol) || cmd.respond_to?(:call)
@@ -58,15 +61,17 @@
end
else
if cmd.nil?
keys = @key_sequence.map { |ch| key_name(ch) }.join(" ")
@key_sequence.clear
+ @prefix_arg = nil
message("#{keys} is undefined")
end
end
rescue Exception => e
show_exception(e)
+ @prefix_arg = nil
end
Window.redisplay
end
end
end
@@ -107,10 +112,12 @@
case key
when Symbol
"<#{key}>"
when "\e"
"ESC"
+ when "\n"
+ "RET"
when /\A[\0-\b\v-\x1f\x7f]\z/
"C-" + (key.ord ^ 0x40).chr.downcase
else
key.to_s
end
@@ -120,8 +127,35 @@
def key_binding(key_sequence)
@overriding_map&.lookup(key_sequence) ||
Buffer.current&.keymap&.lookup(key_sequence) ||
GLOBAL_MAP.lookup(key_sequence)
+ end
+
+ def echo_input
+ if @prefix_arg || !@key_sequence.empty?
+ if !@echo_immediately
+ return if wait_input(1000)
+ end
+ @echo_immediately = true
+ s = String.new
+ if @prefix_arg
+ s << "C-u"
+ if @prefix_arg != [4]
+ s << "(#{@prefix_arg.inspect})"
+ end
+ end
+ if !@key_sequence.empty?
+ s << " " if !s.empty?
+ s << @key_sequence.map { |ch| key_name(ch) }.join(" ")
+ end
+ s << "-"
+ Window.echo_area.show(s)
+ Window.echo_area.redisplay
+ Window.current.window.noutrefresh
+ Window.update
+ else
+ @echo_immediately = false
+ end
end
end
end