Class: PM::PmWindow

Inherits:
SimpleDelegator
  • Object
show all
Includes:
Curses
Defined in:
lib/patchmaster/curses/pm_window.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rows, cols, row, col, title_prefix) ⇒ PmWindow

If title is nil then list’s name will be used



13
14
15
16
17
18
# File 'lib/patchmaster/curses/pm_window.rb', line 13

def initialize(rows, cols, row, col, title_prefix)
  @win = Window.new(rows, cols, row, col)
  super(@win)
  @title_prefix = title_prefix
  set_max_contents_len(cols)
end

Instance Attribute Details

#titleObject

Returns the value of attribute title.



10
11
12
# File 'lib/patchmaster/curses/pm_window.rb', line 10

def title
  @title
end

#title_prefixObject (readonly)

Returns the value of attribute title_prefix.



9
10
11
# File 'lib/patchmaster/curses/pm_window.rb', line 9

def title_prefix
  @title_prefix
end

#winObject (readonly)

Returns the value of attribute win.



9
10
11
# File 'lib/patchmaster/curses/pm_window.rb', line 9

def win
  @win
end

Instance Method Details

#drawObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/patchmaster/curses/pm_window.rb', line 26

def draw
  @win.clear
  @win.box(?|, ?-)
  return unless @title_prefix || @title

  @win.setpos(0, 1)
  @win.attron(A_REVERSE) {
    @win.addch(' ')
    @win.addstr("#{@title_prefix}: ") if @title_prefix
    @win.addstr(@title) if @title
    @win.addch(' ')
  }
end

#make_fit(str) ⇒ Object



49
50
51
52
# File 'lib/patchmaster/curses/pm_window.rb', line 49

def make_fit(str)
  str = str[0..@max_contents_len] if str.length > @max_contents_len
  str
end

#move_and_resize(rect) ⇒ Object



20
21
22
23
24
# File 'lib/patchmaster/curses/pm_window.rb', line 20

def move_and_resize(rect)
  @win.move(rect[2], rect[3])
  @win.resize(rect[0], rect[1])
  set_max_contents_len(rect[1])
end

#set_max_contents_len(cols) ⇒ Object



45
46
47
# File 'lib/patchmaster/curses/pm_window.rb', line 45

def set_max_contents_len(cols)
  @max_contents_len = cols - 3 # 2 for borders
end

#visible_heightObject

Visible height is height of window minus 2 for the borders.



41
42
43
# File 'lib/patchmaster/curses/pm_window.rb', line 41

def visible_height
  @win.maxy - 2
end