Module: Fontist::Import::ImportDisplay

Defined in:
lib/fontist/import/import_display.rb

Overview

Unified progress display for all import commands

Provides consistent, professional Paint-colored output with emojis across Google, SIL, and macOS importers.

Class Method Summary collapse

Class Method Details

.debug_info(message) ⇒ Object

Display debug/info message in gray bold (like macOS import)

Parameters:

  • message (String)

    Debug message



144
145
146
# File 'lib/fontist/import/import_display.rb', line 144

def self.debug_info(message)
  Fontist.ui.say("    #{Paint[message, :black, :bright]}")
end

.download_url(url) ⇒ Object

Display download URL

Parameters:

  • url (String)

    Download URL



158
159
160
161
# File 'lib/fontist/import/import_display.rb', line 158

def self.download_url(url)
  Fontist.ui.say("  #{Paint['📥',
                            :green]} Download URL: #{Paint[url, :white]}")
end

.error(message) ⇒ Object

Display error message

Parameters:

  • message (String)

    Error message



130
131
132
# File 'lib/fontist/import/import_display.rb', line 130

def self.error(message)
  Fontist.ui.error("#{message}")
end

Display “Following link…” message

Parameters:

  • text (String)

    Link description



166
167
168
# File 'lib/fontist/import/import_display.rb', line 166

def self.following_link(text)
  debug_info("Following #{text}...")
end

.format_duration(seconds) ⇒ String

Format duration in human-readable format

Parameters:

  • seconds (Float)

    Duration in seconds

Returns:

  • (String)

    Formatted duration



182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/fontist/import/import_display.rb', line 182

def self.format_duration(seconds)
  return "#{seconds.round(2)}s" if seconds < 60

  minutes = (seconds / 60).floor
  remaining = (seconds % 60).round(2)

  if minutes < 60
    "#{minutes}m #{remaining}s"
  else
    hours = (minutes / 60).floor
    remaining_minutes = minutes % 60
    "#{hours}h #{remaining_minutes}m #{remaining.round}s"
  end
end

.found_elements(count, selector) ⇒ Object

Display “Found N elements” message

Parameters:

  • count (Integer)

    Number of elements

  • selector (String)

    CSS selector name



174
175
176
# File 'lib/fontist/import/import_display.rb', line 174

def self.found_elements(count, selector)
  debug_info("Found #{count} '#{selector}' elements") if count.positive?
end

.header(source, details = {}, import_cache: nil) ⇒ Object

Display import header with Paint styling

Parameters:

  • source (String)

    Import source name (e.g., “Google Fonts”, “SIL International”)

  • details (Hash) (defaults to: {})

    Details to display (e.g., “…”, font_filter: “…”)

  • import_cache (String, Pathname) (defaults to: nil)

    Import cache location (optional)



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fontist/import/import_display.rb', line 15

def self.header(source, details = {}, import_cache: nil)
  Fontist.ui.say("")
  Fontist.ui.say(Paint["" * 80, :cyan])
  Fontist.ui.say(Paint["  📦 #{source} Import", :cyan, :bright])
  Fontist.ui.say(Paint["" * 80, :cyan])
  Fontist.ui.say("")

  # Show import cache if provided
  if import_cache
    cache_path = import_cache.is_a?(Pathname) ? import_cache.to_s : import_cache.to_s
    Fontist.ui.say("📦 Import cache: #{Paint[cache_path, :white]}")
  end

  # Show other details
  details.each do |key, value|
    next unless value

    label = key.to_s.split("_").map(&:capitalize).join(" ")
    Fontist.ui.say("📁 #{label}: #{Paint[value.to_s, :white]}")
  end

  Fontist.ui.say("")
end

.info(message) ⇒ Object

Display info message

Parameters:

  • message (String)

    Info message



123
124
125
# File 'lib/fontist/import/import_display.rb', line 123

def self.info(message)
  Fontist.ui.say("  ℹ️  #{message}")
end

.page_url(url) ⇒ Object

