mini_readline 0.1.1 → 0.1.3

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
  SHA1:
3
- metadata.gz: eeadfb80cae515eb0fb0b55dde44df6e84025f8e
4
- data.tar.gz: a299a996d90db9ca83680c01917a78798710cfd6
3
+ metadata.gz: 634b35a4a125886de4969dd4f807fdf2b35e5ec3
4
+ data.tar.gz: d6be43dd1584f371fea17f7600ee5b5e49ccefc4
5
5
  SHA512:
6
- metadata.gz: 0654a25c5f4e36736df2e22f3394509ea10811c5ac43c8f73dba1a7e20b0ff2663910ff227329f491dcf99a5b0123c91e6e6a517e543055288f41f38b95206c2
7
- data.tar.gz: f0519c20d588ae84c4d3496e697f61ca4a5d84f732b10010155790d057b940f54419e98aca6d207ce0db25a365b74514b952764460cda96c3baf9d802d599e50
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 makes a rather
134
- menacing part of the history buffer.
135
+ available to the edit instance. For example, the following adds a rather
136
+ menacing entry to the history buffer.
135
137
  ```ruby
136
- hist << "launch --weapons:nuclear --all"
138
+ edit.history << "launch --weapons:nuclear --all"
137
139
  ```
138
- <br>Maybe I should cut back on the Fallout/4?
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
 
@@ -0,0 +1,5 @@
1
+ # coding: utf-8
2
+
3
+ #The exception raised when an enabled EOI is detected in a readline operation.
4
+ class MiniReadlineEOI < StandardError
5
+ end
@@ -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.
@@ -59,5 +59,8 @@ module MiniReadline
59
59
 
60
60
  #The Cancel key
61
61
  MAP["\f"] = [:cancel]
62
+
63
+ #End of Input
64
+ MAP["\ez"] = [:end_of_input]
62
65
  end
63
66
  end
@@ -38,6 +38,8 @@ module MiniReadline
38
38
  end
39
39
 
40
40
  #Sound a beep
41
+ #<br>Endemic Code Smells
42
+ #* :reek:UtilityFunction
41
43
  def beep
42
44
  $stderr.write(BELL)
43
45
  $stderr.flush
@@ -56,5 +56,8 @@ module MiniReadline
56
56
 
57
57
  #The Escape key
58
58
  MAP["\x1B"] = [:cancel]
59
+
60
+ #End of Input
61
+ MAP["\x1A"] = [:end_of_input]
59
62
  end
60
63
  end
@@ -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, ""]
@@ -29,7 +29,7 @@ module MiniReadline
29
29
 
30
30
  #Get the auto-complete manager
31
31
  def auto_manager
32
- @_auto_manager ||= AutoManager.new { @options[:auto_source].new }
32
+ @_auto_manager ||= AutoManager.new{@options[:auto_source].new(@options)}
33
33
  end
34
34
  end
35
35
 
@@ -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 edit_posn < left_margin
22
- self.left_margin = [edit_posn - scroll_step, 0].max
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
- old_margins == [left_margin, right_margin]
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
@@ -22,6 +22,7 @@ require_relative 'edit/previous_history'
22
22
  require_relative 'edit/next_history'
23
23
 
24
24
  require_relative 'edit/auto_complete'
25
+ require_relative 'edit/end_of_input'
25
26
 
26
27
  require_relative 'edit/unmapped'
27
28
 
@@ -1,4 +1,4 @@
1
1
  module MiniReadline
2
2
  #The current version of the mini_readline gem.
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.3"
4
4
  end
data/lib/mini_readline.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # coding: utf-8
2
2
 
3
3
  require_relative "mini_readline/version"
4
+ require_relative "mini_readline/exceptions"
4
5
  require_relative "mini_readline/options"
5
6
  require_relative "mini_readline/raw_term"
6
7
  require_relative "mini_readline/read_line"
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.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-15 00:00:00.000000000 Z
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