Module: Nvoi::Cli::Onboard::Ui

Included in:
Command, Steps::App, Steps::AppName, Steps::Compute, Steps::Database, Steps::Domain, Steps::Env
Defined in:
lib/nvoi/cli/onboard/ui.rb

Overview

Shared UI helpers for onboard steps

Constant Summary collapse

MAX_RETRIES =
3

Instance Method Summary collapse

Instance Method Details

#box(text) ⇒ Object



67
68
69
70
# File 'lib/nvoi/cli/onboard/ui.rb', line 67

def box(text)
  output.puts TTY::Box.frame(text, padding: [0, 2], align: :center, border: :light)
  output.puts
end

#error(msg) ⇒ Object



24
25
26
# File 'lib/nvoi/cli/onboard/ui.rb', line 24

def error(msg)
  output.puts "#{pastel.red("✗")} #{msg}"
end

#outputObject



72
73
74
# File 'lib/nvoi/cli/onboard/ui.rb', line 72

def output
  @prompt.output
end

#prompt_with_retry(message, mask: false, max: MAX_RETRIES) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/nvoi/cli/onboard/ui.rb', line 43

def prompt_with_retry(message, mask: false, max: MAX_RETRIES)
  retries = 0
  loop do
    value = mask ? @prompt.mask(message) : @prompt.ask(message) { |q| q.required true }
    begin
      yield(value) if block_given?
      return value
    rescue Errors::ValidationError, Errors::AuthenticationError => e
      retries += 1
      if retries >= max
        error("Failed after #{max} attempts: #{e.message}")
        raise
      end
      output.puts("#{e.message}. Please try again. (#{retries}/#{max})")
    end
  end
end

#section(title) ⇒ Object



15
16
17
18
# File 'lib/nvoi/cli/onboard/ui.rb', line 15

def section(title)
  output.puts
  output.puts pastel.bold("─── #{title} ───")
end

#success(msg) ⇒ Object



20
21
22
# File 'lib/nvoi/cli/onboard/ui.rb', line 20

def success(msg)
  output.puts "#{pastel.green("✓")} #{msg}"
end

#table(rows:, header: nil) ⇒ Object



61
62
63
64
65
# File 'lib/nvoi/cli/onboard/ui.rb', line 61

def table(rows:, header: nil)
  t = TTY::Table.new(header:, rows:)
  output.puts t.render(:unicode, padding: [0, 1])
  output.puts
end

#with_spinner(message) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/nvoi/cli/onboard/ui.rb', line 28

def with_spinner(message)
  return yield if @test_mode

  spinner = TTY::Spinner.new("[:spinner] #{message}", format: :dots)
  spinner.auto_spin
  begin
    result = yield
    spinner.success("done")
    result
  rescue StandardError => e
    spinner.error("failed")
    raise
  end
end