Class: Rfd::MainWindow

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

Defined Under Namespace

Classes: Panes

Constant Summary

Constants inherited from Window

Window::ACS_BTEE, Window::ACS_HLINE, Window::ACS_LLCORNER, Window::ACS_LRCORNER, Window::ACS_LTEE, Window::ACS_RTEE, Window::ACS_TTEE, Window::ACS_ULCORNER, Window::ACS_URCORNER, Window::ACS_VLINE

Instance Method Summary collapse

Methods inherited from Window

#begx, #begy, draw_borders, #maxx, #maxy, #waddstr, #wclear, #wmove, #wrefresh

Constructor Details

#initialize(dir = '.') ⇒ MainWindow

Returns a new instance of MainWindow.



176
177
178
# File 'lib/rfd/windows.rb', line 176

def initialize(dir = '.')
  spawn_panes 2
end

Instance Method Details

#activate_pane(num) ⇒ Object



188
189
190
# File 'lib/rfd/windows.rb', line 188

def activate_pane(num)
  @panes.activate num
end

#draw_item(item, current: false) ⇒ Object



204
205
206
207
208
209
210
# File 'lib/rfd/windows.rb', line 204

def draw_item(item, current: false)
  window.setpos item.index % maxy, 0
  window.attron(Curses.color_pair(item.color) | (current ? Curses::A_UNDERLINE : Curses::A_NORMAL)) do
    window.addstr "#{item.to_s}\n"
  end
  wrefresh
end

#draw_items_to_each_pane(items) ⇒ Object



212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/rfd/windows.rb', line 212

def draw_items_to_each_pane(items)
  original_active_pane_index = @panes.current_index

  0.upto(@panes.size - 1) do |index|
    activate_pane index
    wclear
    wmove 0
    items[maxy * index, maxy * (index + 1)].each do |item|
      window.attron(Curses.color_pair(item.color) | Curses::A_NORMAL) { waddstr "#{item.to_s}\n" }
    end if items[maxy * index, maxy * (index + 1)]
    wrefresh
  end
  activate_pane original_active_pane_index
end

#max_itemsObject



200
201
202
# File 'lib/rfd/windows.rb', line 200

def max_items
  maxy * @panes.size
end

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



192
193
194
# File 'lib/rfd/windows.rb', line 192

def pane_index_at(y: nil, x: nil)
  @panes.get_index_by_point y: y, x: x
end

#spawn_panes(num) ⇒ Object



180
181
182
183
184
185
186
# File 'lib/rfd/windows.rb', line 180

def spawn_panes(num)
  @panes.close_all if defined? @panes
  width = (Curses.cols - 2) / num
  windows = 0.upto(num - 1).inject([]) {|arr, i| arr << Curses.stdscr.subwin(Curses.lines - 7, width - 1, 5, width * i + 1)}
  @panes = Panes.new windows
  activate_pane 0
end

#toggle_mark(item) ⇒ Object



227
228
229
230
231
232
# File 'lib/rfd/windows.rb', line 227

def toggle_mark(item)
  if item.toggle_mark
    window.setpos item.index % maxy, 0
    window.addstr item.current_mark
  end
end

#windowObject



196
197
198
# File 'lib/rfd/windows.rb', line 196

def window
  @panes.active
end