Class: RubyAnything::ItemsWindow

Inherits:
BaseWindow show all
Defined in:
lib/ruby-anything/windows/items_window.rb

Constant Summary

Constants inherited from BaseWindow

BaseWindow::KEYS

Instance Attribute Summary collapse

Attributes inherited from BaseWindow

#cursor, #top

Instance Method Summary collapse

Methods inherited from BaseWindow

#before_down, #before_left, #before_right, #before_up, #change_focus_line, #down, #draw_at, #draw_at!, #enhansive_line, #in_color, #in_pos, #left, #method_missing, #normalize_line, #refresh, #right, #up, #view_collection

Constructor Details

#initialize(parent, items = [], opt) ⇒ ItemsWindow

Returns a new instance of ItemsWindow.



7
8
9
10
# File 'lib/ruby-anything/windows/items_window.rb', line 7

def initialize(parent, items = [], opt)
  @items = items
  super parent, opt
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RubyAnything::BaseWindow

Instance Attribute Details

#itemsObject

Returns the value of attribute items.



5
6
7
# File 'lib/ruby-anything/windows/items_window.rb', line 5

def items
  @items
end

Instance Method Details

#collectionObject



36
# File 'lib/ruby-anything/windows/items_window.rb', line 36

def collection; items.filter(filter_text.to_s) end

#filter(_filter_text) ⇒ Object



16
17
18
19
20
# File 'lib/ruby-anything/windows/items_window.rb', line 16

def filter(_filter_text)
  @filter_text = _filter_text
  cursor.clear
  in_pos(0, 0) { update }
end

#filter_textObject



12
13
14
# File 'lib/ruby-anything/windows/items_window.rb', line 12

def filter_text
  @filter_text ||= ""
end

#on_input(ch) ⇒ Object



39
40
41
42
43
44
# File 'lib/ruby-anything/windows/items_window.rb', line 39

def on_input(ch)
  case ch
  when *KEYS[:up] then up
  when *KEYS[:down] then down
  end
end

#selected_itemObject



37
# File 'lib/ruby-anything/windows/items_window.rb', line 37

def selected_item; view_collection[cursor.y] end

#updateObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ruby-anything/windows/items_window.rb', line 22

def update
  items.each_with_index do |item, index|
    setpos index, 0
    clrtoeol
  end
  refresh

  change_focus_line {
    view_collection.each_with_index do |item, index|
      draw_at index
    end
  }
end