reline 0.0.7 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/reline.rb +51 -24
- data/lib/reline/ansi.rb +59 -26
- data/lib/reline/config.rb +34 -8
- data/lib/reline/general_io.rb +8 -0
- data/lib/reline/history.rb +34 -14
- data/lib/reline/key_actor/emacs.rb +7 -7
- data/lib/reline/key_actor/vi_command.rb +2 -2
- data/lib/reline/key_actor/vi_insert.rb +2 -2
- data/lib/reline/line_editor.rb +439 -90
- data/lib/reline/version.rb +1 -1
- data/lib/reline/windows.rb +41 -4
- metadata +18 -4
data/lib/reline/version.rb
CHANGED
data/lib/reline/windows.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
require 'fiddle/import'
|
2
2
|
|
3
3
|
class Reline::Windows
|
4
|
+
def self.encoding
|
5
|
+
Encoding::UTF_8
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.win?
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
4
12
|
RAW_KEYSTROKE_CONFIG = {
|
5
13
|
[224, 72] => :ed_prev_history, # ↑
|
6
14
|
[224, 80] => :ed_next_history, # ↓
|
@@ -68,6 +76,8 @@ class Reline::Windows
|
|
68
76
|
STD_INPUT_HANDLE = -10
|
69
77
|
STD_OUTPUT_HANDLE = -11
|
70
78
|
WINDOW_BUFFER_SIZE_EVENT = 0x04
|
79
|
+
FILE_TYPE_PIPE = 0x0003
|
80
|
+
FILE_NAME_INFO = 2
|
71
81
|
@@getwch = Win32API.new('msvcrt', '_getwch', [], 'I')
|
72
82
|
@@kbhit = Win32API.new('msvcrt', '_kbhit', [], 'I')
|
73
83
|
@@GetKeyState = Win32API.new('user32', 'GetKeyState', ['L'], 'L')
|
@@ -80,9 +90,36 @@ class Reline::Windows
|
|
80
90
|
@@hConsoleInputHandle = @@GetStdHandle.call(STD_INPUT_HANDLE)
|
81
91
|
@@GetNumberOfConsoleInputEvents = Win32API.new('kernel32', 'GetNumberOfConsoleInputEvents', ['L', 'P'], 'L')
|
82
92
|
@@ReadConsoleInput = Win32API.new('kernel32', 'ReadConsoleInput', ['L', 'P', 'L', 'P'], 'L')
|
93
|
+
@@GetFileType = Win32API.new('kernel32', 'GetFileType', ['L'], 'L')
|
94
|
+
@@GetFileInformationByHandleEx = Win32API.new('kernel32', 'GetFileInformationByHandleEx', ['L', 'I', 'P', 'L'], 'I')
|
95
|
+
|
83
96
|
@@input_buf = []
|
84
97
|
@@output_buf = []
|
85
98
|
|
99
|
+
def self.msys_tty?(io=@@hConsoleInputHandle)
|
100
|
+
# check if fd is a pipe
|
101
|
+
if @@GetFileType.call(io) != FILE_TYPE_PIPE
|
102
|
+
return false
|
103
|
+
end
|
104
|
+
|
105
|
+
bufsize = 1024
|
106
|
+
p_buffer = "\0" * bufsize
|
107
|
+
res = @@GetFileInformationByHandleEx.call(io, FILE_NAME_INFO, p_buffer, bufsize - 2)
|
108
|
+
return false if res == 0
|
109
|
+
|
110
|
+
# get pipe name: p_buffer layout is:
|
111
|
+
# struct _FILE_NAME_INFO {
|
112
|
+
# DWORD FileNameLength;
|
113
|
+
# WCHAR FileName[1];
|
114
|
+
# } FILE_NAME_INFO
|
115
|
+
len = p_buffer[0, 4].unpack("L")[0]
|
116
|
+
name = p_buffer[4, len].encode(Encoding::UTF_8, Encoding::UTF_16LE, invalid: :replace)
|
117
|
+
|
118
|
+
# Check if this could be a MSYS2 pty pipe ('\msys-XXXX-ptyN-XX')
|
119
|
+
# or a cygwin pty pipe ('\cygwin-XXXX-ptyN-XX')
|
120
|
+
name =~ /(msys-|cygwin-).*-pty/ ? true : false
|
121
|
+
end
|
122
|
+
|
86
123
|
def self.getwch
|
87
124
|
unless @@input_buf.empty?
|
88
125
|
return @@input_buf.shift
|
@@ -99,7 +136,7 @@ class Reline::Windows
|
|
99
136
|
return @@input_buf.shift
|
100
137
|
end
|
101
138
|
begin
|
102
|
-
bytes = ret.chr(Encoding::UTF_8).
|
139
|
+
bytes = ret.chr(Encoding::UTF_8).bytes
|
103
140
|
@@input_buf.push(*bytes)
|
104
141
|
rescue Encoding::UndefinedConversionError
|
105
142
|
@@input_buf << ret
|
@@ -205,7 +242,7 @@ class Reline::Windows
|
|
205
242
|
|
206
243
|
def self.scroll_down(val)
|
207
244
|
return if val.zero?
|
208
|
-
scroll_rectangle = [0, val, get_screen_size.
|
245
|
+
scroll_rectangle = [0, val, get_screen_size.last, get_screen_size.first].pack('s4')
|
209
246
|
destination_origin = 0 # y * 65536 + x
|
210
247
|
fill = [' '.ord, 0].pack('SS')
|
211
248
|
@@ScrollConsoleScreenBuffer.call(@@hConsoleHandle, scroll_rectangle, nil, destination_origin, fill)
|
@@ -213,8 +250,8 @@ class Reline::Windows
|
|
213
250
|
|
214
251
|
def self.clear_screen
|
215
252
|
# TODO: Use FillConsoleOutputCharacter and FillConsoleOutputAttribute
|
216
|
-
|
217
|
-
|
253
|
+
write "\e[2J"
|
254
|
+
write "\e[1;1H"
|
218
255
|
end
|
219
256
|
|
220
257
|
def self.set_screen_size(rows, columns)
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- aycabta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: io-console
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.5'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -91,14 +105,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
105
|
requirements:
|
92
106
|
- - ">="
|
93
107
|
- !ruby/object:Gem::Version
|
94
|
-
version: '
|
108
|
+
version: '2.5'
|
95
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
110
|
requirements:
|
97
111
|
- - ">="
|
98
112
|
- !ruby/object:Gem::Version
|
99
113
|
version: '0'
|
100
114
|
requirements: []
|
101
|
-
rubygems_version: 3.
|
115
|
+
rubygems_version: 3.1.2
|
102
116
|
signing_key:
|
103
117
|
specification_version: 4
|
104
118
|
summary: Alternative GNU Readline or Editline implementation by pure Ruby.
|