mini_readline 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +12 -5
- data/lib/mini_readline/exceptions.rb +5 -0
- data/lib/mini_readline/options.rb +2 -0
- data/lib/mini_readline/raw_term/other/map.rb +3 -0
- data/lib/mini_readline/raw_term/other.rb +2 -0
- data/lib/mini_readline/raw_term/windows/map.rb +3 -0
- data/lib/mini_readline/read_line/edit/auto_complete/file_folder_source.rb +4 -0
- data/lib/mini_readline/read_line/edit/auto_complete.rb +1 -1
- data/lib/mini_readline/read_line/edit/edit_window/sync_window.rb +7 -5
- data/lib/mini_readline/read_line/edit/end_of_input.rb +18 -0
- data/lib/mini_readline/read_line/edit.rb +1 -0
- data/lib/mini_readline/version.rb +1 -1
- data/lib/mini_readline.rb +1 -0
- data/sire.rb +52 -0
- data/tests/mini_readline_tests.rb +6 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 634b35a4a125886de4969dd4f807fdf2b35e5ec3
|
4
|
+
data.tar.gz: d6be43dd1584f371fea17f7600ee5b5e49ccefc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09a90d21011cc4e47143fda7e2b01d2ae88bbea694e5c1bf350214a9af3d69f874211d26aa3cd7c065254f95b3b7ccca4fd102db2d21260eda190afe14606bd2
|
7
|
+
data.tar.gz: f713ffa03366f00f15203215656f4225c36e2e929f298bedd824e908885c005ddaf60c5581f8b46ca852ef0ad003c6cd6a932ac2f6b40002ba6e48b2016260f0
|
data/README.md
CHANGED
@@ -56,11 +56,13 @@ Erase Left | Backspace, Ctrl-H | Backspace, Ctrl-H
|
|
56
56
|
Erase Right | Delete, Ctrl-Backspace | Delete, Ctrl-Backspace
|
57
57
|
Erase All | Escape | Ctrl-L
|
58
58
|
Auto-complete | Tab, Ctrl-I | Tab, Ctrl-I
|
59
|
+
End of Input | Ctrl-Z | Alt-z
|
59
60
|
|
60
61
|
### Notes
|
61
62
|
* The label "Other" is an umbrella that bundles together the Linux, Mac,
|
62
63
|
and Cygwin platforms.
|
63
64
|
* References to Pad keys under Windows assume that Num Lock is not engaged.
|
65
|
+
* Support for End of Input is controlled by the eoi_detect option.
|
64
66
|
|
65
67
|
## Usage
|
66
68
|
|
@@ -130,12 +132,12 @@ of the history buffer of the edit object with:
|
|
130
132
|
hist = edit.history
|
131
133
|
```
|
132
134
|
This method answers an array of strings. Entries added to this array are
|
133
|
-
available to the edit instance. For example, the following
|
134
|
-
menacing
|
135
|
+
available to the edit instance. For example, the following adds a rather
|
136
|
+
menacing entry to the history buffer.
|
135
137
|
```ruby
|
136
|
-
|
138
|
+
edit.history << "launch --weapons:nuclear --all"
|
137
139
|
```
|
138
|
-
|
140
|
+
Maybe I should cut back on the Fallout/4?
|
139
141
|
|
140
142
|
### Options
|
141
143
|
In mini_readline, options exist at three levels:
|
@@ -168,6 +170,8 @@ BASE_OPTIONS = {
|
|
168
170
|
:auto_complete => false, #Is auto complete enabled?
|
169
171
|
:auto_source => nil, #Filled in by auto_complete.rb
|
170
172
|
|
173
|
+
:eoi_detect => false, #Is end of input detection enabled?
|
174
|
+
|
171
175
|
:history => false, #Is the history buffer enabled?
|
172
176
|
:no_blanks => true, #No empty lines in history.
|
173
177
|
:no_dups => true, #No duplicate lines in history.
|
@@ -180,7 +184,7 @@ BASE_OPTIONS = {
|
|
180
184
|
<br>While most of these options are self explanatory, a few could stand some
|
181
185
|
further description:
|
182
186
|
* :alt_prompt is the prompt used when the text must be scrolled to fit on the
|
183
|
-
screen.
|
187
|
+
screen. If this is set to nil, then the main prompt is always used.
|
184
188
|
* :auto_complete is disabled by default. Of course there are a number of ways
|
185
189
|
to enable it, or to make auto-complete enabled the default use:
|
186
190
|
```ruby
|
@@ -190,6 +194,9 @@ MiniReadline::BASE_OPTION[:auto_complete] = true
|
|
190
194
|
* :auto_source is the class of the source for auto-complete data. By default this
|
191
195
|
is MiniReadline::FileFolderSource. This option can be changed up to get auto-complete
|
192
196
|
data other than files and folders.
|
197
|
+
* :eoi_detect is used to control the end of input detection logic. If disabled,
|
198
|
+
eoi inputs are treated as unmapped. If enabled, they raise a MiniReadlineEOI
|
199
|
+
exception.
|
193
200
|
* :term is the interactive source of data, the console by default. This can be
|
194
201
|
changed to get data from another source (like a serial attached terminal).
|
195
202
|
|
@@ -12,6 +12,8 @@ module MiniReadline
|
|
12
12
|
:auto_complete => false, #Is auto complete enabled?
|
13
13
|
:auto_source => nil, #Filled in by auto_complete.rb
|
14
14
|
|
15
|
+
:eoi_detect => false, #Is end of input detection enabled?
|
16
|
+
|
15
17
|
:history => false, #Is the history buffer enabled?
|
16
18
|
:no_blanks => true, #No empty lines in history.
|
17
19
|
:no_dups => true, #No duplicate lines in history.
|
@@ -6,6 +6,10 @@ module MiniReadline
|
|
6
6
|
#* file_folder_source.rb - The data source for auto-complete.
|
7
7
|
class FileFolderSource
|
8
8
|
|
9
|
+
#Create a new file/folder auto-data source. NOP
|
10
|
+
def initialize(_options)
|
11
|
+
end
|
12
|
+
|
9
13
|
#Construct a new data list for auto-complete
|
10
14
|
def rebuild(str)
|
11
15
|
@root, pivot = /\S+$/ =~ str ? [$`.to_s, $~.to_s] : [str, ""]
|
@@ -8,23 +8,25 @@ module MiniReadline
|
|
8
8
|
|
9
9
|
#Keep the edit window in sync!
|
10
10
|
def sync_window(edit_buffer, edit_posn)
|
11
|
-
window_buffer.clear unless check_margins(edit_posn)
|
11
|
+
window_buffer.clear unless check_margins(edit_buffer.length, edit_posn)
|
12
12
|
image = build_screen_image(edit_buffer)
|
13
13
|
update_screen(image)
|
14
14
|
@window_buffer = image
|
15
15
|
end
|
16
16
|
|
17
17
|
#Verify/update the window margins. Returns true if they're fine.
|
18
|
-
def check_margins(edit_posn)
|
18
|
+
def check_margins(length, edit_posn)
|
19
19
|
old_margins = [left_margin, right_margin]
|
20
20
|
|
21
|
-
if
|
22
|
-
self.left_margin
|
21
|
+
if length < base_width
|
22
|
+
self.left_margin = 0
|
23
|
+
elsif edit_posn < left_margin
|
24
|
+
self.left_margin = [edit_posn - scroll_step, 0].max
|
23
25
|
elsif edit_posn > right_margin
|
24
26
|
self.right_margin = edit_posn + scroll_step
|
25
27
|
end
|
26
28
|
|
27
|
-
|
29
|
+
old_margins == [left_margin, right_margin]
|
28
30
|
end
|
29
31
|
|
30
32
|
#Compute what should be on the screen.
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#* read_line/window/edit/end_of_input.rb - Process :end_of_input
|
4
|
+
module MiniReadline
|
5
|
+
|
6
|
+
#* read_line/window/edit/end_of_input.rb - Process :end_of_input
|
7
|
+
class Edit
|
8
|
+
|
9
|
+
#The insert_text command. We are DONE!
|
10
|
+
def end_of_input(_keyboard_args)
|
11
|
+
if @options[:eoi_detect]
|
12
|
+
raise MiniReadlineEOI, "EOI Detected."
|
13
|
+
else
|
14
|
+
@term.beep
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/mini_readline.rb
CHANGED
data/sire.rb
CHANGED
@@ -71,6 +71,55 @@ class SIRE
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
+
#Strict Windows Regex.
|
75
|
+
# a File name character, no spaces.
|
76
|
+
# b File name character, with spaces.
|
77
|
+
# c Drive specification.
|
78
|
+
# x Non-quoted file spec.
|
79
|
+
# y Quoted file spec.
|
80
|
+
WRE = %r{
|
81
|
+
(?<a> [^\/\\\:\*\?\<\>\"\s]){0}
|
82
|
+
(?<b> [^\/\\\:\*\?\<\>\"]){0}
|
83
|
+
(?<c> ([a-zA-z]\:)?\\){0}
|
84
|
+
(?<x> \g<c>?(\g<a>*\\?)*){0}
|
85
|
+
(?<y> \"\g<c>?(\g<a>(\g<b>*\g<a>)?\\?)*\"){0}
|
86
|
+
|
87
|
+
(\g<x>|\g<y>)$
|
88
|
+
}x
|
89
|
+
|
90
|
+
#Rubified Windows Regex.
|
91
|
+
# a File name character, no spaces.
|
92
|
+
# b File name character, with spaces.
|
93
|
+
# c Drive specification.
|
94
|
+
# x Non-quoted file spec.
|
95
|
+
# y Quoted file spec.
|
96
|
+
RRE = %r{
|
97
|
+
(?<a> [^\/\\\:\*\?\<\>\"\s]){0}
|
98
|
+
(?<b> [^\/\\\:\*\?\<\>\"]){0}
|
99
|
+
(?<c> ([a-zA-z]\:)?\/){0}
|
100
|
+
(?<x> \g<c>?(\g<a>*\/?)*){0}
|
101
|
+
(?<y> \"\g<c>?(\g<a>(\g<b>*\g<a>)?\/?)*\"){0}
|
102
|
+
|
103
|
+
(\g<x>|\g<y>)$
|
104
|
+
}x
|
105
|
+
|
106
|
+
#Other Platforms Regex.
|
107
|
+
# a File name character, no spaces.
|
108
|
+
# b File name character, with spaces.
|
109
|
+
# c Root specification.
|
110
|
+
# x Non-quoted file spec.
|
111
|
+
# y Quoted file spec.
|
112
|
+
ORE = %r{
|
113
|
+
(?<a> [^\/\\\:\*\?\<\>\"\s]){0}
|
114
|
+
(?<b> [^\/\\\:\*\?\<\>\"]){0}
|
115
|
+
(?<c> \/){0}
|
116
|
+
(?<x> \g<c>?(\g<a>*\/?)*){0}
|
117
|
+
(?<y> \"\g<c>?(\g<a>(\g<b>*\g<a>)?\/?)*\"){0}
|
118
|
+
|
119
|
+
(\g<x>|\g<y>)$
|
120
|
+
}x
|
121
|
+
|
122
|
+
|
74
123
|
#Execute a single line.
|
75
124
|
def exec_line(line)
|
76
125
|
result = eval line
|
@@ -99,6 +148,9 @@ class SIRE
|
|
99
148
|
end
|
100
149
|
|
101
150
|
puts "\n\n"
|
151
|
+
|
152
|
+
rescue Interrupt => e
|
153
|
+
puts "\n"
|
102
154
|
end
|
103
155
|
|
104
156
|
end
|
@@ -54,6 +54,12 @@ class MiniReadlineTester < Minitest::Test
|
|
54
54
|
assert_equal("quit", result)
|
55
55
|
end
|
56
56
|
|
57
|
+
def test_end_of_input_detection
|
58
|
+
edit = MiniReadline::Readline.new()
|
59
|
+
puts "Exit by signaling end of input"
|
60
|
+
assert_raises(MiniReadlineEOI) {edit.readline(">", eoi_detect: true)}
|
61
|
+
end
|
62
|
+
|
57
63
|
def test_prompt_verification
|
58
64
|
opts = {:window_width => 39}
|
59
65
|
edit = MiniReadline::Readline.new()
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_readline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Camilleri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- README.md
|
82
82
|
- Rakefile
|
83
83
|
- lib/mini_readline.rb
|
84
|
+
- lib/mini_readline/exceptions.rb
|
84
85
|
- lib/mini_readline/options.rb
|
85
86
|
- lib/mini_readline/raw_term.rb
|
86
87
|
- lib/mini_readline/raw_term/mapper.rb
|
@@ -102,6 +103,7 @@ files:
|
|
102
103
|
- lib/mini_readline/read_line/edit/edit_window.rb
|
103
104
|
- lib/mini_readline/read_line/edit/edit_window/sync_cursor.rb
|
104
105
|
- lib/mini_readline/read_line/edit/edit_window/sync_window.rb
|
106
|
+
- lib/mini_readline/read_line/edit/end_of_input.rb
|
105
107
|
- lib/mini_readline/read_line/edit/enter.rb
|
106
108
|
- lib/mini_readline/read_line/edit/go_end.rb
|
107
109
|
- lib/mini_readline/read_line/edit/go_home.rb
|