reline 0.3.6 → 0.3.7

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: 3075f4003cf263e4652fc0dec716c71b55b597e6cbdc8cdb5297181b72780b57
4
- data.tar.gz: 78eb2e13f17bc0c7ae34b425effe29bf40a30b355af7d0efd271823c2cdde521
3
+ metadata.gz: 67ad796ede485308abba9038bb03672537e8cba1409ef61e921d165db277846d
4
+ data.tar.gz: 9692f5e08f6ed30722262d70c89e413b4f7d7651f98698d6253f720aea600125
5
5
  SHA512:
6
- metadata.gz: 9fd55d135c7b1aaffaff575f930bdb6365c202a1d15b5943d3dd9f678f416ba312b21c836ef8b78d11ee9942c4e0f0ac50d395633196bd649bd23a2fa6096456
7
- data.tar.gz: 43fe692b243560a81da41a48f4cb5cdf05514f85788bbc6b54bba72aef4d5e7258e73c2a84622c80e51adf36345cd9e7595455f8301e09c1f299f7b2ec147ff2
6
+ metadata.gz: 4d69f27ac94aecc2f9628e824d4ded200cf0e0e1939b00d28db99b30f5b21baed78bba0edc7ab68105af327803c0e5f8f03853fb629079ae9017be6016bff0d7
7
+ data.tar.gz: 62af3574af7223c038e3b078708b116af92bcecf1ec9301e32f8653c008fdfea082253f9308aa99067f60aa9c98deecb5382552deee6847966f4e4ceb387f8f3
data/lib/reline/ansi.rb CHANGED
@@ -14,10 +14,21 @@ class Reline::ANSI
14
14
  'kcud1' => :ed_next_history,
15
15
  'kcuf1' => :ed_next_char,
16
16
  'kcub1' => :ed_prev_char,
17
- 'cuu' => :ed_prev_history,
18
- 'cud' => :ed_next_history,
19
- 'cuf' => :ed_next_char,
20
- 'cub' => :ed_prev_char,
17
+ }
18
+
19
+ ANSI_CURSOR_KEY_BINDINGS = {
20
+ # Up
21
+ 'A' => [:ed_prev_history, {}],
22
+ # Down
23
+ 'B' => [:ed_next_history, {}],
24
+ # Right
25
+ 'C' => [:ed_next_char, { ctrl: :em_next_word, meta: :em_next_word }],
26
+ # Left
27
+ 'D' => [:ed_prev_char, { ctrl: :ed_prev_word, meta: :ed_prev_word }],
28
+ # End
29
+ 'F' => [:ed_move_to_end, {}],
30
+ # Home
31
+ 'H' => [:ed_move_to_beg, {}],
21
32
  }
22
33
 
23
34
  if Reline::Terminfo.enabled?
@@ -33,22 +44,12 @@ class Reline::ANSI
33
44
  end
34
45
 
35
46
  def self.set_default_key_bindings(config, allow_terminfo: true)
47
+ set_default_key_bindings_ansi_cursor(config)
36
48
  if allow_terminfo && Reline::Terminfo.enabled?
37
49
  set_default_key_bindings_terminfo(config)
38
50
  else
39
51
  set_default_key_bindings_comprehensive_list(config)
40
52
  end
41
- {
42
- # extended entries of terminfo
43
- [27, 91, 49, 59, 53, 67] => :em_next_word, # Ctrl+→, extended entry
44
- [27, 91, 49, 59, 53, 68] => :ed_prev_word, # Ctrl+←, extended entry
45
- [27, 91, 49, 59, 51, 67] => :em_next_word, # Meta+→, extended entry
46
- [27, 91, 49, 59, 51, 68] => :ed_prev_word, # Meta+←, extended entry
47
- }.each_pair do |key, func|
48
- config.add_default_key_binding_by_keymap(:emacs, key, func)
49
- config.add_default_key_binding_by_keymap(:vi_insert, key, func)
50
- config.add_default_key_binding_by_keymap(:vi_command, key, func)
51
- end
52
53
  {
53
54
  [27, 91, 90] => :completion_journey_up, # S-Tab
54
55
  }.each_pair do |key, func|
@@ -64,18 +65,33 @@ class Reline::ANSI
64
65
  end
65
66
  end
66
67
 
