mini_readline 0.3.1 → 0.3.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: fdfa436a71940734402798fef36869a990280c8a
4
- data.tar.gz: 3d895f85d7c7f8a965362068aed8728fec2536c5
3
+ metadata.gz: af31e49431ef4c0e691617e54b7a49682f0ff54c
4
+ data.tar.gz: 2d8eec7c4e57644c35e8c48eb64f59de7eaa0be7
5
5
  SHA512:
6
- metadata.gz: 558703724da30c6794aa066ded902f72a1a41496b5fb88b2ac05cace0baa4021e06b4b2b03bf8a0f7db1edeabc87773a36f5e3595fe0fe11c583e56047bba3b1
7
- data.tar.gz: e219431676db413815d454a5b4d9c6996ad71d20552f22c0df75130954413aa55ca419cf705aa6f96c1c0a960b760956e9b7af183e2dc905b835868ed64ed1b7
6
+ metadata.gz: faa8d05392d4f11c966b5a3e803701a4e6830f2e734ce75907563642d3f5985baec7d44db4c3534b04156b2da7091f4bc588074358f287e888f530dc5e3e754a
7
+ data.tar.gz: 6473692e2bfa5b592e64dd30afb51ec6314690de7ebeb91dc622a6f23f029027a913a5a7440a1edae0a3d2c11d7272a64a00b8bc6117cecebee7172933b40bde
data/README.md CHANGED
@@ -5,7 +5,8 @@ inline editing and command history.
5
5
 
6
6
  The mini readline gem is an experiment in replacing the standard readline gem
7
7
  that is part of Ruby. The mini readline will focus on the needs of Ruby programs
8
- as opposed to a UN*X shell program.
8
+ as opposed to a UN*X shell program. It will also try to correct a number of
9
+ irritating issues encountered when running under a Windows platform.
9
10
 
10
11
  The mini_readline gem is designed for use with MRI version 1.9.3 or later.
11
12
  The original readline tried to support older versions of Ruby.
@@ -188,13 +189,18 @@ require 'mini_readline'
188
189
  MiniReadline::BASE_OPTION[:auto_complete] = true
