reline 0.4.0 → 0.5.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reline/face.rb +42 -0
- data/lib/reline/general_io.rb +1 -1
- data/lib/reline/line_editor.rb +604 -1285
- data/lib/reline/version.rb +1 -1
- data/lib/reline.rb +10 -7
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6fdc2426aceadd0680462674da1132c7042924e9fda18daecd68b82e459a867
|
4
|
+
data.tar.gz: 5fc586dfacfd1cc5524320b0e3190982098fbdaf541a6ff56f9c153aa828560c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 052abb950ef133821f1c3bf43f4727e8ef6afe7210fb9a9f56df65ad1a16a96d54cfc519ecbab94c8b5502d8c6976fdfc7b5e87effb4f7b9e15a800ffaefa92f
|
7
|
+
data.tar.gz: 617b9876da860ac3b08fd659e9ef8e7cda3afc189e496b34cd116d9850bee9ed176e68f129b4ceff6443f3f3992460ef22ddad9d16c2a6dbdf07a3ee020a25e0
|
data/lib/reline/face.rb
CHANGED
@@ -74,6 +74,13 @@ class Reline::Face
|
|
74
74
|
@definition[name] = values
|
75
75
|
end
|
76
76
|
|
77
|
+
def reconfigure
|
78
|
+
@definition.each_value do |values|
|
79
|
+
values.delete(:escape_sequence)
|
80
|
+
values[:escape_sequence] = format_to_sgr(values.to_a).freeze
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
77
84
|
def [](name)
|
78
85
|
@definition.dig(name, :escape_sequence) or raise ArgumentError, "unknown face: #{name}"
|
79
86
|
end
|
@@ -82,6 +89,14 @@ class Reline::Face
|
|
82
89
|
|
83
90
|
def sgr_rgb(key, value)
|
84
91
|
return nil unless rgb_expression?(value)
|
92
|
+
if Reline::Face.truecolor?
|
93
|
+
sgr_rgb_truecolor(key, value)
|
94
|
+
else
|
95
|
+
sgr_rgb_256color(key, value)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def sgr_rgb_truecolor(key, value)
|
85
100
|
case key
|
86
101
|
when :foreground
|
87
102
|
"38;2;"
|
@@ -90,6 +105,24 @@ class Reline::Face
|
|
90
105
|
end + value[1, 6].scan(/../).map(&:hex).join(";")
|
91
106
|
end
|
92
107
|
|
108
|
+
def sgr_rgb_256color(key, value)
|
109
|
+
# 256 colors are
|
110
|
+
# 0..15: standard colors, hight intensity colors
|
111
|
+
# 16..232: 216 colors (R, G, B each 6 steps)
|
112
|
+
# 233..255: grayscale colors (24 steps)
|
113
|
+
# This methods converts rgb_expression to 216 colors
|
114
|
+
rgb = value[1, 6].scan(/../).map(&:hex)
|
115
|
+
# Color steps are [0, 95, 135, 175, 215, 255]
|
116
|
+
r, g, b = rgb.map { |v| v <= 95 ? v / 48 : (v - 35) / 40 }
|
117
|
+
color = (16 + 36 * r + 6 * g + b)
|
118
|
+
case key
|
119
|
+
when :foreground
|
120
|
+
"38;5;#{color}"
|
121
|
+
when :background
|
122
|
+
"48;5;#{color}"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
93
126
|
def format_to_sgr(ordered_values)
|
94
127
|
sgr = "\e[" + ordered_values.map do |key_value|
|
95
128
|
key, value = key_value
|
@@ -124,6 +157,15 @@ class Reline::Face
|
|
124
157
|
|
125
158
|
private_constant :SGR_PARAMETERS, :Config
|
126
159
|
|
160
|
+
def self.truecolor?
|
161
|
+
@force_truecolor || %w[truecolor 24bit].include?(ENV['COLORTERM'])
|
162
|
+
end
|
163
|
+
|
164
|
+
def self.force_truecolor
|
165
|
+
@force_truecolor = true
|
166
|
+
@configs&.each_value(&:reconfigure)
|
167
|
+
end
|
168
|
+
|
127
169
|
def self.[](name)
|
128
170
|
@configs[name]
|
129
171
|
end
|