Class: Ifilter::Client
- Inherits:
-
Object
- Object
- Ifilter::Client
- Defined in:
- lib/ifilter/client.rb
Instance Method Summary collapse
- #execute(array) ⇒ Object
-
#initialize(name) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(name) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/ifilter/client.rb', line 5 def initialize(name) @prompt = "#{name}> " @target = [] @input = Input.new @outputs = [] @cursor_position = 1 @page_number = 1 @window = Window.new(Curses.lines, Curses.cols, 0, 0) end |
Instance Method Details
#execute(array) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ifilter/client.rb', line 17 def execute(array) @target = array update_window loop do key = @window.getch keycode = get_keycode(key) if key.class == String @input << key @filtered_result = nil @page_number = 1 elsif key == 127 # <BS> @input.backspace! @filtered_result = nil @page_number = 1 elsif keycode == :KEY_CTRL_J # <CR> break if @outputs.size >= @cursor_position elsif keycode == :KEY_DOWN || keycode == :KEY_CTRL_N down_cursor_position unless @outputs.empty? next elsif keycode == :KEY_UP || keycode == :KEY_CTRL_P up_cursor_position unless @outputs.empty? next else # Ignore other keys next end update_window end @window.close @outputs[@cursor_position - 1] rescue Interrupt # <C-c> @window.close end |