Class: Themigrator::UI::LogArea::LogWindow

Inherits:
Window
  • Object
show all
Defined in:
lib/themigrator/ui/log_area.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(height, width, top, left) ⇒ LogWindow

Returns a new instance of LogWindow.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/themigrator/ui/log_area.rb', line 11

def initialize(height, width, top, left)
  @height = height
  @width = width
  @top = top
  @left = left
  @inner_win = ::Curses::Window.new(height - 2, width - 2, top + 1, left + 1)
  @inner_win.scrollok(true)
  @buffer = ''
  @scroll = -1
  super
  idlok(true)
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



10
11
12
# File 'lib/themigrator/ui/log_area.rb', line 10

def action
  @action
end

#roleObject

Returns the value of attribute role.



10
11
12
# File 'lib/themigrator/ui/log_area.rb', line 10

def role
  @role
end

Instance Method Details

#append(msg) ⇒ Object



55
56
57
# File 'lib/themigrator/ui/log_area.rb', line 55

def append(msg)
  @buffer << msg
end

#log(msg) ⇒ Object



64
65
66
# File 'lib/themigrator/ui/log_area.rb', line 64

def log(msg)
  ui_log("#{name}##{msg}")
end

#nameObject



51
52
53
# File 'lib/themigrator/ui/log_area.rb', line 51

def name
  '%-13s/%-10s' % [action, role]
end

#nextpageObject



35
36
37
38
39
# File 'lib/themigrator/ui/log_area.rb', line 35

def nextpage
  @scroll += 5
  @scroll = -1 if @scroll > -1
  log("@scroll = #{@scroll}")
end

#prevpageObject



41
42
43
44
45
46
47
48
49
# File 'lib/themigrator/ui/log_area.rb', line 41

def prevpage
  @scroll -= 5
  buffer_lines = @buffer.split("\n").size
  offset_lines = buffer_lines - @height + (2 + 5)

  log("@scroll = #{@scroll} and offset_lines - #{offset_lines} | buffer_lines #{buffer_lines} | @height = #{@height}")
  @height
  @scroll = -offset_lines if @scroll < -offset_lines
end

#redrawObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/themigrator/ui/log_area.rb', line 24

def redraw
  clear
  @inner_win.clear
  setpos(0, 0)
  box('|', '-')
  addstr(name)
  log('redraw')
  refresh
  render(true)
end

#render(force = false) ⇒ Object



59
60
61
62
# File 'lib/themigrator/ui/log_area.rb', line 59

def render(force = false)
  # refresh
  render_inner_win(force)
end