lib/cryptum/ui.rb in cryptum-0.0.262 vs lib/cryptum/ui.rb in cryptum-0.0.263
- old
+ new
@@ -275,11 +275,11 @@
# unless key_press.nil?
# File.open('/tmp/detect_key_press_in_ui-cryptum.txt', 'a') do |f|
# f.puts key_press.class
# f.print key_press.inspect
# f.puts "\n\n\n"
- # end
+ # end
# end
case key_press
when 'C'
key_press_event.key_c = true
@@ -291,19 +291,33 @@
key_press_event.key_u = true
when 'w'
key_press_event.key_w = true
when 'x'
key_press_event.key_x = true
- when "\t"
- key_press_event.key_tab = true
when "\e"
key_press_event.key_esc = true
+ when "\n"
+ key_press_event.key_enter = true
+ when "\t"
+ key_press_event.key_tab = true
end
- # What a hack to detect up / down arrow key presses.
- key_press_event.key_ansi = true if key_press_event.key_esc && key_press == '['
- key_press_event.key_up_arrow = true if key_press_event.key_ansi && key_press == 'A'
- key_press_event.key_down_arrow = true if key_press_event.key_ansi && key_press == 'B'
+ # What a hack to detect special keys (-.-)
+ if key_press_event.key_esc
+ key_press_event.key_ansi = true if key_press == '['
+ if key_press_event.key_ansi
+ key_press_event.key_up_arrow = true if key_press == 'A'
+ key_press_event.key_down_arrow = true if key_press == 'B'
+ # NOTE: the ~ at the end of these keys are ignored
+ # which may result in other keys working in place of them
+ # e.g. home is \e[1~ but we know it's home as soon as
+ # \e[1 is detected.
+ key_press_event.key_page_up = true if key_press == '5'
+ key_press_event.key_page_down = true if key_press == '6'
+ key_press_event.key_home = true if key_press == '1'
+ key_press_event.key_end = true if key_press == '4'
+ end
+ end
key_press_event
rescue Interrupt
# Exit Gracefully if CTRL+C is Pressed During Session
Cryptum.exit_gracefully(which_self: self)