Module: Howzit::RunReport

Defined in:
lib/howzit/run_report.rb

Overview

Formatter for task run summaries

Class Method Summary collapse

Class Method Details

.entriesObject



17
18
19
# File 'lib/howzit/run_report.rb', line 17

def entries
  Howzit.run_log || []
end

.formatObject



21
22
23
24
25
26
27
# File 'lib/howzit/run_report.rb', line 21

def format
  return '' if entries.empty?

  lines = entries.map { |entry| format_line(entry, Howzit.multi_topic_run) }
  output_lines = ["\n\n***\n"] + lines
  output_lines.join("\n")
end

.format_as_tableObject

Table formatting methods kept for possible future use



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/howzit/run_report.rb', line 48

def format_as_table
  return '' if entries.empty?

  rows = entries.map { |entry| format_row(entry, Howzit.multi_topic_run) }

  # Status column width: " :--: " = 6 chars (4 for :--: plus 1 space each side)
  # Emoji is 2-width in terminal, so we need 2 spaces on each side to center it
  status_width = 6
  task_width = [4, rows.map { |r| r[:task_plain].length }.max].max

  # Build the table with emoji header - center emoji in 6-char column
  header = "|  🚥  | #{'Task'.ljust(task_width)} |"
  separator = "| :--: | #{':' + '-' * (task_width - 1)} |"

  table_lines = [header, separator]
  rows.each do |row|
    table_lines << table_row_colored(row[:status], row[:task], row[:task_plain], status_width, task_width)
  end

  table_lines.join("\n")
end

.format_line(entry, prefix_topic) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/howzit/run_report.rb', line 29

def format_line(entry, prefix_topic)
  symbol = entry[:success] ? '✅' : '❌'
  parts = ["#{symbol} "]
  if prefix_topic && entry[:topic] && !entry[:topic].empty?
    # Escape braces in topic name to prevent color code interpretation
    topic_escaped = entry[:topic].gsub(/\{/, '\\{').gsub(/\}/, '\\}')
    parts << "{bw}#{topic_escaped}{x}: "
  end
  # Escape braces in task name to prevent color code interpretation
  task_escaped = entry[:task].gsub(/\{/, '\\{').gsub(/\}/, '\\}')
  parts << "{by}#{task_escaped}{x}"
  unless entry[:success]
    reason = entry[:exit_status] ? "exit code #{entry[:exit_status]}" : 'failed'
    parts << " {br}(#{reason}){x}"
  end
  parts.join.c
end

.format_row(entry, prefix_topic) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/howzit/run_report.rb', line 76

def format_row(entry, prefix_topic)
  # Use plain emoji without color codes - the emoji itself provides visual meaning
  # and complex ANSI codes interfere with mdless table rendering
  symbol = entry[:success] ? '✅' : '❌'

  task_parts = []
  task_parts_plain = []

  if prefix_topic && entry[:topic] && !entry[:topic].empty?
    # Escape braces in topic name to prevent color code interpretation
    topic_escaped = entry[:topic].gsub(/\{/, '\\{').gsub(/\}/, '\\}')
    task_parts << "{bw}#{topic_escaped}{x}: "
    task_parts_plain << "#{entry[:topic]}: "
  end

  # Escape braces in task name to prevent color code interpretation
  task_escaped = entry[:task].gsub(/\{/, '\\{').gsub(/\}/, '\\}')
  task_parts << "{by}#{task_escaped}{x}"
  task_parts_plain << entry[:task]

  unless entry[:success]
    reason = entry[:exit_status] ? "exit code #{entry[:exit_status]}" : 'failed'
    task_parts << " {br}(#{reason}){x}"
    task_parts_plain << " (#{reason})"
  end

  {
    status: symbol,
    status_plain: symbol,
    task: task_parts.join.c,
    task_plain: task_parts_plain.join
  }
end

.log(entry) ⇒ Object



12
13
14
15
# File 'lib/howzit/run_report.rb', line 12

def log(entry)
  Howzit.run_log = [] if Howzit.run_log.nil?
  Howzit.run_log << entry
end

.resetObject



8
9
10
# File 'lib/howzit/run_report.rb', line 8

def reset
  Howzit.run_log = []
end

.table_row_colored(status, task, task_plain, _status_width, task_width) ⇒ Object



70
71
72
73
74
# File 'lib/howzit/run_report.rb', line 70

def table_row_colored(status, task, task_plain, _status_width, task_width)
  task_padding = task_width - task_plain.length

  "|  #{status}  | #{task}#{' ' * task_padding} |"
end