Module: CLI::UI::ProgressReporter

Defined in:
lib/cli/ui/progress_reporter.rb

Overview

Handles terminal progress bar reporting using ConEmu OSC 9;4 sequences Supports:

  • Numerical progress (0-100%)

  • Indeterminate/pulsing progress

  • Success/error states

  • Paused state

Defined Under Namespace

Classes: Reporter

Class Method Summary collapse

Class Method Details

.current_reporterObject

: -> Reporter?



165
166
167
# File 'lib/cli/ui/progress_reporter.rb', line 165

def current_reporter
  reporter_stack.last
end

.reporter_stackObject

Thread-local storage for the current reporter stack : -> Array



160
161
162
# File 'lib/cli/ui/progress_reporter.rb', line 160

def reporter_stack
  Thread.current[:progress_reporter_stack] ||= []
end

.supports_progress?Boolean

: -> bool

Returns:

  • (Boolean)


183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/cli/ui/progress_reporter.rb', line 183

def supports_progress?
  # Check if terminal supports ConEmu OSC sequences
  # This is supported by:
  # - ConEmu on Windows
  # - Windows Terminal
  # - Ghostty
  # - Various terminals on Linux (with OSC 9;4 support)

  # Check common environment variables that indicate support
  return true if ENV['ConEmuPID']
  return true if ENV['WT_SESSION'] # Windows Terminal
  return true if ENV['GHOSTTY_RESOURCES_DIR'] # Ghostty

  # Check TERM_PROGRAM for known supporting terminals
  term_program = ENV['TERM_PROGRAM']
  return true if term_program == 'ghostty'

  # For now, we'll be conservative and only enable for known terminals
  # Users can force-enable with an environment variable
  return true if ENV['CLI_UI_ENABLE_PROGRESS'] == '1'

  false
end

.with_progress(mode: :indeterminate, to: $stdout, delay_start: false, &block) ⇒ Object

Block-based API that ensures progress is cleared : [T] (?mode: Symbol, ?to: io_like, ?delay_start: bool) { (Reporter reporter) -> T } -> T



171
172
173
174
175
176
177
178
179
180
# File 'lib/cli/ui/progress_reporter.rb', line 171

def with_progress(mode: :indeterminate, to: $stdout, delay_start: false, &block)
  parent = current_reporter
  reporter = Reporter.new(mode, to, parent: parent, delay_start: delay_start)

  reporter_stack.push(reporter)
  yield(reporter)
ensure
  reporter_stack.pop
  reporter&.cleanup
end