class ChefCore::CLIUX::UI::Terminal
Attributes
enable_spinners[RW]
To support matching in test
location[RW]
To support matching in test
Public Class Methods
get_multispinner()
click to toggle source
# File lib/chef_core/cliux/ui/terminal.rb, line 87 def get_multispinner enable_spinners ? TTY::Spinner::Multi : PlainTextHeader end
get_spinner()
click to toggle source
# File lib/chef_core/cliux/ui/terminal.rb, line 91 def get_spinner # TODO bootstrap - these was as below, which seems backwards: enable_spinners ? TTY::Spinner : PlainTextElement end
init(location, enable_spinners: false)
click to toggle source
# File lib/chef_core/cliux/ui/terminal.rb, line 34 def init(location, enable_spinners: false) @enable_spinners = enable_spinners @location = location end
output(msg)
click to toggle source
# File lib/chef_core/cliux/ui/terminal.rb, line 43 def output(msg) @location.puts msg end
render_job(initial_msg, job)
click to toggle source
# File lib/chef_core/cliux/ui/terminal.rb, line 72 def render_job(initial_msg, job) # TODO why do we have to pass prefix to both the spinner and the reporter? spinner = get_spinner.new(spinner_prefix(job.prefix), output: @location, hide_cursor: true) reporter = StatusReporter.new(spinner, prefix: job.prefix, key: :status) reporter.update(initial_msg) spinner.auto_spin job.run(reporter) end
render_parallel_jobs(header, jobs)
click to toggle source
# File lib/chef_core/cliux/ui/terminal.rb, line 47 def render_parallel_jobs(header, jobs) # Do not indent the topmost 'parent' spinner, but do indent child spinners indent_style = { top: "", middle: TTY::Spinner::Multi::DEFAULT_INSET[:middle], bottom: TTY::Spinner::Multi::DEFAULT_INSET[:bottom] } # @option options [Hash] :style # keys :top :middle and :bottom can contain Strings that are used to # indent the spinners. Ignored if message is blank multispinner = get_multispinner.new("[:spinner] #{header}", output: @location, hide_cursor: true, style: indent_style) jobs.each do |job| multispinner.register(spinner_prefix(job.prefix), hide_cursor: true) do |spinner| reporter = StatusReporter.new(spinner, prefix: job.prefix, key: :status) job.run(reporter) end end multispinner.auto_spin ensure # Spinners hide the cursor for better appearance, so we need to make sure # we always bring it back show_cursor end
show_cursor()
click to toggle source
# File lib/chef_core/cliux/ui/terminal.rb, line 96 def show_cursor TTY::Cursor.show end
spinner_prefix(prefix)
click to toggle source
# File lib/chef_core/cliux/ui/terminal.rb, line 81 def spinner_prefix(prefix) spinner_msg = "[:spinner] " spinner_msg += ":prefix " unless prefix.empty? spinner_msg + ":status" end
write(msg)
click to toggle source
# File lib/chef_core/cliux/ui/terminal.rb, line 39 def write(msg) @location.write(msg) end