Module: RSpecTurbo::Terminal
- Defined in:
- lib/rspec_turbo/terminal.rb
Overview
Pure presentation helpers shared across the reporting code: duration formatting, optional ANSI colour, spinner frames and rule separators.
On CI (no TTY) colour is dropped and box-drawing characters fall back to plain ASCII, which CI log viewers render without mangling.
Constant Summary collapse
- SPINNER_FRAMES =
%w[⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏].freeze
- SEP_THIN =
(Config::TTY ? "─" : "=") * 68
- SEP_THICK =
(Config::TTY ? "═" : "=") * 68
Class Method Summary collapse
-
.c(code, text) ⇒ Object
Wraps text in an ANSI escape sequence only when running in a TTY.
- .fmt_duration(seconds) ⇒ Object
- .strip_ansi(text) ⇒ Object
Class Method Details
.c(code, text) ⇒ Object
Wraps text in an ANSI escape sequence only when running in a TTY.
24 |
# File 'lib/rspec_turbo/terminal.rb', line 24 def c(code, text) = Config::TTY ? "\e[#{code}m#{text}\e[0m" : text |
.fmt_duration(seconds) ⇒ Object
17 18 19 20 21 |
# File 'lib/rspec_turbo/terminal.rb', line 17 def fmt_duration(seconds) minutes, secs = seconds.divmod(60) minutes.positive? ? format("%dm%02ds", minutes, secs) : format("%ds", secs) end |
.strip_ansi(text) ⇒ Object
26 |
# File 'lib/rspec_turbo/terminal.rb', line 26 def strip_ansi(text) = text.gsub(/\e\[[0-9;]*m/, "") |