class UserInputActor

Constants

DEFAULT_SCROLL_STEP
USER_INPUT_MAPPINGS

Public Class Methods

new() click to toggle source
# File lib/user_input_actor.rb, line 38
def initialize
  async.watch_input
end
pop_mode() click to toggle source
# File lib/user_input_actor.rb, line 26
def self.pop_mode
  @user_input_mode = prev_user_input_modes.pop
end
prev_user_input_modes() click to toggle source
# File lib/user_input_actor.rb, line 12
def self.prev_user_input_modes
  @prev_user_input_modes ||= []
end
push_mode(mode) click to toggle source
# File lib/user_input_actor.rb, line 21
def self.push_mode(mode)
  prev_user_input_modes << @user_input_mode if @user_input_mode
  @user_input_mode = mode
end
set_user_input_mode(mode) click to toggle source
# File lib/user_input_actor.rb, line 16
def self.set_user_input_mode(mode)
  debug_message "set input mode: #{mode.inspect}"
  push_mode(mode)
end
user_input_mode() click to toggle source
# File lib/user_input_actor.rb, line 8
def self.user_input_mode
  @user_input_mode
end

Public Instance Methods

clean_up() click to toggle source
# File lib/user_input_actor.rb, line 177
def clean_up
  debug_message "done user input"
end
handle_help_input(ch) click to toggle source
# File lib/user_input_actor.rb, line 74
def handle_help_input(ch)
  case ch
  when ?q.ord
    mode = pop_mode
    case mode
    when :welcome_user then publish "welcome_user"
    when :working_set  then publish "display_working_set"
    else
      debug_message "Unrecognized mode from pop: #{mode.inspect}"
      throw :shutdown
    end
  else
    debug_message "Unhandled user input: #{ch}"
  end
end
handle_modal_input(ch) click to toggle source
# File lib/user_input_actor.rb, line 59
def handle_modal_input(ch)
  if ch == Ncurses::KEY_RESIZE # window resize
    publish "window_resized"
    return
  end
  case user_input_mode
  when :welcome_user then handle_welcome_user_input(ch)
  when :help         then handle_help_input(ch)
  when :working_set  then handle_working_set_input(ch)
  else
    debug_message "Uncrecognized mode: #{user_input_mode.inspect}"
    throw :shutdown
  end
end
handle_welcome_user_input(ch) click to toggle source
# File lib/user_input_actor.rb, line 90
def handle_welcome_user_input(ch)
  case ch
  when ?q.ord
    throw :shutdown
  when ??.ord
    publish "display_help"
  else
    debug_message "Unhandled user input: #{ch}"
  end
end
handle_working_set_input(ch) click to toggle source
# File lib/user_input_actor.rb, line 169
def handle_working_set_input(ch)
  mapping = USER_INPUT_MAPPINGS[ch] || USER_INPUT_MAPPINGS[ch.chr]
  if mapping
    instance_exec(&mapping[:action])
  end
rescue RangeError # ignore when .chr is out of range.  Just means it's not input we care about anyways.
end
pop_mode() click to toggle source
# File lib/user_input_actor.rb, line 34
def pop_mode
  self.class.pop_mode
end
user_input_mode() click to toggle source
# File lib/user_input_actor.rb, line 30
def user_input_mode
  self.class.user_input_mode
end
watch_input() click to toggle source
# File lib/user_input_actor.rb, line 42
def watch_input

  # Creating this otherwise unused window so that I can run getch() without
  # the implicit call to stdscr.refresh that it apparently precipitates.
  trash_win = Ncurses.newwin(1, 1, 0, 0)
  trash_win.keypad(true)

  catch(:shutdown) do
    while(ch = trash_win.getch)
      debug_message "getch: #{ch}"
      handle_modal_input(ch)
    end
  end
  debug_message "Caught :shutdown"
  $supervisor.do_shutdown
end