mini_readline 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -5
- data/lib/mini_readline/read_line.rb +6 -5
- data/lib/mini_readline/read_line/edit/edit_window.rb +1 -1
- data/lib/mini_readline/read_line/edit/edit_window/sync_window.rb +13 -4
- data/lib/mini_readline/read_line/prompt.rb +28 -0
- data/lib/mini_readline/version.rb +1 -1
- data/sire.rb +1 -1
- data/tests/mini_readline_tests.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f85684d28ccc8db527dfffaa18a44cacc0d895a
|
4
|
+
data.tar.gz: 10ab8d5a4e563e544b421348932e9955db9e2ba5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6066051c11226c1910cffc07230c43c222968f52bd48589b6f2f40688ad88e51e1e51cc42880fe68f6d8a4df4658a71eefe047807ae57a67c8e153121d765515
|
7
|
+
data.tar.gz: d8c18d10e928dadb05d629f8a0957b679a78d51642c7312f7667dbd6092728bc8dcb142fa2f5e72dfe26473284921765d4d58332c7c2c38082093c6286548fc5
|
data/README.md
CHANGED
@@ -180,17 +180,21 @@ BASE_OPTIONS = {
|
|
180
180
|
|
181
181
|
<br>While most of these options are self explanatory, a few could stand some
|
182
182
|
further description:
|
183
|
+
* :prompt is the standard prompt used when text is not scrolled.
|
183
184
|
* :alt_prompt is the prompt used when the text must be scrolled to fit on the
|
184
185
|
screen. If this is set to nil, then the main prompt is always used.
|
186
|
+
<br>Both the prompt and alt_prompt may contain ANSI terminal control sequences.
|
187
|
+
These are restricted, however, to those commands that do not alter the position
|
188
|
+
of the cursor. So basically colors, highlighting, etc.
|
185
189
|
* :auto_complete is disabled by default. Of course there are a number of ways
|
186
190
|
to enable it, or to make auto-complete enabled the default use:
|
187
191
|
```ruby
|
188
192
|
require 'mini_readline'
|
189
193
|
MiniReadline::BASE_OPTION[:auto_complete] = true
|
190
194
|
```
|
191
|
-
* :auto_source is the class of the source for auto-complete data. By default
|
192
|
-
is MiniReadline::QuotedFileFolderSource. This option can be changed up to
|
193
|
-
auto-complete data other than files and folders. See Auto-Compete below for
|
195
|
+
* :auto_source is the class of the source for auto-complete data. By default
|
196
|
+
this is MiniReadline::QuotedFileFolderSource. This option can be changed up to
|
197
|
+
get auto-complete data other than files and folders. See Auto-Compete below for
|
194
198
|
more details.
|
195
199
|
* :eoi_detect is used to control the end of input detection logic. If disabled,
|
196
200
|
eoi inputs are treated as unmapped. If enabled, they raise a MiniReadlineEOI
|
@@ -261,7 +265,7 @@ the initialize, rebuild, and next methods.
|
|
261
265
|
|
262
266
|
end
|
263
267
|
```
|
264
|
-
To enable the use of a custom auto-completer, three things
|
268
|
+
To enable the use of a custom auto-completer, three things must be done:
|
265
269
|
* The option[:auto_complete] must be set to true
|
266
270
|
* The option[:auto_source] must be set to the class name of the new completer.
|
267
271
|
* Any optional, additional options required by the completer must be set.
|
@@ -325,7 +329,8 @@ To date this code has been tested under:
|
|
325
329
|
* Windows 7 with ruby 2.1.6p336 (2015-04-13 revision 50298) [i386-mingw32]
|
326
330
|
* Windows 7+Cygwin with ruby 2.2.3p173 (2015-08-18 revision 51636) [i386-cygwin]
|
327
331
|
|
328
|
-
<br>**More testing is clearly called for and suggestions/bug reports are most
|
332
|
+
<br>**More testing is clearly called for and suggestions/bug reports are most
|
333
|
+
welcomed!!!**
|
329
334
|
|
330
335
|
## Contributing
|
331
336
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
+
require_relative 'read_line/prompt'
|
3
4
|
require_relative 'read_line/edit'
|
4
5
|
require_relative 'read_line/history'
|
5
6
|
require_relative 'read_line/no_history'
|
@@ -63,18 +64,18 @@ module MiniReadline
|
|
63
64
|
|
64
65
|
#Set up the prompt.
|
65
66
|
def set_prompt(prompt)
|
66
|
-
@options[:base_prompt] = prompt
|
67
|
-
@options[:scroll_prompt] = @options[:alt_prompt] || prompt
|
67
|
+
@options[:base_prompt] = Prompt.new(prompt)
|
68
|
+
@options[:scroll_prompt] = Prompt.new(@options[:alt_prompt] || prompt)
|
68
69
|
|
69
70
|
verify_prompt(@options[:base_prompt])
|
70
71
|
verify_prompt(@options[:scroll_prompt])
|
71
72
|
end
|
72
73
|
|
73
74
|
#Verify that the prompt will fit!
|
74
|
-
def verify_prompt(
|
75
|
-
unless (@options[:window_width] -
|
75
|
+
def verify_prompt(prompt)
|
76
|
+
unless (@options[:window_width] - prompt.length) >
|
76
77
|
(@options[:scroll_step] * 2)
|
77
|
-
fail "
|
78
|
+
fail "Too long: #{prompt.inspect}"
|
78
79
|
end
|
79
80
|
end
|
80
81
|
end
|
@@ -16,7 +16,7 @@ module MiniReadline
|
|
16
16
|
@scroll_width = window_width - @options[:scroll_prompt].length
|
17
17
|
@term = @options[:term]
|
18
18
|
|
19
|
-
@left_margin, @window_buffer = 0, ""
|
19
|
+
@left_margin, @window_buffer, @show_prompt = 0, "", true
|
20
20
|
end
|
21
21
|
|
22
22
|
#What is the offset of the window's left margin?
|
@@ -8,7 +8,11 @@ module MiniReadline
|
|
8
8
|
|
9
9
|
#Keep the edit window in sync!
|
10
10
|
def sync_window(edit_buffer, edit_posn)
|
11
|
-
|
11
|
+
unless check_margins(edit_buffer.length, edit_posn)
|
12
|
+
window_buffer.clear
|
13
|
+
@show_prompt = true
|
14
|
+
end
|
15
|
+
|
12
16
|
image = build_screen_image(edit_buffer)
|
13
17
|
update_screen(image)
|
14
18
|
@window_buffer = image
|
@@ -31,14 +35,19 @@ module MiniReadline
|
|
31
35
|
|
32
36
|
#Compute what should be on the screen.
|
33
37
|
def build_screen_image(edit_buffer)
|
34
|
-
|
38
|
+
edit_buffer[left_margin..right_margin].ljust(active_width)
|
35
39
|
end
|
36
40
|
|
37
41
|
#Bring the screen into agreement with the image.
|
38
42
|
def update_screen(image)
|
39
|
-
|
43
|
+
if @show_prompt
|
44
|
+
@term.put_string("\r#{prompt.text}\r")
|
45
|
+
@show_prompt = false
|
46
|
+
end
|
47
|
+
|
48
|
+
(0...active_width).each do |index|
|
40
49
|
if (image_char = image[index]) != window_buffer[index]
|
41
|
-
@term.set_posn(index)
|
50
|
+
@term.set_posn(prompt.length + index)
|
42
51
|
@term.put_string(image_char)
|
43
52
|
end
|
44
53
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#Support for the specialized prompt string class.
|
4
|
+
module MiniReadline
|
5
|
+
|
6
|
+
#A class used to hold prompt strings that may contain ANSI terminal
|
7
|
+
#control embellishments.
|
8
|
+
class Prompt
|
9
|
+
|
10
|
+
#Get the text.
|
11
|
+
attr_reader :text
|
12
|
+
|
13
|
+
#Get the length without ANSI sequences.
|
14
|
+
attr_reader :length
|
15
|
+
|
16
|
+
def initialize(text)
|
17
|
+
@text = text
|
18
|
+
@length = text.gsub(/\x1B\[(\d|;)*[@-~]/, "").length
|
19
|
+
end
|
20
|
+
|
21
|
+
#Inspect the prompt
|
22
|
+
def inspect
|
23
|
+
"<Prompt: #{@text.inspect}>"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/sire.rb
CHANGED
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.
|
4
|
+
version: 0.4.0
|
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-02-
|
11
|
+
date: 2016-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- lib/mini_readline/read_line/edit/word_right.rb
|
120
120
|
- lib/mini_readline/read_line/history.rb
|
121
121
|
- lib/mini_readline/read_line/no_history.rb
|
122
|
+
- lib/mini_readline/read_line/prompt.rb
|
122
123
|
- lib/mini_readline/version.rb
|
123
124
|
- mini_readline.gemspec
|
124
125
|
- mini_readline.reek
|