Method: Blufin::Terminal.execute_proc
- Defined in:
- lib/core/terminal.rb
.execute_proc(title, proc, verbose: true) ⇒ Object
Same as above but with a proc/lambda instead of a terminal command.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/core/terminal.rb', line 118 def self.execute_proc(title, proc, verbose: true) raise RuntimeError, "Expected String, instead got:#{title.class}" unless title.is_a?(String) raise RuntimeError, "Expected proc to be an instance of Proc, instead got: #{proc.class}" unless proc.is_a?(Proc) t1 = Time.now spinner = nil spinner = TTY::Spinner.new("[:spinner] \x1B[38;5;208m#{title}\x1B[0m", format: :dots) if verbose spinner.auto_spin if verbose res = proc.call t2 = Time.now delta = "#{'%.3f' % (t2 - t1).abs}s" spinner.success("\x1B[38;5;246m\xe2\x86\x92 \x1B[38;5;46mComplete \x1B[38;5;240m(#{delta})\x1B[0m\x1B[0m") if verbose && res spinner.error("\x1B[38;5;246m\xe2\x86\x92 \x1B[38;5;196mFailed (#{delta})\x1B[0m") if verbose && !res res end |