Class: PM::ListWindow

Inherits:
PmWindow
  • Object
show all
Defined in:
lib/patchmaster/curses/list_window.rb

Instance Attribute Summary collapse

Attributes inherited from PmWindow

#title, #title_prefix, #win

Instance Method Summary collapse

Methods inherited from PmWindow

#make_fit, #move_and_resize, #set_max_contents_len, #visible_height

Constructor Details

#initialize(rows, cols, row, col, title_prefix) ⇒ ListWindow

Returns a new instance of ListWindow.



8
9
10
11
# File 'lib/patchmaster/curses/list_window.rb', line 8

def initialize(rows, cols, row, col, title_prefix)
  super
  @offset = 0
end

Instance Attribute Details

#listObject (readonly)

Returns the value of attribute list.



6
7
8
# File 'lib/patchmaster/curses/list_window.rb', line 6

def list
  @list
end

Instance Method Details

#drawObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/patchmaster/curses/list_window.rb', line 20

def draw
  super
  return unless @list

  curr_item = PM::PatchMaster.instance.send(@curr_item_method_sym)
  return unless curr_item

  curr_index = @list.index(curr_item)
  if curr_index < @offset
    @offset = curr_index
  elsif curr_index >= @offset + visible_height
    @offset = curr_index - visible_height + 1
  end

  @list[@offset, visible_height].each_with_index do |thing, i|
    @win.setpos(i+1, 1)
    @win.attron(A_REVERSE) if thing == curr_item
    @win.addstr(make_fit(" #{thing.name} "))
    @win.attroff(A_REVERSE) if thing == curr_item
  end
end

#set_contents(title, list, curr_item_method_sym) ⇒ Object

PM::PatchMaster to obtain the current item so we can highlight it.



15
16
17
18
# File 'lib/patchmaster/curses/list_window.rb', line 15

def set_contents(title, list, curr_item_method_sym)
  @title, @list, @curr_item_method_sym = title, list, curr_item_method_sym
  draw
end