File: constants.rb

package info (click to toggle)
ruby-paint 2.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 232 kB
  • sloc: ruby: 688; makefile: 4
file content (104 lines) | stat: -rw-r--r-- 3,338 bytes parent folder | download
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# frozen_string_literal: true

module Paint
  # Clears all colors
  NOTHING = "\033[0m"

  # Number of possible colors in TRUE COLOR mode
  TRUE_COLOR = 0xFFFFFF

  # Basic colors (often, the color differs when using the bright effect)
  # Final color will be 30 + value for foreground and 40 + value for background
  ANSI_COLORS = {
    :black   => 0,
    :red     => 1,
    :green   => 2,
    :yellow  => 3,
    :blue    => 4,
    :magenta => 5,
    :cyan    => 6,
    :white   => 7, :gray => 7,
    :default => 9,
  }.freeze

  ANSI_COLORS_FOREGROUND = {
    :black   => 30,
    :red     => 31,
    :green   => 32,
    :yellow  => 33,
    :blue    => 34,
    :magenta => 35,
    :cyan    => 36,
    :white   => 37, :gray => 37,
    :default => 39,
  }.freeze

  ANSI_COLORS_BACKGROUND = {
    :black   => 40,
    :red     => 41,
    :green   => 42,
    :yellow  => 43,
    :blue    => 44,
    :magenta => 45,
    :cyan    => 46,
    :white   => 47, :gray => 47,
    :default => 49,
  }.freeze

  # Terminal effects - most of them are not supported ;)
  # See https://en.wikipedia.org/wiki/ANSI_escape_code
  ANSI_EFFECTS = {
    :reset         => 0,  :nothing         => 0,  # usually supported
    :bright        => 1,  :bold            => 1,  # usually supported
    :faint         => 2,
    :italic        => 3,
    :underline     => 4,                          # usually supported
    :blink         => 5,  :slow_blink      => 5,
    :rapid_blink   => 6,
    :inverse       => 7,  :swap            => 7,  # usually supported
    :conceal       => 8,  :hide            => 9,
    :default_font  => 10,
    :font0 => 10, :font1 => 11, :font2 => 12, :font3 => 13, :font4 => 14,
    :font5 => 15, :font6 => 16, :font7 => 17, :font8 => 18, :font9 => 19,
    :fraktur       => 20,
    :bright_off    => 21, :bold_off        => 21, :double_underline => 21,
    :clean         => 22,
    :italic_off    => 23, :fraktur_off     => 23,
    :underline_off => 24,
    :blink_off     => 25,
    :inverse_off   => 26, :positive        => 26,
    :conceal_off   => 27, :show            => 27, :reveal           => 27,
    :crossed_off   => 29, :crossed_out_off => 29,
    :frame         => 51,
    :encircle      => 52,
    :overline      => 53,
    :frame_off     => 54, :encircle_off    => 54,
    :overline_off  => 55,
  }.freeze

  # A list of color names for standard ansi colors, needed for 16/8 color fallback mode
  # See https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
  RGB_COLORS_ANSI = {
    :black   => [  0,   0,   0],
    :red     => [205,   0,   0],
    :green   => [  0, 205,   0],
    :yellow  => [205, 205,   0],
    :blue    => [  0,   0, 238],
    :magenta => [205,   0, 205],
    :cyan    => [  0, 205, 205],
    :white   => [229, 229, 229], :gray => [229, 229, 229],
  }.each { |k, v| v.freeze }.freeze

  # A list of color names for standard bright ansi colors, needed for 16 color fallback mode
  # See https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
  RGB_COLORS_ANSI_BRIGHT = {
    :black   => [127, 127, 127],
    :red     => [255,   0,   0],
    :green   => [  0, 255,   0],
    :yellow  => [255, 255,   0],
    :blue    => [ 92,  92, 255],
    :magenta => [255,   0, 255],
    :cyan    => [  0, 255, 255],
    :white   => [255, 255, 255], :gray => [255, 255, 255],
  }.each { |k, v| v.freeze }.freeze
end