Class: Everywhere::UI::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/everywhere/ui.rb

Overview

A single self-rewriting line for waits that produce no output — chiefly every platform build, which can sit for many minutes while GitHub finds a hosted macOS runner. Without it the CLI looks hung.

On a TTY it redraws in place with a spinner frame. When stdout is a pipe (CI, | tee) carriage returns would pile up, so it degrades to one plain line every HEADLESS_INTERVAL seconds. Callers MUST clear before writing anything else — update tracks whether a line is currently on screen so clear is cheap and idempotent.

NOTE: this writes to its io: directly, NOT through Console, so it is not serialized against other writers. That's fine for its one caller (every platform build, single-threaded) — do not reuse it concurrently.

Constant Summary collapse

FRAMES =
UI::FRAMES
HEADLESS_INTERVAL =

seconds between plain lines when not a TTY

30

Instance Method Summary collapse

Constructor Details

#initialize(io: $stdout) ⇒ Status

Returns a new instance of Status.



135
136
137
138
139
140
141
# File 'lib/everywhere/ui.rb', line 135

def initialize(io: $stdout)
  @io = io
  @tty = io.tty? && !ENV["NO_COLOR"]
  @frame = 0
  @drawn = false
  @last_headless = nil
end

Instance Method Details

#clearObject

Wipe the current line so normal output lands on a clean row. No-op when nothing is drawn (including the whole headless path).



156
157
158
159
160
161
162
# File 'lib/everywhere/ui.rb', line 156

def clear
  return unless @drawn

  @io.print("\r\e[2K")
  @io.flush
  @drawn = false
end

#update(text) ⇒ Object



143
144
145
146
147
148
149
150
151
152
# File 'lib/everywhere/ui.rb', line 143

def update(text)
  return headless(text) unless @tty

  line = "  #{UI.cyan(FRAMES[@frame % FRAMES.size])} #{UI.dim(text)}"
  @frame += 1
  clear
  @io.print(line)
  @io.flush
  @drawn = true
end