189
190
  ```
190
191
  * :auto_source is the class of the source for auto-complete data. By default this
191
- is MiniReadline::FileFolderSource. This option can be changed up to get auto-complete
192
- data other than files and folders. See Auto-Compete below for more details.
192
+ is MiniReadline::QuotedFileFolderSource. This option can be changed up to get
193
+ auto-complete data other than files and folders. See Auto-Compete below for
194
+ more details.
193
195
  * :eoi_detect is used to control the end of input detection logic. If disabled,
194
196
  eoi inputs are treated as unmapped. If enabled, they raise a MiniReadlineEOI
195
197
  exception.
196
- * :term is the interactive source of data, the console by default. This can be
197
- changed to get data from another source (like a serial attached terminal).
198
+ * :term is the interactive source of data, the console by default. The raw
199
+ terminal console driver automatically adapts to the system environment
200
+ (Windows or Other) so that correct operation is normally achieved with no
201
+ further actions on the part of the user. The terminal support class can be
202
+ changed, to a user supplied class, to get data from another source, such as
203
+ a serial attached terminal.
198
204
 
199
205
  #### Notes
200
206
  * Since the compatibility mode does not accept an options hash, the only way to
@@ -205,15 +211,67 @@ the environment and plugs in the needed object. This can be overridden where
205
211
  special io needs exist.
206
212
 
207
213
  ### Auto-Complete
208
- The mini readline gem comes with two auto-complete engines. These are:
214
+ The mini readline gem comes with three auto-complete engines. These are:
209
215
  * MiniReadline::ArraySource - Make a selection from an array of choices. That
210
216
  array is found in the option :array_src. This can either be an array of
211
217
  strings or a proc (or lambda) that returns an array of strings.
212
218
  * MiniReadline::FileFolderSource - A simple, in-line auto-complete for files
213
219
  and folders that do **not** contain embedded spaces.
214
220
  * MiniReadline::QuotedFileFolderSource - A simple, in-line auto-complete for
215
- files and folders embedded in quotes "foo bar.rb" that may contain spaces.
216
- This is the default auto-complete data source.
221
+ files and folders embedded in quotes. For example "foo bar.rb". Note that the
222
+ file names may contain spaces. This is the default auto-complete data source.
223
+
224
+ ### Adding Custom Auto-Completers
225
+ It is possible, and fairly straightforward to add application specific
226
+ auto-completers to mini readline. To show how this might be done, the
227
+ File and Folder data source is shown. Essential components of this class are
228
+ the initialize, rebuild, and next methods.
229
+
230
+ ```ruby
231
+ class FileFolderSource
232
+
233
+ #Create a new file/folder auto-data source. NOP
234
+ def initialize(options)
235
+ # Save or ignore the options hash.
236
+ end
237
+
238
+ #Construct a new data list for auto-complete given the current contents
239
+ #of the mini_readline edit buffer. Return true-ish for success and
240
+ #false-ish for failure.
241
+ def rebuild(str)
242
+ extract_root_pivot(str)
243
+
244
+ list = Dir.glob(@pivot + '*')
245
+
246
+ @cycler = list.empty? ? nil : list.cycle
247
+ end
248
+
249
+ #Parse the string into the two basic components. This is not part of the
250
+ #protocol but is included to give an example of splitting the invariant
251
+ #(root) part of the buffer from the variable (pivot) part.
252
+ def extract_root_pivot(str)
253
+ @root, @pivot = /\S+$/ =~ str ? [$PREMATCH, $MATCH] : [str, ""]
254
+ end
255
+
256
+ #Get the next string for auto-complete. Note that this is the entire
257
+ #string, not just the pivot bit at the end.
258
+ def next
259
+ @root + @cycler.next
260
+ end
261
+
262
+ end
263
+ ```
264
+ To enable the use of a custom auto-completer, three things mst be done:
265
+ * The option[:auto_complete] must be set to true
266
+ * The option[:auto_source] must be set to the class name of the new completer.
267
+ * Any optional, additional options required by the completer must be set.
268
+
269
+ <br> See the section Options above for more details on setting/controlling
270
+ options.
271
+
272
+ <br>Note: Elsewhere in the code above there exists a require 'English'
273
+ statement to permit the use of clearer, easier to read access to regular
274
+ expression results.
217
275
 
218
276
  ## Demo
219
277
  A simple demo of mini_readline in action is available. To access this demo use
@@ -17,11 +17,7 @@ module MiniReadline
17
17
 
18
18
  list = (get_array.select {|str| str.start_with?(@pivot)}).sort
19
19
 
20
- unless list.empty?
21
- @cycler = list.cycle
22
- else
23
- @cycler = nil
24
- end
20
+ @cycler = list.empty? ? nil : list.cycle
25
21
  end
26
22
 
27
23
  #Parse the string into the two basic components.
@@ -15,11 +15,7 @@ module MiniReadline
15
15
 
16
16
  list = Dir.glob(@pivot + '*')
17
17
 
18
- unless list.empty?
19
- @cycler = list.cycle
20
- else
21
- @cycler = nil
22
- end
18
+ @cycler = list.empty? ? nil : list.cycle
23
19
  end
24
20
 
25
21
  #Parse the string into the two basic components.
@@ -15,11 +15,7 @@ module MiniReadline
15
15
 
16
16
  list = Dir.glob(@pivot + '*')
17
17
 
18
- unless list.empty?
19
- @cycler = list.cycle
20
- else
21
- @cycler = nil
22
- end
18
+ @cycler = list.empty? ? nil : list.cycle
23
19
  end
24
20
 
25
21
  #The parsing regular expression.
@@ -60,5 +60,20 @@ module MiniReadline
60
60
  def scroll_step
61
61
  @options[:scroll_step]
62
62
  end
63
+
64
+ private
65
+
66
+ #Set the left margin
67
+ def set_left_margin(value)
68
+ @left_margin = value
69
+ end
70
+
71
+ #Set the right margin
72
+ #<br>Notes
73
+ #* If the right_margin is being set, then we must be scrolling. That is
74
+ # why the scroll_width is used instead of active_width here.
75
+ def set_right_margin(value)
76
+ @left_margin = value - scroll_width + 1
77
+ end
63
78
  end
64
79
  end
@@ -43,20 +43,5 @@ module MiniReadline
43
43
  end
44
44
  end
45
45
  end
46
-
47
- private
48
-
49
- #Set the left margin
50
- def set_left_margin(value)
51
- @left_margin = value
52
- end
53
-
54
- #Set the right margin
55
- #<br>Notes
56
- #* If the right_margin is being set, then we must be scrolling. That is
57
- # why the scroll_width is used instead of active_width here.
58
- def set_right_margin(value)
59
- @left_margin = value - scroll_width + 1
60
- end
61
46
  end
62
47
  end
@@ -9,7 +9,7 @@ module MiniReadline
9
9
  #The insert_text command. We are DONE!
10
10
  def end_of_input(_keyboard_args)
11
11
  if @options[:eoi_detect]
12
- raise MiniReadlineEOI, "EOI Detected."
12
+ raise MiniReadlineEOI, "End of input detected."
13
13
  else
14
14
  @term.beep
15
15
  end
@@ -1,4 +1,4 @@
1
1
  module MiniReadline
2
2
  #The current version of the mini_readline gem.
3
- VERSION = "0.3.1"
3
+ VERSION = "0.3.3"
4
4
  end
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.required_ruby_version = '>=1.9.3'
27
27
 
28
28
  spec.add_development_dependency "minitest", ">= 5.7"
29
- spec.add_development_dependency "minitest_visible", ">= 0.0.2"
29
+ spec.add_development_dependency "minitest_visible", ">= 0.1.0"
30
30
  spec.add_development_dependency "bundler", "~> 1.11"
31
31
  spec.add_development_dependency "rake", "~> 10.0"
32
32
  end
data/mini_readline.reek CHANGED
@@ -103,6 +103,9 @@ UncommunicativeVariableName:
103
103
  UnusedParameters:
104
104
  enabled: true
105
105
  exclude: []
106
+ UnusedPrivateMethod:
107
+ enabled: false
108
+ exclude: []
106
109
  UtilityFunction:
107
110
  enabled: true
108
111
  exclude: []
data/sire.rb CHANGED
@@ -5,6 +5,7 @@ require 'pp'
5
5
 
6
6
  if ARGV[0] == 'old'
7
7
  require 'readline'
8
+ $old = true
8
9
  puts "\nOption(old). Loaded the standard readline gem. Version #{Readline::VERSION}"
9
10
  elsif ARGV[0] == 'local'
10
11
  require './lib/mini_readline'
@@ -59,8 +60,12 @@ class SIRE
59
60
 
60
61
  #Get a mapped keystroke.
61
62
  def g
62
- print 'Press a key:'
63
- MiniReadline::BASE_OPTIONS[:term].get_mapped_keystroke
63
+ if $old
64
+ print 'Not supported by old readline.'
65
+ else
66
+ print 'Press a key:'
67
+ MiniReadline::BASE_OPTIONS[:term].get_mapped_keystroke
68
+ end
64
69
  end
65
70
 
66
71
  #Test spawning a process. This breaks the regular readline gem.
@@ -90,22 +95,22 @@ class SIRE
90
95
 
91
96
  #Run the interactive session.
92
97
  def run_sire
93
- edit = MiniReadline::Readline.new(prompt: 'SIRE>',
94
- auto_complete: true,
95
- history: true,
96
- eoi_detect: true)
98
+ unless $old
99
+ MiniReadline::BASE_OPTIONS[:auto_complete] = true
100
+ MiniReadline::BASE_OPTIONS[:eoi_detect] = true
101
+ end
97
102
 
98
103
  puts
99
104
  puts "Welcome to a Simple Interactive Ruby Environment\n"
100
105
  puts "Use the command 'q' to quit.\n\n"
101
106
 
102
107
  until @_done
103
- exec_line(edit.readline)
108
+ exec_line(Readline.readline('SIRE>', true))
104
109
  end
105
110
 
106
111
  puts "\n\n"
107
112
 
108
- rescue MiniReadlineEOI, Interrupt => e
113
+ rescue StandardError, Interrupt => e
109
114
  puts "\n"
110
115
  end
111
116
 
@@ -9,7 +9,7 @@ require 'minitest_visible'
9
9
  class MiniReadlineTester < Minitest::Test
10
10
 
11
11
  #Track mini-test progress.
12
- MinitestVisible.track self, __FILE__
12
+ include MinitestVisible
13
13
 
14
14
  def test_that_module_entities_exists
15
15
  assert_equal(Module, MiniReadline.class)
@@ -107,6 +107,25 @@ class MiniReadlineTester < Minitest::Test
107
107
  assert(fruit.include?(result))
108
108
  end
109
109
 
110
+ def test_file_auto
111
+ puts "\nPlease select an unquoted file."
112
+
113
+ edit = MiniReadline::Readline.new(auto_complete: true,
114
+ auto_source: MiniReadline::FileFolderSource)
115
+
116
+ result = edit.readline(prompt: "File: ")
117
+ assert(result.is_a?(String))
118
+ end
119
+
120
+ def test_file_quoated
121
+ puts "\nPlease select an quoted file."
122
+
123
+ edit = MiniReadline::Readline.new(auto_complete: true,
124
+ auto_source: MiniReadline::QuotedFileFolderSource)
125
+
126
+ result = edit.readline(prompt: "File: ")
127
+ assert(result.is_a?(String))
128
+ end
110
129
 
111
130
  def test_end_of_input_detection
112
131
  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.3.1
4
+ version: 0.3.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-28 00:00:00.000000000 Z
11
+ date: 2016-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.0.2
33
+ version: 0.1.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.0.2
40
+ version: 0.1.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -150,3 +150,4 @@ signing_key:
150
150
  specification_version: 4
151
151
  summary: A simplified replacement for readline.
152
152
  test_files: []
153
+ has_rdoc: