File: color.rb

package info (click to toggle)
ruby-whitequark-parser 3.3.4.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,828 kB
  • sloc: yacc: 40,699; ruby: 20,395; makefile: 12; sh: 8
file content (32 lines) | stat: -rw-r--r-- 627 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

module Parser
  module Color
    def self.color(str, code, bold: false)
      return str unless STDOUT.tty?
      code = Array(code)
      code.unshift(1) if bold
      "\e[#{code.join(';')}m#{str}\e[0m"
    end

    def self.red(str, bold: false)
      color(str, 31, bold: bold)
    end

    def self.green(str, bold: false)
      color(str, 32, bold: bold)
    end

    def self.yellow(str, bold: false)
      color(str, 33, bold: bold)
    end

    def self.magenta(str, bold: false)
      color(str, 35, bold: bold)
    end

    def self.underline(str)
      color(str, 4)
    end
  end
end