reline 0.3.8 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/lib/reline/config.rb +1 -1
- data/lib/reline/face.rb +157 -0
- data/lib/reline/general_io.rb +5 -1
- data/lib/reline/line_editor.rb +10 -13
- data/lib/reline/unicode/east_asian_width.rb +3 -3
- data/lib/reline/version.rb +1 -1
- data/lib/reline.rb +6 -8
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24b02f1563ed151bd0b67246977442d845c887048264399384dddf506b4d6de2
|
4
|
+
data.tar.gz: 3d51b1b162709f7d378e782a4f28b6b1e99b0fe3fa8929846481c4c6ab9dae5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a467797d4c4191c3b9949b5048fc3cadae9e837bdf086565e51206f7d6786774ae13b6081f6e418fdf4ee62c82d02e369d50a4cca9955918ebfb682d5875a7d
|
7
|
+
data.tar.gz: 65e0a409b22c3f5ebeb8bd3b068168bdabac6cda5d0b8b7d6d07dacbe90265055a7eeb24f433a455b9bd6ca06dbe3f9d2018987ea1a098dedc96d6a6eb16430c
|
data/README.md
CHANGED
@@ -55,6 +55,13 @@ end
|
|
55
55
|
|
56
56
|
See also: [test/reline/yamatanooroti/multiline_repl](https://github.com/ruby/reline/blob/master/test/reline/yamatanooroti/multiline_repl)
|
57
57
|
|
58
|
+
## Documentation
|
59
|
+
|
60
|
+
### Reline::Face
|
61
|
+
|
62
|
+
You can modify the text color and text decorations in your terminal emulator.
|
63
|
+
See [doc/reline/face.md](./doc/reline/face.md)
|
64
|
+
|
58
65
|
## Contributing
|
59
66
|
|
60
67
|
Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/reline.
|
data/lib/reline/config.rb
CHANGED
data/lib/reline/face.rb
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Reline::Face
|
4
|
+
SGR_PARAMETERS = {
|
5
|
+
foreground: {
|
6
|
+
black: 30,
|
7
|
+
red: 31,
|
8
|
+
green: 32,
|
9
|
+
yellow: 33,
|
10
|
+
blue: 34,
|
11
|
+
magenta: 35,
|
12
|
+
cyan: 36,
|
13
|
+
white: 37,
|
14
|
+
bright_black: 90,
|
15
|
+
gray: 90,
|
16
|
+
bright_red: 91,
|
17
|
+
bright_green: 92,
|
18
|
+
bright_yellow: 93,
|
19
|
+
bright_blue: 94,
|
20
|
+
bright_magenta: 95,
|
21
|
+
bright_cyan: 96,
|
22
|
+
bright_white: 97
|
23
|
+
},
|
24
|
+
background: {
|
25
|
+
black: 40,
|
26
|
+
red: 41,
|
27
|
+
green: 42,
|
28
|
+
yellow: 43,
|
29
|
+
blue: 44,
|
30
|
+
magenta: 45,
|
31
|
+
cyan: 46,
|
32
|
+
white: 47,
|
33
|
+
bright_black: 100,
|
34
|
+
gray: 100,
|
35
|
+
bright_red: 101,
|
36
|
+
bright_green: 102,
|
37
|
+
bright_yellow: 103,
|
38
|
+
bright_blue: 104,
|
39
|
+
bright_magenta: 105,
|
40
|
+
bright_cyan: 106,
|
41
|
+
bright_white: 107,
|
42
|
+
},
|
43
|
+
style: {
|
44
|
+
reset: 0,
|
45
|
+
bold: 1,
|
46
|
+
faint: 2,
|
47
|
+
italicized: 3,
|
48
|
+
underlined: 4,
|
49
|
+
slowly_blinking: 5,
|
50
|
+
blinking: 5,
|
51
|
+
rapidly_blinking: 6,
|
52
|
+
negative: 7,
|
53
|
+
concealed: 8,
|
54
|
+
crossed_out: 9
|
55
|
+
}
|
56
|
+
}.freeze
|
57
|
+
|
58
|
+
class Config
|
59
|
+
ESSENTIAL_DEFINE_NAMES = %i(default enhanced scrollbar).freeze
|
60
|
+
RESET_SGR = "\e[0m".freeze
|
61
|
+
|
62
|
+
def initialize(name, &block)
|
63
|
+
@definition = {}
|
64
|
+
block.call(self)
|
65
|
+
ESSENTIAL_DEFINE_NAMES.each do |name|
|
66
|
+
@definition[name] ||= { style: :reset, escape_sequence: RESET_SGR }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
attr_reader :definition
|
71
|
+
|
72
|
+
def define(name, **values)
|
73
|
+
values[:escape_sequence] = format_to_sgr(values.to_a).freeze
|
74
|
+
@definition[name] = values
|
75
|
+
end
|
76
|
+
|
77
|
+
def [](name)
|
78
|
+
@definition.dig(name, :escape_sequence) or raise ArgumentError, "unknown face: #{name}"
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def sgr_rgb(key, value)
|
84
|
+
return nil unless rgb_expression?(value)
|
85
|
+
case key
|
86
|
+
when :foreground
|
87
|
+
"38;2;"
|
88
|
+
when :background
|
89
|
+
"48;2;"
|
90
|
+
end + value[1, 6].scan(/../).map(&:hex).join(";")
|
91
|
+
end
|
92
|
+
|
93
|
+
def format_to_sgr(ordered_values)
|
94
|
+
sgr = "\e[" + ordered_values.map do |key_value|
|
95
|
+
key, value = key_value
|
96
|
+
case key
|
97
|
+
when :foreground, :background
|
98
|
+
case value
|
99
|
+
when Symbol
|
100
|
+
SGR_PARAMETERS[key][value]
|
101
|
+
when String
|
102
|
+
sgr_rgb(key, value)
|
103
|
+
end
|
104
|
+
when :style
|
105
|
+
[ value ].flatten.map do |style_name|
|
106
|
+
SGR_PARAMETERS[:style][style_name]
|
107
|
+
end.then do |sgr_parameters|
|
108
|
+
sgr_parameters.include?(nil) ? nil : sgr_parameters
|
109
|
+
end
|
110
|
+
end.then do |rendition_expression|
|
111
|
+
unless rendition_expression
|
112
|
+
raise ArgumentError, "invalid SGR parameter: #{value.inspect}"
|
113
|
+
end
|
114
|
+
rendition_expression
|
115
|
+
end
|
116
|
+
end.join(';') + "m"
|
117
|
+
sgr == RESET_SGR ? RESET_SGR : RESET_SGR + sgr
|
118
|
+
end
|
119
|
+
|
120
|
+
def rgb_expression?(color)
|
121
|
+
color.respond_to?(:match?) and color.match?(/\A#[0-9a-fA-F]{6}\z/)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
private_constant :SGR_PARAMETERS, :Config
|
126
|
+
|
127
|
+
def self.[](name)
|
128
|
+
@configs[name]
|
129
|
+
end
|
130
|
+
|
131
|
+
def self.config(name, &block)
|
132
|
+
@configs ||= {}
|
133
|
+
@configs[name] = Config.new(name, &block)
|
134
|
+
end
|
135
|
+
|
136
|
+
def self.configs
|
137
|
+
@configs.transform_values(&:definition)
|
138
|
+
end
|
139
|
+
|
140
|
+
def self.load_initial_configs
|
141
|
+
config(:default) do |conf|
|
142
|
+
conf.define :default, style: :reset
|
143
|
+
conf.define :enhanced, style: :reset
|
144
|
+
conf.define :scrollbar, style: :reset
|
145
|
+
end
|
146
|
+
config(:completion_dialog) do |conf|
|
147
|
+
conf.define :default, foreground: :white, background: :cyan
|
148
|
+
conf.define :enhanced, foreground: :white, background: :magenta
|
149
|
+
conf.define :scrollbar, foreground: :white, background: :cyan
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def self.reset_to_initial_configs
|
154
|
+
@configs = {}
|
155
|
+
load_initial_configs
|
156
|
+
end
|
157
|
+
end
|
data/lib/reline/general_io.rb
CHANGED
@@ -3,7 +3,11 @@ require 'io/wait'
|
|
3
3
|
class Reline::GeneralIO
|
4
4
|
def self.reset(encoding: nil)
|
5
5
|
@@pasting = false
|
6
|
-
|
6
|
+
if encoding
|
7
|
+
@@encoding = encoding
|
8
|
+
elsif defined?(@@encoding)
|
9
|
+
remove_class_variable(:@@encoding)
|
10
|
+
end
|
7
11
|
end
|
8
12
|
|
9
13
|
def self.encoding
|
data/lib/reline/line_editor.rb
CHANGED
@@ -831,27 +831,24 @@ class Reline::LineEditor
|
|
831
831
|
dialog.column = 0
|
832
832
|
dialog.width = @screen_size.last
|
833
833
|
end
|
834
|
+
face = Reline::Face[dialog_render_info.face || :default]
|
835
|
+
scrollbar_sgr = face[:scrollbar]
|
836
|
+
default_sgr = face[:default]
|
837
|
+
enhanced_sgr = face[:enhanced]
|
834
838
|
dialog.contents = contents.map.with_index do |item, i|
|
835
|
-
|
836
|
-
fg_color = dialog_render_info.pointer_fg_color
|
837
|
-
bg_color = dialog_render_info.pointer_bg_color
|
838
|
-
else
|
839
|
-
fg_color = dialog_render_info.fg_color
|
840
|
-
bg_color = dialog_render_info.bg_color
|
841
|
-
end
|
839
|
+
line_sgr = i == pointer ? enhanced_sgr : default_sgr
|
842
840
|
str_width = dialog.width - (scrollbar_pos.nil? ? 0 : @block_elem_width)
|
843
841
|
str = padding_space_with_escape_sequences(Reline::Unicode.take_range(item, 0, str_width), str_width)
|
844
|
-
colored_content = "
|
842
|
+
colored_content = "#{line_sgr}#{str}"
|
845
843
|
if scrollbar_pos
|
846
|
-
color_seq = "\e[37m"
|
847
844
|
if scrollbar_pos <= (i * 2) and (i * 2 + 1) < (scrollbar_pos + bar_height)
|
848
|
-
colored_content +
|
845
|
+
colored_content + scrollbar_sgr + @full_block
|
849
846
|
elsif scrollbar_pos <= (i * 2) and (i * 2) < (scrollbar_pos + bar_height)
|
850
|
-
colored_content +
|
847
|
+
colored_content + scrollbar_sgr + @upper_half_block
|
851
848
|
elsif scrollbar_pos <= (i * 2 + 1) and (i * 2) < (scrollbar_pos + bar_height)
|
852
|
-
colored_content +
|
849
|
+
colored_content + scrollbar_sgr + @lower_half_block
|
853
850
|
else
|
854
|
-
colored_content +
|
851
|
+
colored_content + scrollbar_sgr + ' ' * @block_elem_width
|
855
852
|
end
|
856
853
|
else
|
857
854
|
colored_content
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Reline::Unicode::EastAsianWidth
|
2
2
|
# This is based on EastAsianWidth.txt
|
3
|
-
#
|
3
|
+
# UNICODE_VERSION = '15.1.0'
|
4
4
|
|
5
5
|
# Fullwidth
|
6
6
|
TYPE_F = /^[#{ %W(
|
@@ -60,14 +60,14 @@ class Reline::Unicode::EastAsianWidth
|
|
60
60
|
\u{2E80}-\u{2E99}
|
61
61
|
\u{2E9B}-\u{2EF3}
|
62
62
|
\u{2F00}-\u{2FD5}
|
63
|
-
\u{2FF0}-\u{
|
63
|
+
\u{2FF0}-\u{2FFF}
|
64
64
|
\u{3001}-\u{303E}
|
65
65
|
\u{3041}-\u{3096}
|
66
66
|
\u{3099}-\u{30FF}
|
67
67
|
\u{3105}-\u{312F}
|
68
68
|
\u{3131}-\u{318E}
|
69
69
|
\u{3190}-\u{31E3}
|
70
|
-
\u{
|
70
|
+
\u{31EF}-\u{321E}
|
71
71
|
\u{3220}-\u{3247}
|
72
72
|
\u{3250}-\u{4DBF}
|
73
73
|
\u{4E00}-\u{A48C}
|
data/lib/reline/version.rb
CHANGED
data/lib/reline.rb
CHANGED
@@ -7,6 +7,7 @@ require 'reline/key_stroke'
|
|
7
7
|
require 'reline/line_editor'
|
8
8
|
require 'reline/history'
|
9
9
|
require 'reline/terminfo'
|
10
|
+
require 'reline/face'
|
10
11
|
require 'rbconfig'
|
11
12
|
|
12
13
|
module Reline
|
@@ -36,10 +37,8 @@ module Reline
|
|
36
37
|
DialogRenderInfo = Struct.new(
|
37
38
|
:pos,
|
38
39
|
:contents,
|
39
|
-
:
|
40
|
-
:
|
41
|
-
:fg_color,
|
42
|
-
:pointer_fg_color,
|
40
|
+
:face,
|
41
|
+
:bg_color, # For the time being, this line should stay here for the compatibility with IRB.
|
43
42
|
:width,
|
44
43
|
:height,
|
45
44
|
:scrollbar,
|
@@ -260,10 +259,7 @@ module Reline
|
|
260
259
|
contents: result,
|
261
260
|
scrollbar: true,
|
262
261
|
height: [15, preferred_dialog_height].min,
|
263
|
-
|
264
|
-
pointer_bg_color: 45,
|
265
|
-
fg_color: 37,
|
266
|
-
pointer_fg_color: 37
|
262
|
+
face: :completion_dialog
|
267
263
|
)
|
268
264
|
}
|
269
265
|
Reline::DEFAULT_DIALOG_CONTEXT = Array.new
|
@@ -606,4 +602,6 @@ else
|
|
606
602
|
io
|
607
603
|
end
|
608
604
|
|
605
|
+
Reline::Face.load_initial_configs
|
606
|
+
|
609
607
|
Reline::HISTORY = Reline::History.new(Reline.core.config)
|
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
|
+
version: 0.4.0
|
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
|
+
date: 2023-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: io-console
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- lib/reline.rb
|
38
38
|
- lib/reline/ansi.rb
|
39
39
|
- lib/reline/config.rb
|
40
|
+
- lib/reline/face.rb
|
40
41
|
- lib/reline/general_io.rb
|
41
42
|
- lib/reline/history.rb
|
42
43
|
- lib/reline/key_actor.rb
|
@@ -72,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
73
|
- !ruby/object:Gem::Version
|
73
74
|
version: '0'
|
74
75
|
requirements: []
|
75
|
-
rubygems_version: 3.
|
76
|
+
rubygems_version: 3.5.0.dev
|
76
77
|
signing_key:
|
77
78
|
specification_version: 4
|
78
79
|
summary: Alternative GNU Readline or Editline implementation by pure Ruby.
|