module SpecSelectorUtil::UI
The UI
module contains methods used to bind and process user input.
Constants
- DIRECTION_KEYS
- OPTION_KEYS
- TREE_NAVIGATION_KEYS
Public Instance Methods
back()
click to toggle source
# File lib/spec_selector/ui.rb, line 84 def back return if top_level? parent_list set_selected display_list end
bind_input()
click to toggle source
# File lib/spec_selector/ui.rb, line 33 def bind_input input = user_input direction_keys(input) if DIRECTION_KEYS.include?(input) tree_nav_keys(input) if TREE_NAVIGATION_KEYS.include?(input) option_keys(input) if OPTION_KEYS.any? { |key| input.match?(key) } end
direction_keys(input)
click to toggle source
# File lib/spec_selector/ui.rb, line 105 def direction_keys(input) exit_instruction_page if @instructions dir = input == "\e[A" ? -1 : 1 @selector_index = (@selector_index + dir) % @list.length @selected = @list[@selector_index] @example_display ? display_example : display_list end
exit_instruction_page_only()
click to toggle source
# File lib/spec_selector/ui.rb, line 71 def exit_instruction_page_only exit_instruction_page refresh_display end
exit_only()
click to toggle source
# File lib/spec_selector/ui.rb, line 12 def exit_only q_to_exit loop { quit if user_input.match?(/^q$/i) } end
option_keys(input)
click to toggle source
# File lib/spec_selector/ui.rb, line 126 def option_keys(input) case input when /^t$/i top_fail! when /^ $/ top_fail when /^p$/i toggle_passing when /^f$/i run_only_fails when /^q$/i quit when /^i$/i unless @instructions view_instructions_page return end exit_instruction_page_only when /^r$/i rerun when /^a$/i rerun_all when /^m$/i return if @instructions @selected.metadata[:include] ? filter_remove : filter_include refresh_display when /^c$/i clear_filter when /^v$/i view_inclusion_filter end end
parent_list()
click to toggle source
# File lib/spec_selector/ui.rb, line 92 def parent_list if @example_display @example_display = false @list = @active_map[@selected.example_group.metadata[:block]] else data = parent_data(@selected.metadata) p_data = parent_data(data) parent_key = p_data ? p_data[:block] : :top_level @list = @active_map[parent_key] @selected = @groups[data[:block]] end end
quit()
click to toggle source
# File lib/spec_selector/ui.rb, line 40 def quit close_alt_buffer if @instructions clear_frame delete_filter_data reveal_cursor exit end
select_item()
click to toggle source
# File lib/spec_selector/ui.rb, line 57 def select_item return if @example_display if example?(@selected) display_example return end @list = @active_map[@selected.metadata[:block]] @selected = nil set_selected display_list end
selector()
click to toggle source
# File lib/spec_selector/ui.rb, line 17 def selector set_selected @example_count > 1 ? display_list : display_example navigate end
set_selected()
click to toggle source
# File lib/spec_selector/ui.rb, line 23 def set_selected @list ||= @active_map[:top_level] @selected ||= @list.first end
top_fail()
click to toggle source
# File lib/spec_selector/ui.rb, line 76 def top_fail exit_instruction_page if @instructions return if @failed.empty? @selected = @failed.first display_example end
top_level_list()
click to toggle source
# File lib/spec_selector/ui.rb, line 48 def top_level_list exit_instruction_page if @instructions @example_display = false @selected = nil @list = @active_map[:top_level] set_selected display_list end
user_input()
click to toggle source
# File lib/spec_selector/ui.rb, line 161 def user_input input = $stdin.getch return input unless IO.select([$stdin], nil, nil, 0.000001) input << $stdin.read_nonblock(2) input end