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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c109228f50bec62ad64f9231151865fc6767b95ea5e714c254f2ce8f4480d3e6
4
- data.tar.gz: 8fe386600dca93bb0fce22c72a628392840ad0922d5285afedd5542bdb9e1f3b
3
+ metadata.gz: 5d16269b004e83a04194509a08f401942324ca51a216897f84a7c79bf0c1e0a4
4
+ data.tar.gz: dc7fe8a18875d588b45f6e5ef37bba5495e40d30ab0268d7895f4dfb36b6e3bc
5
5
  SHA512:
6
- metadata.gz: c1652f7c8c852328fe3371e8881e1fdf13e0c41c4e34894e08c36c15c7521f33035bdfad34cdf0264a3ef4bdf23e1cb45a4a25e3231f592831dd6e8fb6cbeb8f
7
- data.tar.gz: 9aadb3ba73cd2c8ca051e0310d297dc76e6a7a210c4048620c143bf76afce3b7a780f642d2f8167894978301daa82c7229fdd443718ba25a14e2970ead7f9702
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, &:getbyte)
130
- sleep 0.1
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 ||= inputrc_path
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
- # override @key_actors[@editing_mode_label].default_key_bindings with @additional_key_bindings[@editing_mode_label]
152
- @key_actors[@editing_mode_label].default_key_bindings.merge(@additional_key_bindings[@editing_mode_label])
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)
@@ -43,7 +43,7 @@ class Reline::KeyActor::Emacs < Reline::KeyActor::Base
43
43
  # 20 ^T
44
44
  :ed_transpose_chars,
45
45
  # 21 ^U
46
- :em_kill_line,
46
+ :ed_kill_line,
47
47
  # 22 ^V
48
48
  :ed_quoted_insert,
49
49
  # 23 ^W
@@ -1,38 +1,87 @@
1
1
  class Reline::KeyStroke
2
- using Module.new {
3
- refine Array do
4
- def start_with?(other)
5
- other.size <= size && other == self.take(other.size)
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
- def bytes
9
- self
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 initialize(config)
15
- @config = config
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
- lhs.start_with? input
68
+ start_with?(lhs, input)
21
69
  }.tap { |it|
22
- return :matched if it.size == 1 && (it.max_by(&:size)&.size&.== input.size)
23
- return :matching if it.size == 1 && (it.max_by(&:size)&.size&.!= input.size)
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
- input.start_with? lhs
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
- lhs = key_mapping.keys.select { |item| input.start_with? item }.sort_by(&:size).reverse.first
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