Module: Themigrator::UI::ProgressWindow

Includes:
Curses
Included in:
Themigrator::UI
Defined in:
lib/themigrator/progress_window.rb,
lib/themigrator/ui/progress_window.rb

Instance Method Summary collapse

Instance Method Details

#build_status_lineObject

def build_status_line

  scripts = progress_window_status
  width = scripts.map(&:size).inject(&:+)
  free_space = @cols - width
  sep_space = scripts.size - 1
  inline_space = ((free_space - sep_space) / scripts.size - 1) / 2

  action_msg = []
  scripts.map do |script|
    a = ''
    inline_space.times { a << ' ' }
    a << if defined?(@pg_action) && @pg_action.to_s == script.to_s
           script.upcase
         else
           script.downcase
         end
    inline_space.times { a << ' ' }
    action_msg << a
  end
  action_msg.join('>')
end


48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/themigrator/ui/progress_window.rb', line 48

def build_status_line
  width = @cols
  ncols = progress_window_status.size
  col_width = (width / ncols) - 1
  cols = []
  ncols.times do |i|
    cols[i] = build_status_line_column(index: i,width: col_width)
  end
  cols.join(?>)
rescue => e
  e.inspect
end

#build_status_line_column(index:, width:) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/themigrator/ui/progress_window.rb', line 61

def build_status_line_column(index:, width:)
  title = progress_window_status[index]
  title.upcase!  if title == @current_action

  padding = (width - title.size) / 2
  padding = 0 if padding < 0 
  "%#{padding}s%-#{width - padding}s" % [ "", title ]
end

#progress_windowObject



13
14
15
16
17
# File 'lib/themigrator/progress_window.rb', line 13

def progress_window
  @progress_widnow ||= Window.new(@lines - 1, @cols - 1, @lines - 1, 0).tap do |w|
    w.attrset(A_DIM)
  end
end

#render_progressObject



5
6
7
8
9
10
11
# File 'lib/themigrator/progress_window.rb', line 5

def render_progress
  progress_window.setpos(0, 0)
  progress_window.addstr(@pm.roles.inspect)
  progress_window.addstr(@pm.current_action.inspect)
  progress_window.addstr(@action)
  progress_window.refresh
end

#say(*msg) ⇒ Object



20
21
22
# File 'lib/themigrator/ui/progress_window.rb', line 20

def say(*msg)
  @pw_status = msg.map(&:to_s).join(' ')
end