Class: ChefCore::CLIUX::UI::Terminal
- Inherits:
-
Object
- Object
- ChefCore::CLIUX::UI::Terminal
- Defined in:
- lib/chef_core/cliux/ui/terminal.rb,
lib/chef_core/cliux/ui/terminal/job.rb
Defined Under Namespace
Classes: Job
Class Attribute Summary collapse
-
.enable_spinners ⇒ Object
To support matching in test.
-
.location ⇒ Object
To support matching in test.
Class Method Summary collapse
- .get_multispinner ⇒ Object
- .get_spinner ⇒ Object
- .init(location, enable_spinners: false) ⇒ Object
- .output(msg) ⇒ Object
- .render_job(initial_msg, job) ⇒ Object
- .render_parallel_jobs(header, jobs) ⇒ Object
- .show_cursor ⇒ Object
- .spinner_prefix(prefix) ⇒ Object
- .write(msg) ⇒ Object
Class Attribute Details
.enable_spinners ⇒ Object
To support matching in test
32 33 34 |
# File 'lib/chef_core/cliux/ui/terminal.rb', line 32 def enable_spinners @enable_spinners end |
.location ⇒ Object
To support matching in test
32 33 34 |
# File 'lib/chef_core/cliux/ui/terminal.rb', line 32 def location @location end |
Class Method Details
.get_multispinner ⇒ Object
87 88 89 |
# File 'lib/chef_core/cliux/ui/terminal.rb', line 87 def get_multispinner enable_spinners ? TTY::Spinner::Multi : PlainTextHeader end |
.get_spinner ⇒ Object
91 92 93 94 |
# 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) ⇒ Object
34 35 36 37 |
# 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) ⇒ Object
43 44 45 |
# File 'lib/chef_core/cliux/ui/terminal.rb', line 43 def output(msg) @location.puts msg end |
.render_job(initial_msg, job) ⇒ Object
72 73 74 75 76 77 78 79 |
# 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) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# 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 ⇒ Object
96 97 98 |
# File 'lib/chef_core/cliux/ui/terminal.rb', line 96 def show_cursor TTY::Cursor.show end |
.spinner_prefix(prefix) ⇒ Object
81 82 83 84 85 |
# 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) ⇒ Object
39 40 41 |
# File 'lib/chef_core/cliux/ui/terminal.rb', line 39 def write(msg) @location.write(msg) end |