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, draw_ncursesw_border, ncursesw?, #writeln

Constructor Details

#initializeMainWindow

Returns a new instance of MainWindow.



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

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.



112
113
114
# File 'lib/rfd/windows.rb', line 112

def begy
  @begy
end

#current_indexObject (readonly)

Returns the value of attribute current_index.



112
113
114
# File 'lib/rfd/windows.rb', line 112

def current_index
  @current_index
end

#number_of_panesObject

Returns the value of attribute number_of_panes.



112
113
114
# File 'lib/rfd/windows.rb', line 112

def number_of_panes
  @number_of_panes
end

Instance Method Details

#activate_pane(num) ⇒ Object



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

def activate_pane(num)
  @current_index = num
end

#display(page) ⇒ Object



129
130
131
# File 'lib/rfd/windows.rb', line 129

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

#draw_item(item, current: false) ⇒ Object



149
150
151
152
153
154
# File 'lib/rfd/windows.rb', line 149

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



156
157
158
159
160
161
162
163
# File 'lib/rfd/windows.rb', line 156

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



145
146
147
# File 'lib/rfd/windows.rb', line 145

def max_items
  maxy * @number_of_panes
end

#newpad(items) ⇒ Object



120
121
122
123
124
125
126
127
# File 'lib/rfd/windows.rb', line 120

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



137
138
139
# File 'lib/rfd/windows.rb', line 137

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

#toggle_mark(item) ⇒ Object



165
166
167
# File 'lib/rfd/windows.rb', line 165

def toggle_mark(item)
  item.toggle_mark
end

#widthObject



141
142
143
# File 'lib/rfd/windows.rb', line 141

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