class Bosh::Cli::InteractiveProgressRenderer

Public Class Methods

new() click to toggle source
# File lib/cli/interactive_progress_renderer.rb, line 3
def initialize
  @mutex = Mutex.new
  @indices = {}
end

Public Instance Methods

error(path, message) click to toggle source
# File lib/cli/interactive_progress_renderer.rb, line 16
def error(path, message)
  render(path, message.make_red)
end
finish(path, label) click to toggle source
# File lib/cli/interactive_progress_renderer.rb, line 20
def finish(path, label)
  render(path, label.make_green)
end
progress(path, label, percent) click to toggle source
# File lib/cli/interactive_progress_renderer.rb, line 12
def progress(path, label, percent)
  render(path, "#{label} (#{percent}%)")
end
start(path, label) click to toggle source
# File lib/cli/interactive_progress_renderer.rb, line 8
def start(path, label)
  render(path, label)
end

Private Instance Methods

clear_line() click to toggle source
# File lib/cli/interactive_progress_renderer.rb, line 66
def clear_line
  say("\033[K", "")
end
render(path, label) click to toggle source
# File lib/cli/interactive_progress_renderer.rb, line 26
def render(path, label)
  @mutex.synchronize do
    truncated_path = path.truncate(40)
    truncated_path_length = truncated_path.length + 1

    if !@indices.has_key?(path)
      say(truncated_path.make_yellow, " \n")
    end

    @indices[path] ||= @indices.count

    save_cursor_position
    up(@indices.count - @indices[path])

    right(truncated_path_length)
    clear_line

    say(label, "")

    restore_cursor_position
    Bosh::Cli::Config.output.flush # Ruby 1.8 compatibility
  end
end
restore_cursor_position() click to toggle source
# File lib/cli/interactive_progress_renderer.rb, line 54
def restore_cursor_position
  say("\033[u", "")
end
right(count = 1) click to toggle source
# File lib/cli/interactive_progress_renderer.rb, line 62
def right(count = 1)
  say("\033[#{count}C", "")
end
save_cursor_position() click to toggle source
# File lib/cli/interactive_progress_renderer.rb, line 50
def save_cursor_position
  say("\033[s", "")
end
up(count = 1) click to toggle source
# File lib/cli/interactive_progress_renderer.rb, line 58
def up(count = 1)
  say("\033[#{count}A", "")
end