Module: Bwrap::Output::Colors
- Included in:
- Levels
- Defined in:
- lib/bwrap/output/colors.rb
Overview
Methods to color CLI output.
Class Method Summary collapse
-
.color(red, green, blue, bold: false) ⇒ Object
Outputs ANSI true color sequence.
-
.stopcolor ⇒ Object
Outputs ANSI command to stop color output.
Class Method Details
.color(red, green, blue, bold: false) ⇒ Object
Outputs ANSI true color sequence.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/bwrap/output/colors.rb', line 6 def self.color red, green, blue, bold: false return unless $stdout.tty? return if ENV["COLORTERM"] != "truecolor" && ENV["COLORTERM"] != "24bit" out = "" out += "\x1b[38;1;1m" if bold # https://stackoverflow.com/questions/4842424/list-of-ansi-color-escape-sequences out += "\x1b[38;2;#{red};#{green};#{blue}m" out end |
.stopcolor ⇒ Object
Outputs ANSI command to stop color output.
19 20 21 22 23 24 |
# File 'lib/bwrap/output/colors.rb', line 19 def self.stopcolor return unless $stdout.tty? return if ENV["COLORTERM"] != "truecolor" && ENV["COLORTERM"] != "24bit" "\x1b[0m" end |