68
+ def self.set_default_key_bindings_ansi_cursor(config)
69
+ ANSI_CURSOR_KEY_BINDINGS.each do |char, (default_func, modifiers)|
70
+ bindings = [["\e[#{char}", default_func]] # CSI + char
71
+ if modifiers[:ctrl]
72
+ # CSI + ctrl_key_modifier + char
73
+ bindings << ["\e[1;5#{char}", modifiers[:ctrl]]
74
+ end
75
+ if modifiers[:meta]
76
+ # CSI + meta_key_modifier + char
77
+ bindings << ["\e[1;3#{char}", modifiers[:meta]]
78
+ # Meta(ESC) + CSI + char
79
+ bindings << ["\e\e[#{char}", modifiers[:meta]]
80
+ end
81
+ bindings.each do |sequence, func|
82
+ key = sequence.bytes
83
+ config.add_default_key_binding_by_keymap(:emacs, key, func)
84
+ config.add_default_key_binding_by_keymap(:vi_insert, key, func)
85
+ config.add_default_key_binding_by_keymap(:vi_command, key, func)
86
+ end
87
+ end
88
+ end
89
+
67
90
  def self.set_default_key_bindings_terminfo(config)
68
91
  key_bindings = CAPNAME_KEY_BINDINGS.map do |capname, key_binding|
69
92
  begin
70
93
  key_code = Reline::Terminfo.tigetstr(capname)
71
- case capname
72
- # Escape sequences that omit the move distance and are set to defaults
73
- # value 1 may be sometimes sent by pressing the arrow-key.
74
- when 'cuu', 'cud', 'cuf', 'cub'
75
- [ key_code.sub(/%p1%d/, '').bytes, key_binding ]
76
- else
77
- [ key_code.bytes, key_binding ]
78
- end
94
+ [ key_code.bytes, key_binding ]
79
95
  rescue Reline::Terminfo::TerminfoError
80
96
  # capname is undefined
81
97
  end
@@ -94,14 +110,8 @@ class Reline::ANSI
94
110
  [27, 91, 49, 126] => :ed_move_to_beg, # Home
95
111
  [27, 91, 52, 126] => :ed_move_to_end, # End
96
112
  [27, 91, 51, 126] => :key_delete, # Del
97
- [27, 91, 65] => :ed_prev_history, # ↑
98
- [27, 91, 66] => :ed_next_history, # ↓
99
- [27, 91, 67] => :ed_next_char, # →
100
- [27, 91, 68] => :ed_prev_char, # ←
101
113
 
102
114
  # KDE
103
- [27, 91, 72] => :ed_move_to_beg, # Home
104
- [27, 91, 70] => :ed_move_to_end, # End
105
115
  # Del is 0x08
106
116
  [27, 71, 65] => :ed_prev_history, # ↑
107
117
  [27, 71, 66] => :ed_next_history, # ↓
@@ -118,12 +128,6 @@ class Reline::ANSI
118
128
  # Del is 0x08
119
129
  # Arrow keys are the same of KDE
120
130
 
121
- # iTerm2
122
- [27, 27, 91, 67] => :em_next_word, # Option+→, extended entry
123
- [27, 27, 91, 68] => :ed_prev_word, # Option+←, extended entry
124
- [195, 166] => :em_next_word, # Option+f
125
- [195, 162] => :ed_prev_word, # Option+b
126
-
127
131
  [27, 79, 65] => :ed_prev_history, # ↑
128
132
  [27, 79, 66] => :ed_next_history, # ↓
129
133
  [27, 79, 67] => :ed_next_char, # →
@@ -331,9 +335,12 @@ class Reline::ANSI
331
335
  @@output.write "\e[K"
332
336
  end
333
337
 
338
+ # This only works when the cursor is at the bottom of the scroll range
339
+ # For more details, see https://github.com/ruby/reline/pull/577#issuecomment-1646679623
334
340
  def self.scroll_down(x)
335
341
  return if x.zero?
336
- @@output.write "\e[#{x}S"
342
+ # We use `\n` instead of CSI + S because CSI + S would cause https://github.com/ruby/reline/issues/576
343
+ @@output.write "\n" * x
337
344
  end
338
345
 
339
346
  def self.clear_screen
@@ -1605,7 +1605,7 @@ class Reline::LineEditor
1605
1605
  else
1606
1606
  @just_cursor_moving = false
1607
1607
  end
1608
- if @is_multiline and @auto_indent_proc and not simplified_rendering?
1608
+ if @is_multiline and @auto_indent_proc and not simplified_rendering? and @line
1609
1609
  process_auto_indent
1610
1610
  end
1611
1611
  end
@@ -1,3 +1,3 @@
1
1
  module Reline
2
- VERSION = '0.3.6'
2
+ VERSION = '0.3.7'
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.3.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - aycabta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-08 00:00:00.000000000 Z
11
+ date: 2023-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: io-console