Module: Deploio::Output

Defined in:
lib/deploio/output.rb

Class Method Summary collapse

Class Method Details

.color_enabledObject



10
11
12
13
14
# File 'lib/deploio/output.rb', line 10

def color_enabled
  return @color_enabled if defined?(@color_enabled)

  @color_enabled = $stdout.tty?
end

.color_enabled=(value) ⇒ Object



16
17
18
19
# File 'lib/deploio/output.rb', line 16

def color_enabled=(value)
  @color_enabled = value
  @pastel = nil
end

.command(cmd) ⇒ Object



37
38
39
# File 'lib/deploio/output.rb', line 37

def command(cmd)
  puts pastel.bold("> #{cmd}")
end

.error(message) ⇒ Object



25
26
27
# File 'lib/deploio/output.rb', line 25

def error(message)
  warn pastel.red("#{message}")
end

.grouped_table(groups, headers: nil) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/deploio/output.rb', line 65

def grouped_table(groups, headers: nil)
  return if groups.empty?

  all_rows = groups.values.flatten(1)
  return if all_rows.empty?

  # Track which row indices should have separators after them (0-indexed)
  # The separator lambda receives the row index (0 = first data row)
  separator_after = []
  current_idx = 0
  groups.each_with_index do |(_, group_rows), group_idx|
    current_idx += group_rows.size
    # Add separator after last row of each group (except the last group)
    separator_after << (current_idx - 1) if group_idx < groups.size - 1
  end

  rows = groups.values.flatten(1)
  tty_table = headers ? TTY::Table.new(header: headers, rows: rows) : TTY::Table.new(rows: rows)

  output = tty_table.render(:unicode, padding: [0, 2, 0, 1], width: 10_000) do |renderer|
    # row_idx 0 = separator after header, then data row indices
    renderer.border.separator = ->(row_idx) { row_idx == 0 || separator_after.include?(row_idx - 1) }
  end

  puts output
end

.header(text) ⇒ Object



41
42
43
# File 'lib/deploio/output.rb', line 41

def header(text)
  puts pastel.magenta.bold(text)
end

.info(message) ⇒ Object



33
34
35
# File 'lib/deploio/output.rb', line 33

def info(message)
  puts pastel.cyan("#{message}")
end

Create a clickable hyperlink using OSC 8 escape sequences Supported by most modern terminal emulators (iTerm2, GNOME Terminal, Windows Terminal, etc.)



47
48
49
50
51
52
# File 'lib/deploio/output.rb', line 47

def link(text, url = nil)
  return text unless color_enabled

  url ||= text.start_with?("http") ? text : "https://#{text}"
  "\e]8;;#{url}\e\\#{text}\e]8;;\e\\"
end

.list(items) ⇒ Object



61
62
63
# File 'lib/deploio/output.rb', line 61

def list(items)
  items.each { |item| puts "#{item}" }
end

.success(message) ⇒ Object



21
22
23
# File 'lib/deploio/output.rb', line 21

def success(message)
  puts pastel.green("#{message}")
end

.table(rows, headers: nil) ⇒ Object



54
55
56
57
58
59
# File 'lib/deploio/output.rb', line 54

def table(rows, headers: nil)
  return if rows.empty?

  tty_table = headers ? TTY::Table.new(header: headers, rows: rows) : TTY::Table.new(rows: rows)
  puts tty_table.render(:unicode, padding: [0, 2, 0, 1], width: 10_000)
end

.warning(message) ⇒ Object



29
30
31
# File 'lib/deploio/output.rb', line 29

def warning(message)
  puts pastel.yellow("! #{message}")
end