Class: SQLiteSweep::Display
- Inherits:
-
Object
- Object
- SQLiteSweep::Display
- Defined in:
- lib/sqlitesweep/display.rb
Overview
Live progress display on stderr. Shows a single-line status that updates in-place using ANSI escape codes (r to return to line start, e[2K to clear the line).
Output format:
Queried: 14523 | Errors: 3 | Rate: 847/s | Elapsed: 17.1s | Result: 2847291
When live mode is disabled (–no-live or non-TTY stderr), all rendering is silently skipped. This keeps piped output clean.
The display auto-refreshes every 250ms via a background timer thread, and can also be manually refreshed after each query completes.
Instance Method Summary collapse
-
#finish ⇒ Object
Stops the timer, renders one final update, and prints a newline so subsequent output starts on a fresh line.
-
#initialize(aggregator, live: true) ⇒ Display
constructor
A new instance of Display.
-
#refresh ⇒ Object
Manually triggers a display refresh.
-
#start(start_time) ⇒ Object
Starts the display timer.
Constructor Details
#initialize(aggregator, live: true) ⇒ Display
Returns a new instance of Display.
18 19 20 21 22 23 24 |
# File 'lib/sqlitesweep/display.rb', line 18 def initialize(aggregator, live: true) @aggregator = aggregator @live = live @start_time = nil @mutex = Mutex.new @timer = nil end |
Instance Method Details
#finish ⇒ Object
Stops the timer, renders one final update, and prints a newline so subsequent output starts on a fresh line.
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/sqlitesweep/display.rb', line 52 def finish @timer&.kill @timer&.join(1) if @live @mutex.synchronize do render $stderr.write("\n") end end end |
#refresh ⇒ Object
Manually triggers a display refresh. Called by workers after each query completes to keep the display responsive.
45 46 47 48 |
# File 'lib/sqlitesweep/display.rb', line 45 def refresh return unless @live @mutex.synchronize { render } end |
#start(start_time) ⇒ Object
Starts the display timer. Must be called before any refresh calls.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sqlitesweep/display.rb', line 29 def start(start_time) @start_time = start_time return unless @live @timer = Thread.new do loop do sleep 0.25 refresh end rescue # timer thread exits silently on kill end end |