lib/cryptum/ui.rb in cryptum-0.0.254 vs lib/cryptum/ui.rb in cryptum-0.0.255
- old
+ new
@@ -85,28 +85,23 @@
# Draw a Box Around a Window
public_class_method def self.line(opts = {})
ui_win = opts[:ui_win]
out_line_no = opts[:out_line_no].to_i
+ color = opts[:color]
+ color ||= :white
+ style = :normal
+ style = :bold unless color == :white
+
ui_win.setpos(out_line_no, 0)
- if Curses.can_change_color?
- colorize(
- ui_win: ui_win,
- color: :custom,
- red: 192,
- green: 192,
- blue: 192,
- string: "\u2500" * Curses.cols
- )
- else
- colorize(
- ui_win: ui_win,
- color: :white,
- string: "\u2500" * Curses.cols
- )
- end
+ colorize(
+ ui_win: ui_win,
+ color: color,
+ style: style,
+ string: "\u2500" * Curses.cols
+ )
rescue Interrupt
# Exit Gracefully if CTRL+C is Pressed During Session
Cryptum.exit_gracefully(which_self: self)
rescue StandardError => e
# Produce a Stacktrace for anything else
@@ -272,11 +267,22 @@
public_class_method def self.detect_key_press_in_ui(opts = {})
key_press_event = opts[:key_press_event]
ui_win = opts[:ui_win]
- case ui_win.getch
+ key_press = ui_win.get_char
+
+ # Useful for detecting and logging actual key presses to file
+ # 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
+
+ case key_press
when 'C'
key_press_event.key_c = true
when 'G'
key_press_event.key_g = true
when 'r'
@@ -285,10 +291,19 @@
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
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 = true if key_press_event.key_ansi && key_press == 'A'
+ key_press_event.key_down = true if key_press_event.key_ansi && key_press == 'B'
key_press_event
rescue Interrupt
# Exit Gracefully if CTRL+C is Pressed During Session
Cryptum.exit_gracefully(which_self: self)