Module: TestBench::Output::Palette
- Defined in:
- lib/test_bench/output/palette.rb
Class Method Summary collapse
- .apply(prose, **colors) ⇒ Object
- .escape_code(fg: nil, bg: nil) ⇒ Object
- .get(name) ⇒ Object
- .names ⇒ Object
Class Method Details
.apply(prose, **colors) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/test_bench/output/palette.rb', line 4 def self.apply prose, **colors escape_code = self.escape_code(**colors) if escape_code.empty? prose else "#{escape_code}#{prose}\e[0m" end end |
.escape_code(fg: nil, bg: nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/test_bench/output/palette.rb', line 14 def self.escape_code fg: nil, bg: nil return '' if fg.nil? and bg.nil? brightness, fg = get fg if fg _, bg = get bg if bg str = String.new "\e[" str << "#{brightness};3#{fg}" if fg str << ';' if fg and bg str << "4#{bg}" if bg str << 'm' str end |
.get(name) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/test_bench/output/palette.rb', line 30 def self.get name code = names.index name return unless code brightness, code = code.divmod 8 return brightness, code end |
.names ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/test_bench/output/palette.rb', line 37 def self.names @names ||= %i( black red green brown blue magenta cyan gray dark_gray bright_red bright_green yellow bright_blue bright_magenta bright_cyan white ) end |