Module: EndOfLife::TerminalHelper

Included in:
EndOfLife, CLI
Defined in:
lib/end_of_life/terminal_helper.rb

Instance Method Summary collapse

Instance Method Details

#error_msg(message, label: "[ERROR]") ⇒ Object



7
8
9
10
11
# File 'lib/end_of_life/terminal_helper.rb', line 7

def error_msg(message, label: "[ERROR]")
  label = paint.red("#{label} ")

  "#{label} #{message}"
end

#new_spinner(message, options = {success_mark: paint.green("✔"), error_mark: paint.red("✖")}) ⇒ Object



32
33
34
# File 'lib/end_of_life/terminal_helper.rb', line 32

def new_spinner(message, options = {success_mark: paint.green(""), error_mark: paint.red("")})
  TTY::Spinner.new("[:spinner] #{message}", options)
end

#paintObject



28
29
30
# File 'lib/end_of_life/terminal_helper.rb', line 28

def paint
  @paint ||= Pastel.new
end

#tableObject



24
25
26
# File 'lib/end_of_life/terminal_helper.rb', line 24

def table(...)
  TTY::Table.new(...).render(:unicode, padding: [0, 1])
end

#with_loading_spinner(message) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/end_of_life/terminal_helper.rb', line 13

def with_loading_spinner(message)
  result = nil

  new_spinner(message).run do |spinner|
    result = yield(spinner)
    spinner.success
  end

  result
end