Class: Audition::Report::Style
- Inherits:
-
Object
- Object
- Audition::Report::Style
- Defined in:
- lib/audition/report.rb
Overview
ANSI + OSC 8 styling with graceful degradation. Color and hyperlinks are decided once, at construction; pass color: false for pipes, NO_COLOR, or dumb terminals.
Constant Summary collapse
- GLYPHS =
Ractor.make_shareable( { error: ["✖", "x"], warning: ["⚠", "!"], info: ["ℹ", "i"], pass: ["✔", "ok"], section: ["◆", "*"], fix: ["✎", "+"] } )
- PAINTS =
%i[red yellow green cyan magenta dim bold].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #glyph(kind) ⇒ Object
-
#initialize(color:, hyperlinks:) ⇒ Style
constructor
A new instance of Style.
-
#link(text, absolute_path) ⇒ Object
OSC 8 hyperlink wrapping "path:line" display text in a file:// URI; supporting terminals make it clickable.
- #severity_color(severity, text) ⇒ Object
Constructor Details
#initialize(color:, hyperlinks:) ⇒ Style
Returns a new instance of Style.
31 32 33 34 35 |
# File 'lib/audition/report.rb', line 31 def initialize(color:, hyperlinks:) @pastel = Pastel.new(enabled: color) @color = color @hyperlinks = hyperlinks end |
Class Method Details
.detect(io: $stdout) ⇒ Object
25 26 27 28 29 |
# File 'lib/audition/report.rb', line 25 def self.detect(io: $stdout) on = io.respond_to?(:tty?) && io.tty? && !ENV.key?("NO_COLOR") && ENV["TERM"] != "dumb" new(color: on, hyperlinks: on && TTY::Link.link?) end |
Instance Method Details
#glyph(kind) ⇒ Object
37 38 39 |
# File 'lib/audition/report.rb', line 37 def glyph(kind) GLYPHS.fetch(kind)[@color ? 0 : 1] end |
#link(text, absolute_path) ⇒ Object
OSC 8 hyperlink wrapping "path:line" display text in a file:// URI; supporting terminals make it clickable. tty-link emits when it detects support; when hyperlinks are forced on despite no detection (tests, --force scenarios) fall back to the raw OSC 8 template, since tty-link's fallback is "text -> url" prose.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/audition/report.rb', line 61 def link(text, absolute_path) return text unless @hyperlinks uri = "file://#{absolute_path}" if TTY::Link.link? TTY::Link.link_to(text, uri) else "\e]8;;#{uri}\e\\#{text}\e]8;;\e\\" end end |
#severity_color(severity, text) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/audition/report.rb', line 47 def severity_color(severity, text) case severity when :error then red(text) when :warning then yellow(text) else cyan(text) end end |