Display page URL being visited

Parameters:

  • url (String)

    Page URL



151
152
153
# File 'lib/fontist/import/import_display.rb', line 151

def self.page_url(url)
  Fontist.ui.say("  #{Paint['🔗', :blue]} Page URL: #{Paint[url, :white]}")
end

.progress(current, total, item, details: nil) ⇒ Object

Display progress update with Paint styling

Parameters:

  • current (Integer)

    Current count

  • total (Integer)

    Total count

  • item (String)

    Item being processed

  • details (String) (defaults to: nil)

    Optional details (e.g., “(3 fonts)”)



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fontist/import/import_display.rb', line 45

def self.progress(current, total, item, details: nil)
  progress_text = "(#{current}/#{total})"
  percentage = ((current.to_f / total) * 100).round(1)

  line = "#{Paint[progress_text, :white]} " \
         "#{Paint["#{percentage}%", :yellow]} | " \
         "#{Paint[item, :cyan, :bright]}"

  line += " #{Paint[details, :black, :bright]}" if details

  Fontist.ui.say(line)
end

.section(title) ⇒ Object

Display section header

Parameters:

  • title (String)

    Section title (deprecated - use header instead)



114
115
116
117
118
# File 'lib/fontist/import/import_display.rb', line 114

def self.section(title)
  Fontist.ui.say("")
  Fontist.ui.say("── #{title} " + "" * (76 - title.length))
  Fontist.ui.say("")
end

.status_failed(message) ⇒ Object

Display failure status

Parameters:

  • message (String)

    Error message



86
87
88
89
90
# File 'lib/fontist/import/import_display.rb', line 86

def self.status_failed(message)
  error_display = message.length > 60 ? "#{message[0..60]}..." : message
  Fontist.ui.say("  #{Paint['',
                            :red]} Failed: #{Paint[error_display, :red]}")
end

.status_overwrite(message) ⇒ Object

Display overwrite warning

Parameters:

  • message (String)

    Warning message



95
96
97
# File 'lib/fontist/import/import_display.rb', line 95

def self.status_overwrite(message)
  Fontist.ui.say("  #{Paint['', :yellow]} #{message}")
end

.status_skipped(message, tip: nil) ⇒ Object

Display skip status

Parameters:

  • message (String)

    Skip message

  • tip (String) (defaults to: nil)

    Optional tip for user



78
79
80
81
# File 'lib/fontist/import/import_display.rb', line 78

def self.status_skipped(message, tip: nil)
  Fontist.ui.say("  #{Paint['', :yellow]} #{message}")
  Fontist.ui.say("    #{Paint['', :blue]} #{tip}") if tip
end

.status_success(message, details = "") ⇒ Object

Display success status

Parameters:

  • message (String)

    Success message

  • details (String) (defaults to: "")

    Optional details (e.g., formula name, timing)



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/fontist/import/import_display.rb', line 62

def self.status_success(message, details = "")
  detail_text = if details.empty?
                  ""
                else
                  " #{Paint[details, :black,
                            :bright]}"
                end
  Fontist.ui.say("  #{Paint['',
                            :green]} #{Paint[message,
                                             :white]}#{detail_text}")
end

.summary(results, options = {}) ⇒ Object

Display summary with Paint styling

Parameters:

  • results (Hash)

    Results hash with :successful, :failed, :duration keys

  • options (Hash) (defaults to: {})

    Display options (:force, :show_tips, etc.)



103
104
105
106
107
108
109
# File 'lib/fontist/import/import_display.rb', line 103

def self.summary(results, options = {})
  print_summary_header
  print_summary_stats(results)
  print_summary_errors(results) if results[:errors]&.any?
  print_summary_tips(results, options)
  print_summary_footer(results)
end

.warn(message) ⇒ Object

Display warning message

Parameters:

  • message (String)

    Warning message



137
138
139
# File 'lib/fontist/import/import_display.rb', line 137

def self.warn(message)
  Fontist.ui.say("  ⚠️  #{message}")
end