Class: RETerm::Components::ScrollList

Inherits:
RETerm::Component show all
Includes:
RETerm::CDKComponent, ItemHelpers
Defined in:
lib/reterm/components/scroll_list.rb

Overview

Scrolling List CDK Component

Constant Summary

Constants included from LogHelpers

LogHelpers::LOG_FILE

Instance Attribute Summary collapse

Attributes inherited from RETerm::Component

#activatable, #activate_focus, #highlight_focus, #window

Instance Method Summary collapse

Methods included from ItemHelpers

#max_item_size

Methods included from RETerm::CDKComponent

#activatable?, #bind_key, #cdk?, #colors=, #component, #deactivate!, #draw!, #early_exit?, #erase, #escape_hit?, #init?, #init_cdk, #normal_exit?, #strip_formatting, #title_attrib=, #value

Methods inherited from RETerm::Component

#activatable?, #activate_focus?, #cdk?, #colored?, #colors=, #deactivate!, #deactivate?, #distance_from, #extra_padding, #finalize!, #highlight_focus?, #reactivate!, #resize, #sync!, #sync_getch

Methods included from KeyBindings

#bind_key, #invoke_key_bindings, #key_bindings, #key_bound?

Methods included from LogHelpers

#logger

Methods included from EventDispatcher

#dispatch, #handle

Constructor Details

#initialize(args = {}) ⇒ ScrollList

Initialize the ScrollList component

Parameters:

  • args (Hash) (defaults to: {})

    list params

Options Hash (args):

  • :title (String)

    title of list

  • :items (Array<String>)

    items to populate list with



16
17
18
19
20
# File 'lib/reterm/components/scroll_list.rb', line 16

def initialize(args={})
  super
  @title  = args[:title] || ""
  @items  = args[:items] || []
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



8
9
10
# File 'lib/reterm/components/scroll_list.rb', line 8

def items
  @items
end

Instance Method Details

#<<(item) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/reterm/components/scroll_list.rb', line 34

def <<(item)
  @items << item

  if window.expand? &&
     (window.rows < (requested_rows + extra_padding) ||
      window.cols < (requested_cols + extra_padding))
    window.request_expansion requested_rows + extra_padding,
                             requested_cols + extra_padding
  end
end

#activate!(*input) ⇒ Object



65
66
67
68
69
70
# File 'lib/reterm/components/scroll_list.rb', line 65

def activate!(*input)
  i = super
  return nil unless normal_exit?
  dispatch(:selected)
  @items[i]
end

#currentObject



57
58
59
# File 'lib/reterm/components/scroll_list.rb', line 57

def current
  selected
end

#current_indexObject



61
62
63
# File 'lib/reterm/components/scroll_list.rb', line 61

def current_index
  component.getCurrentItem
end

#empty!Object



49
50
51
# File 'lib/reterm/components/scroll_list.rb', line 49

def empty!
  @items.clear
end

#quit_on_enter=(v) ⇒ Object



22
23
24
# File 'lib/reterm/components/scroll_list.rb', line 22

def quit_on_enter=(v)
  component.quit_on_enter = v
end

#requested_colsObject



30
31
32
# File 'lib/reterm/components/scroll_list.rb', line 30

def requested_cols
  [@title.size, max_item_size].max + 2
end

#requested_rowsObject



26
27
28
# File 'lib/reterm/components/scroll_list.rb', line 26

def requested_rows
  2 + @items.size
end

#reset!Object



45
46
47
# File 'lib/reterm/components/scroll_list.rb', line 45

def reset!
  component.setCurrentItem(0)
end

#selectedObject



53
54
55
# File 'lib/reterm/components/scroll_list.rb', line 53

def selected
  @items[component.getCurrentItem]
end