class PM::ListWindow

Attributes

list[R]

Public Class Methods

new(rows, cols, row, col, title_prefix) click to toggle source
Calls superclass method
# File lib/patchmaster/curses/list_window.rb, line 8
def initialize(rows, cols, row, col, title_prefix)
  super
  @offset = 0
end

Public Instance Methods

draw() click to toggle source
Calls superclass method
# 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) click to toggle source

curr_item_method_sym is a method symbol that is sent to PM::PatchMaster to obtain the current item so we can highlight it.

# 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