Class: Rfd::MainWindow

Inherits:
Window
  • Object
show all
Defined in:
lib/rfd/windows.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Window

draw_borders, #writeln

Constructor Details

#initializeMainWindow

Returns a new instance of MainWindow.



84
85
86
87
# File 'lib/rfd/windows.rb', line 84

def initialize
  @begy, @current_index, @number_of_panes = 5, 0, 2
  super window: Curses::Pad.new(Curses.lines - 7, Curses.cols - 2)
end

Instance Attribute Details

#begyObject (readonly)

Returns the value of attribute begy.



81
82
83
# File 'lib/rfd/windows.rb', line 81

def begy
  @begy
end

#current_indexObject (readonly)

Returns the value of attribute current_index.



81
82
83
# File 'lib/rfd/windows.rb', line 81

def current_index
  @current_index
end

#number_of_panes=(value) ⇒ Object (writeonly)

Sets the attribute number_of_panes

Parameters:

  • value

    the value to set the attribute number_of_panes to.



82
83
84
# File 'lib/rfd/windows.rb', line 82

def number_of_panes=(value)
  @number_of_panes = value
end

Instance Method Details

#activate_pane(num) ⇒ Object



102
103
104
# File 'lib/rfd/windows.rb', line 102

def activate_pane(num)
  @current_index = num
end

#display(page) ⇒ Object



98
99
100
# File 'lib/rfd/windows.rb', line 98

def display(page)
  noutrefresh 0, (Curses.cols - 2) * page, begy, 1, begy + maxy - 1, Curses.cols - 2
end

#draw_item(item, current: false) ⇒ Object



118
119
120
121
122
123
# File 'lib/rfd/windows.rb', line 118

def draw_item(item, current: false)
  setpos item.index % maxy, width * @current_index
  attron(Curses.color_pair(item.color) | (current ? Curses::A_UNDERLINE : Curses::A_NORMAL)) do
    self << item.to_s
  end
end

#draw_items_to_each_pane(items) ⇒ Object



125
126
127
128
129
130
131
132
# File 'lib/rfd/windows.rb', line 125

def draw_items_to_each_pane(items)
  items.each_slice(maxy).each.with_index do |arr, col_index|
    arr.each.with_index do |item, i|
      setpos i, width * col_index
      attron(Curses.color_pair(item.color) | Curses::A_NORMAL) { self << item.to_s }
    end
  end
end

#max_itemsObject



114
115
116
# File 'lib/rfd/windows.rb', line 114

def max_items
  maxy * @number_of_panes
end

#newpad(items) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/rfd/windows.rb', line 89

def newpad(items)
  clear
  columns = items.size / maxy + 1
  newx = width * (((columns - 1) / @number_of_panes + 1) * @number_of_panes)
  resize maxy, newx if newx != maxx

  draw_items_to_each_pane items
end

#pane_index_at(y: nil, x: nil) ⇒ Object



106
107
108
# File 'lib/rfd/windows.rb', line 106

def pane_index_at(y: nil, x: nil)
  (y >= begy) && (begy + maxy > y) && (x / width)
end

#toggle_mark(item) ⇒ Object



134
135
136
# File 'lib/rfd/windows.rb', line 134

def toggle_mark(item)
  item.toggle_mark
end

#widthObject



110
111
112
# File 'lib/rfd/windows.rb', line 110

def width
  (Curses.cols - 2) / @number_of_panes
end