reline 0.4.0 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24b02f1563ed151bd0b67246977442d845c887048264399384dddf506b4d6de2
4
- data.tar.gz: 3d51b1b162709f7d378e782a4f28b6b1e99b0fe3fa8929846481c4c6ab9dae5e
3
+ metadata.gz: 5fbe3e08832a8893e51895e3efe21ff3e728414d85ae95d62f2c854c1608f966
4
+ data.tar.gz: 8a0af70e8ce6cf9454fdb40070a405e53e0d2afcad9b4ad87345e2d5092662e6
5
5
  SHA512:
6
- metadata.gz: 0a467797d4c4191c3b9949b5048fc3cadae9e837bdf086565e51206f7d6786774ae13b6081f6e418fdf4ee62c82d02e369d50a4cca9955918ebfb682d5875a7d
7
- data.tar.gz: 65e0a409b22c3f5ebeb8bd3b068168bdabac6cda5d0b8b7d6d07dacbe90265055a7eeb24f433a455b9bd6ca06dbe3f9d2018987ea1a098dedc96d6a6eb16430c
6
+ metadata.gz: 1b480360a8dde5c140028bcaa408cdcd08469499ee331fd7441ffb7f63a9dda835e395ffc7b95b9c78fe3ad3209190deac1639f47c8973e2c1839a73d386201b
7
+ data.tar.gz: df35e1166aaec1003a40abb889d5c7a9268bd59293dcd3a1910dd2b5aa36177ba4b03c93aae746c7066c4b267115d621f8c8510b4a40871f27a7c96e1e384581
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
@@ -14,7 +14,7 @@ class Reline::KillRing
14
14
  end
15
15
 
16
16
  def ==(other)
17
- object_id == other.object_id
17
+ equal?(other)
18
18
  end
19
19
  end
20
20
 
@@ -1313,7 +1313,7 @@ class Reline::LineEditor
1313
1313
  end
1314
1314
  if not just_show_list and target < completed
1315
1315
  @line = (preposing + completed + completion_append_character.to_s + postposing).split("\n")[@line_index] || String.new(encoding: @encoding)
1316
- line_to_pointer = (preposing + completed + completion_append_character.to_s).split("\n").last || String.new(encoding: @encoding)
1316
+ line_to_pointer = (preposing + completed + completion_append_character.to_s).split("\n")[@line_index] || String.new(encoding: @encoding)
1317
1317
  @cursor_max = calculate_width(@line)
1318
1318
  @cursor = calculate_width(line_to_pointer)
1319
1319
  @byte_pointer = line_to_pointer.bytesize
@@ -1360,7 +1360,7 @@ class Reline::LineEditor
1360
1360
  completed = @completion_journey_data.list[@completion_journey_data.pointer]
1361
1361
  new_line = (@completion_journey_data.preposing + completed + @completion_journey_data.postposing).split("\n")[@line_index]
1362
1362
  @line = new_line.nil? ? String.new(encoding: @encoding) : new_line
1363
- line_to_pointer = (@completion_journey_data.preposing + completed).split("\n").last
1363
+ line_to_pointer = (@completion_journey_data.preposing + completed).split("\n")[@line_index]
1364
1364
  line_to_pointer = String.new(encoding: @encoding) if line_to_pointer.nil?
1365
1365
  @cursor_max = calculate_width(@line)
1366
1366
  @cursor = calculate_width(line_to_pointer)
@@ -1,3 +1,3 @@
1
1
  module Reline
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - aycabta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-07 00:00:00.000000000 Z
11
+ date: 2024-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: io-console
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  requirements: []
76
- rubygems_version: 3.5.0.dev
76
+ rubygems_version: 3.5.1
77
77
  signing_key:
78
78
  specification_version: 4
79
79
  summary: Alternative GNU Readline or Editline implementation by pure Ruby.