reline 0.2.8.pre.7 → 0.2.8.pre.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reline/ansi.rb +8 -3
- data/lib/reline/config.rb +20 -3
- data/lib/reline/key_actor/emacs.rb +1 -1
- data/lib/reline/key_stroke.rb +63 -14
- data/lib/reline/line_editor.rb +223 -74
- data/lib/reline/terminfo.rb +1 -1
- data/lib/reline/unicode.rb +3 -3
- data/lib/reline/version.rb +1 -1
- data/lib/reline/windows.rb +18 -16
- data/lib/reline.rb +53 -27
- metadata +3 -4
- data/lib/reline/line_editor.rb.orig +0 -3156
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d16269b004e83a04194509a08f401942324ca51a216897f84a7c79bf0c1e0a4
|
4
|
+
data.tar.gz: dc7fe8a18875d588b45f6e5ef37bba5495e40d30ab0268d7895f4dfb36b6e3bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59c0d2c3361faedafaa0266b8951d9dd5b2776aac5b37cb139b2e1a28b2c4a10b825aa79f90054d79eb5f8c5aa1d0969ee63d8e105605c66ec991e4527d2e35f
|
7
|
+
data.tar.gz: 43fbf984721138fe3c52c3ddda17d06f8a2d5f95a0216120d2b62134c3f99d7c8798e23bac06d7d6cef7748360e5ad35cca5804cd81d31e11c429a24e0d087f7
|
data/lib/reline/ansi.rb
CHANGED
@@ -33,11 +33,16 @@ class Reline::ANSI
|
|
33
33
|
config.add_default_key_binding_by_keymap(:vi_insert, key, func)
|
34
34
|
config.add_default_key_binding_by_keymap(:vi_command, key, func)
|
35
35
|
end
|
36
|
+
{
|
37
|
+
[27, 91, 90] => :completion_journey_up, # S-Tab
|
38
|
+
}.each_pair do |key, func|
|
39
|
+
config.add_default_key_binding_by_keymap(:emacs, key, func)
|
40
|
+
config.add_default_key_binding_by_keymap(:vi_insert, key, func)
|
41
|
+
end
|
36
42
|
{
|
37
43
|
# default bindings
|
38
44
|
[27, 32] => :em_set_mark, # M-<space>
|
39
45
|
[24, 24] => :em_exchange_mark, # C-x C-x
|
40
|
-
[27, 91, 90] => :completion_journey_up, # S-Tab
|
41
46
|
}.each_pair do |key, func|
|
42
47
|
config.add_default_key_binding_by_keymap(:emacs, key, func)
|
43
48
|
end
|
@@ -126,8 +131,8 @@ class Reline::ANSI
|
|
126
131
|
unless @@buf.empty?
|
127
132
|
return @@buf.shift
|
128
133
|
end
|
129
|
-
until c = @@input.raw(intr: true,
|
130
|
-
|
134
|
+
until c = @@input.raw(intr: true) { select([@@input], [], [], 0.1) && @@input.getbyte }
|
135
|
+
Reline.core.line_editor.resize
|
131
136
|
end
|
132
137
|
(c == 0x16 && @@input.raw(min: 0, tim: 0, &:getbyte)) || c
|
133
138
|
rescue Errno::EIO
|
data/lib/reline/config.rb
CHANGED
@@ -50,6 +50,7 @@ class Reline::Config
|
|
50
50
|
@additional_key_bindings[:emacs] = {}
|
51
51
|
@additional_key_bindings[:vi_insert] = {}
|
52
52
|
@additional_key_bindings[:vi_command] = {}
|
53
|
+
@oneshot_key_bindings = {}
|
53
54
|
@skip_section = nil
|
54
55
|
@if_stack = nil
|
55
56
|
@editing_mode_label = :emacs
|
@@ -75,6 +76,7 @@ class Reline::Config
|
|
75
76
|
@additional_key_bindings.keys.each do |key|
|
76
77
|
@additional_key_bindings[key].clear
|
77
78
|
end
|
79
|
+
@oneshot_key_bindings.clear
|
78
80
|
reset_default_key_bindings
|
79
81
|
end
|
80
82
|
|
@@ -128,8 +130,12 @@ class Reline::Config
|
|
128
130
|
return home_rc_path
|
129
131
|
end
|
130
132
|
|
133
|
+
private def default_inputrc_path
|
134
|
+
@default_inputrc_path ||= inputrc_path
|
135
|
+
end
|
136
|
+
|
131
137
|
def read(file = nil)
|
132
|
-
file ||=
|
138
|
+
file ||= default_inputrc_path
|
133
139
|
begin
|
134
140
|
if file.respond_to?(:readlines)
|
135
141
|
lines = file.readlines
|
@@ -148,8 +154,19 @@ class Reline::Config
|
|
148
154
|
end
|
149
155
|
|
150
156
|
def key_bindings
|
151
|
-
#
|
152
|
-
@key_actors[@editing_mode_label].default_key_bindings.
|
157
|
+
# The key bindings for each editing mode will be overwritten by the user-defined ones.
|
158
|
+
kb = @key_actors[@editing_mode_label].default_key_bindings.dup
|
159
|
+
kb.merge!(@additional_key_bindings[@editing_mode_label])
|
160
|
+
kb.merge!(@oneshot_key_bindings)
|
161
|
+
kb
|
162
|
+
end
|
163
|
+
|
164
|
+
def add_oneshot_key_binding(keystroke, target)
|
165
|
+
@oneshot_key_bindings[keystroke] = target
|
166
|
+
end
|
167
|
+
|
168
|
+
def reset_oneshot_key_bindings
|
169
|
+
@oneshot_key_bindings.clear
|
153
170
|
end
|
154
171
|
|
155
172
|
def add_default_key_binding_by_keymap(keymap, keystroke, target)
|
data/lib/reline/key_stroke.rb
CHANGED
@@ -1,38 +1,87 @@
|
|
1
1
|
class Reline::KeyStroke
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
def initialize(config)
|
3
|
+
@config = config
|
4
|
+
end
|
5
|
+
|
6
|
+
def compress_meta_key(ary)
|
7
|
+
ary.inject([]) { |result, key|
|
8
|
+
if result.size > 0 and result.last == "\e".ord
|
9
|
+
result[result.size - 1] = Reline::Key.new(key, key | 0b10000000, true)
|
10
|
+
else
|
11
|
+
result << key
|
6
12
|
end
|
13
|
+
result
|
14
|
+
}
|
15
|
+
end
|
7
16
|
|
8
|
-
|
9
|
-
|
17
|
+
def start_with?(me, other)
|
18
|
+
compressed_me = compress_meta_key(me)
|
19
|
+
compressed_other = compress_meta_key(other)
|
20
|
+
i = 0
|
21
|
+
loop do
|
22
|
+
my_c = compressed_me[i]
|
23
|
+
other_c = compressed_other[i]
|
24
|
+
other_is_last = (i + 1) == compressed_other.size
|
25
|
+
me_is_last = (i + 1) == compressed_me.size
|
26
|
+
if my_c != other_c
|
27
|
+
if other_c == "\e".ord and other_is_last and my_c.is_a?(Reline::Key) and my_c.with_meta
|
28
|
+
return true
|
29
|
+
else
|
30
|
+
return false
|
31
|
+
end
|
32
|
+
elsif other_is_last
|
33
|
+
return true
|
34
|
+
elsif me_is_last
|
35
|
+
return false
|
10
36
|
end
|
37
|
+
i += 1
|
11
38
|
end
|
12
|
-
|
39
|
+
end
|
13
40
|
|
14
|
-
def
|
15
|
-
|
41
|
+
def equal?(me, other)
|
42
|
+
case me
|
43
|
+
when Array
|
44
|
+
compressed_me = compress_meta_key(me)
|
45
|
+
compressed_other = compress_meta_key(other)
|
46
|
+
compressed_me.size == compressed_other.size and [compressed_me, compressed_other].transpose.all?{ |i| equal?(i[0], i[1]) }
|
47
|
+
when Integer
|
48
|
+
if other.is_a?(Reline::Key)
|
49
|
+
if other.combined_char == "\e".ord
|
50
|
+
false
|
51
|
+
else
|
52
|
+
other.combined_char == me
|
53
|
+
end
|
54
|
+
else
|
55
|
+
me == other
|
56
|
+
end
|
57
|
+
when Reline::Key
|
58
|
+
if other.is_a?(Integer)
|
59
|
+
me.combined_char == other
|
60
|
+
else
|
61
|
+
me == other
|
62
|
+
end
|
63
|
+
end
|
16
64
|
end
|
17
65
|
|
18
66
|
def match_status(input)
|
19
67
|
key_mapping.keys.select { |lhs|
|
20
|
-
|
68
|
+
start_with?(lhs, input)
|
21
69
|
}.tap { |it|
|
22
|
-
return :matched if it.size == 1 && (it
|
23
|
-
return :matching if it.size == 1 && (it
|
70
|
+
return :matched if it.size == 1 && equal?(it[0], input)
|
71
|
+
return :matching if it.size == 1 && !equal?(it[0], input)
|
24
72
|
return :matched if it.max_by(&:size)&.size&.< input.size
|
25
73
|
return :matching if it.size > 1
|
26
74
|
}
|
27
75
|
key_mapping.keys.select { |lhs|
|
28
|
-
|
76
|
+
start_with?(input, lhs)
|
29
77
|
}.tap { |it|
|
30
78
|
return it.size > 0 ? :matched : :unmatched
|
31
79
|
}
|
32
80
|
end
|
33
81
|
|
34
82
|
def expand(input)
|
35
|
-
|
83
|
+
input = compress_meta_key(input)
|
84
|
+
lhs = key_mapping.keys.select { |item| start_with?(input, item) }.sort_by(&:size).last
|
36
85
|
return input unless lhs
|
37
86
|
rhs = key_mapping[lhs]
|
38
87
|
|