Class: Dcha::UI::Window

Inherits:
Curses::Window
  • Object
show all
Defined in:
lib/dcha/ui/window.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializeWindow

Returns a new instance of Window.



5
6
7
8
9
10
# File 'lib/dcha/ui/window.rb', line 5

def initialize(*)
  super

  @sidebar = subwin(maxy - 2, maxx * 0.3, 0, 0)
  @input = subwin(3, 0, maxy - 3, 0)
end

Instance Method Details

#heading=(head) ⇒ Object



21
22
23
24
# File 'lib/dcha/ui/window.rb', line 21

def heading=(head)
  @input.setpos(1, 1)
  @input.addstr(head)
end

#peers=(peers) ⇒ Object

TODO: Cut off string if overflow



27
28
29
30
31
32
33
34
# File 'lib/dcha/ui/window.rb', line 27

def peers=(peers)
  peers = peers.take(maxy - 5)
  peers.push('And more ...') if peers.size == maxy - 5
  peers.each.with_index do |peer, index|
    @sidebar.setpos(index + 1, 2)
    @sidebar.addstr(peer)
  end
end

#update(&_block) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/dcha/ui/window.rb', line 12

def update(&_block)
  clear
  update_sidebar
  box('|', '-')
  update_input
  yield if block_given?
  refresh
end