mini_readline 0.9.0 → 0.9.5

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
- SHA1:
3
- metadata.gz: 13d29a79c8b695d0491081997bfd2f78c2d6b6f4
4
- data.tar.gz: a13e598d917734a3448e4d9316aee17cabc701b3
2
+ SHA256:
3
+ metadata.gz: 33cf8359aa2da932030ed129ee92904857f87e85fb7e5b12d819b1a5029cbff6
4
+ data.tar.gz: 165b10fc4c40b9a22b213530d065300d3f5404b8f6cf7cd738546db27bd149d7
5
5
  SHA512:
6
- metadata.gz: a92268026fa1ac6abfd573cb6debd80b4055fbe047dd58bae5a666f39745831397c089b54615537ad1aee765a19d480375fe208234ca2f957bb640abb46c2570
7
- data.tar.gz: 568fa17fc7a40b0bf8f4bc7d01214e947f1503b8f49166a56636c049be91b595fd7284b86499942a91187cf75049855cc8eb0a13815400f56cf2ba2c3f6a7b1c
6
+ metadata.gz: dbf6fe9f4bc027f2a8d45ed09837c61f01a247a25e446e4eb04ed81865460f726c6ada4bee7c0c5abad9fea20baddf7a510f5170ba62c02163095df7232f33ff
7
+ data.tar.gz: 5b4efbf6bb03be62b5ffa9214c41ec4f0db467dafcf1b7db7fa5a120454f495c6997777536c22ee9ac8ab2fb07c840f8a4c206a85e59b20181f7eb8657b6000f
data/.reek.yml ADDED
@@ -0,0 +1,17 @@
1
+ ---
2
+
3
+ ### Generic smell configuration
4
+
5
+ detectors:
6
+
7
+ TooManyStatements:
8
+ max_statements: 7
9
+
10
+ InstanceVariableAssumption:
11
+ enabled: false
12
+
13
+ TooManyMethods:
14
+ enabled: true
15
+
16
+ LongParameterList:
17
+ max_params: 3
data/README.md CHANGED
@@ -6,11 +6,24 @@ inline editing, command history, and stock or customizable auto-complete.
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 project will try to focus on the needs
8
8
  of Ruby programs. It will also try to correct a number of irritating issues
9
- encountered when running cross platform environments. See Cross Platform
10
- Portability Progress below for more details.
11
-
12
- Finally, I know this code must seem to give off a sort of angry birds vibe
13
- against the original rb-readline gem. This sort of thing is not good. I owe
9
+ encountered when running cross platform environments. This is achieved through
10
+ the use of the mini_term gem that deals with the mess of getting proper access
11
+ to the low-level "terminal".
12
+
13
+ While the standard readline gem tries its best to be compatible with the GNU
14
+ Readline library written in "C", mini_readline does not. Instead it takes on
15
+ the goal of being best suited to the needs of Ruby programmers. While this
16
+ makes it much less useful to those porting over Unix/Linux utilities, it makes
17
+ it more useful to Ruby programmers creating CLI utilities in that language.
18
+
19
+ Further, while spread out over a much larger number of smaller, manageable
20
+ files, mini readline has only 1238 lines of code. In fact, only two files have
21
+ more than 100 lines in total. The rb-readline gem has a much larger 9480 lines
22
+ of code with 8920 of them in a single, monster file. While the smaller files do
23
+ have some downsides, bloated files are, in my opinion, worse.
24
+
25
+ Finally, I know this whole effort must seem to give off a sort of angry birds
26
+ vibe against the original rb-readline gem. That is not my intent at all. I owe
14
27
  a great debt of gratitude to the authors and maintainers of that vital code.
15
28
  Their getting around the whole Win32API, dl obsolescence debacle saved me so
16
29
  much time and frustration that words do not suffice. Thanks!
@@ -64,6 +77,8 @@ replaced by Escape followed by the appropriate letter.
64
77
  * References to Pad keys under Windows assume that Num Lock is not engaged.
65
78
  * Support for End of Input is controlled by the eoi_detect option. See options
66
79
  below.
80
+ * These keyboard mappings are the standard ones included with mini_readline.
81
+ See the section Adding Custom Key Maps below for more info.
67
82
 
68
83
  ## Usage
69
84
 
@@ -203,30 +218,35 @@ entries.
203
218
 
204
219
  <br>The available options are described below:
205
220
  ```ruby
221
+ # The base options shared by all instances.
206
222
  BASE_OPTIONS = {
207
- :scroll_step => 12, #The amount horizontally scrolled.
223
+ :scroll_step => 12, # The amount scrolled.
224
+
225
+ :prompt => ">", # The default prompt.
226
+ :alt_prompt => "<< ", # The prompt when scrolled.
227
+ # Set to nil to use main prompt.
208
228
 
209
- :prompt => ">", #The default prompt.
210
- :alt_prompt => "<< ", #The prompt when scrolled.
211
- #Set to nil for no alt prompt.
229
+ :auto_complete => false, # Is auto complete enabled?
230
+ :auto_source => nil, # Filled in by auto_complete.rb
231
+ # MiniReadline::QuotedFileFolderSource
212
232
 
213
- :auto_complete => false, #Is auto complete enabled?
214
- :auto_source => nil, #Filled in by auto_complete.rb
215
- #MiniReadline::QuotedFileFolderSource
233
+ :chomp => false, # Remove the trailing new-line?
216
234
 
217
- :eoi_detect => false, #Is end of input detection enabled?
235
+ :eoi_detect => false, # Is end of input detection enabled?
218
236
 
219
- :history => false, #Is the history buffer enabled?
220
- :log => [], #Default is no previous history
221
- :no_blanks => true, #No empty lines in history.
222
- :no_dups => true, #No duplicate lines in history.
237
+ :history => false, # Is the history buffer enabled?
238
+ :log => [], # Default is no previous history
239
+ :no_blanks => true, # No empty lines in history.
240
+ :no_dups => true, # No duplicate lines in history.
241
+ :no_move => false, # Don't move history entries.
223
242
 
224
- :secret_mask => nil, #No secret password mask. Use the
225
- #string "*" to use stars or " "
226
- #for invisible secrets.
243
+ :secret_mask => nil, # No secret password mask. Use the
244
+ # string "*" to use stars or " "
245
+ # for invisible secrets.
227
246
 
228
- :initial => ""} #The initial text for the entry.
229
- #An empty string for none.
247
+ :initial => "" # The initial text for the entry.
248
+ # An empty string for none.
249
+ }
230
250
  ```
231
251
 
232
252
  <br>While most of these options are self explanatory, a few could stand some
@@ -247,9 +267,17 @@ MiniReadline::BASE_OPTION[:auto_complete] = true
247
267
  this is MiniReadline::QuotedFileFolderSource. This option can be changed up to
248
268
  get auto-complete data other than files and folders. See Auto-Compete below for
249
269
  more details.
270
+ * :chomp is used to remove the trailing new-line character that garnishes the
271
+ text from the user. Set to true for clean text, and to false for parsley to
272
+ throw out.
250
273
  * :eoi_detect is used to control the end of input detection logic. If disabled,
251
274
  eoi inputs are treated as unmapped. If enabled, they raise a MiniReadlineEOI
252
275
  exception.
276
+ * A few options control the history buffer. With the history option on, lines
277
+ entered are retained in a buffer. Otherwise, no record is kept of entered text.
278
+ When no_blanks is set, blank lines are not saved. When no_dups is set,
279
+ duplicate lines are not saved. If so, when duplicates do occur, the no_move
280
+ option keeps the older copy. Otherwise the newer copy is retained.
253
281
  * :secret_mask is a masking character to be used for sensitive input like a
254
282
  password or missile launch code. This should be exactly one character long.
255
283
  Typical values are "\*" or " ". Also, any secret entries should be done with
@@ -261,11 +289,6 @@ specified text. Leave as an empty string to default to the empty edit area.
261
289
  Finally the :window_width option is now ignored. Screen width now automatically
262
290
  determined.
263
291
 
264
-
265
- #### Notes
266
- * Since the compatibility mode does not accept an options hash, the only way to
267
- affect options in this case is to modify the MiniReadline::BASE_OPTIONS hash.
268
-
269
292
  ### Auto-Complete
270
293
  The mini readline gem comes with four auto-complete engines. These are:
271
294
 
@@ -346,7 +369,55 @@ statement to permit the use of clearer, easier to read access to regular
346
369
  expression results.
347
370
 
348
371
  <br> An example of a custom auto-complete facility may be found in the mysh
349
- gem located at: https://github.com/PeterCamilleri/mysh/blob/master/lib/mysh/user_input/smart_source.rb
372
+ gem located at: https://github.com/PeterCamilleri/mysh/blob/master/lib/mysh/sources/smart_auto_complete.rb
373
+
374
+ ### Adding Custom Key Maps
375
+ It is possible to override the default keyboard maps used by the mini_readline
376
+ gem. The following shows the installation of a retro, WordStar&#8482; inspired
377
+ keyboard mapping for a Windows system:
378
+
379
+ ```ruby
380
+ MiniTerm.add_map(:windows) do |map|
381
+ map[" ".."~"] = :insert_text
382
+
383
+ #Left Arrows
384
+ map["\x13"] = :go_left
385
+ map["\x01"] = :word_left
386
+
387
+ #Right Arrows
388
+ map["\x04"] = :go_right
389
+ map["\x06"] = :word_right
390
+
391
+ #Up Arrows
392
+ map["\x05"] = :previous_history
393
+
394
+ #Down Arrows
395
+ map["\x18"] = :next_history
396
+
397
+ #The Home and End keys
398
+ map["\x17"] = :go_home
399
+ map["\x12"] = :go_end
400
+
401
+ #The Backspace and Delete keys
402
+ map["\x08"] = :delete_left
403
+ map["\x7F"] = :delete_right
404
+ map["\x11\x13"] = :delete_all_left
405
+ map["\x11\x04"] = :delete_all_right
406
+
407
+ #Auto-completion.
408
+ map["\t"] = :auto_complete
409
+
410
+ #The Enter key
411
+ map["\x0D"] = :enter
412
+
413
+ #The Escape key
414
+ map["\e"] = :cancel
415
+
416
+ #End of Input
417
+ map["\x1A"] = :end_of_input
418
+ end
419
+ ```
420
+
350
421
 
351
422
  ### Important Security Note
352
423
 
@@ -357,24 +428,25 @@ command line itself. Untrusted users should **never** be given such access!
357
428
 
358
429
  ## Demo
359
430
  A simple demo of mini_readline in action is available. To access this demo use
360
- the following from the mini_readline root folder:
431
+ the following:
361
432
 
362
- $ ruby sire.rb
433
+ $ sire
363
434
 
364
435
  This will launch SIRE, a Simple Interactive Ruby Environment, a sort of
365
- simple minded irb knock-off. This starts off by requiring the mini
366
- readline gem from either the system gem library or the local lib folder or
367
- if all fails, it will load the "classic" Readline gem. Here is a typical run:
436
+ simple minded irb knock-off. The utility supports a number of options that
437
+ allow the behaviour of the gem to be explored. These are:
368
438
 
369
- C:\Sites\mini_readline>ruby sire.rb
439
+ Option | Effect
440
+ -------|-------
441
+ local | Use the mini_readline in the lib folder. For testing.
442
+ gem | Use the mini_readline installed as a gem. The default.
443
+ old | Use the old readline facility.
444
+ map1 | Install a Wordstar keyboard map.
445
+ help | Display usage info and exit.
446
+ -? | Same thing.
370
447
 
448
+ #### Testing Shell Out Bugs
371
449
 
372
- Loaded mini_readline from the local code folder.
373
-
374
- Welcome to a Simple Interactive Ruby Environment
375
- Use the command 'quit' to exit.
376
-
377
- SIRE>
378
450
  Of note, the run method can be used to test for the shell process bug. For
379
451
  example:
380
452
 
@@ -391,15 +463,12 @@ example:
391
463
  "sire.rb",
392
464
  "tests"]
393
465
  SIRE>
394
- After this command is run, the program should continue to operate correctly
395
- and not go bannanas. To test the behavior of the standard readline library, use:
396
-
397
- $ ruby sire.rb old
398
466
 
399
- To test the local copy of mini_readline in the lib folder instead of the
400
- system gem, use this:
467
+ After this command is run, the program should continue to operate correctly
468
+ and not go bannanas. To test the behavior of the (currently broken) standard
469
+ readline library, use:
401
470
 
402
- $ ruby sire.rb local
471
+ $ sire.rb old
403
472
 
404
473
  ## Cross Platform Portability Progress
405
474
 
@@ -433,3 +502,14 @@ aspect that could use some TLC or a suggestion or an idea. Please see
433
502
  ( https://github.com/PeterCamilleri/mini_readline/issues )
434
503
 
435
504
  This is a low pressure environment. All are welcome!
505
+
506
+ ## License
507
+
508
+ The gem is available as open source under the terms of the
509
+ [MIT License](./LICENSE.txt).
510
+
511
+ ## Code of Conduct
512
+
513
+ Everyone interacting in the fully_freeze project’s codebases, issue trackers,
514
+ chat rooms and mailing lists is expected to follow the
515
+ [code of conduct](./CODE_OF_CONDUCT.md).
data/bin/sire ADDED
@@ -0,0 +1,218 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # A Simple Interactive Ruby Environment
4
+ #
5
+
6
+ require 'pp'
7
+
8
+ # Capture a binding for code evaluation.
9
+ sire_binding = binding
10
+
11
+ # Process command line arguments.
12
+ valid_options = {'local' => :reader,
13
+ 'gem' => :reader,
14
+ 'old' => :reader,
15
+ 'map1' => :map,
16
+ 'help' => :help,
17
+ '?' => :help}
18
+
19
+ options = {reader: 'gem'}
20
+
21
+ # Display help for SIRE and exit.
22
+ def display_help(error=nil)
23
+ puts "SIRE: a Simple Interactive Ruby Environment\n"
24
+
25
+ puts "Invalid option: #{error}" if error
26
+
27
+ puts "", "Usage: sire <options>",
28
+ " local Use the local mini_readline code.",
29
+ " gem Use the mini_readline installed gem.",
30
+ " old Use the standard readline gem.",
31
+ " map1 Use the alternate key mapping in Windows.",
32
+ " help -? Display this help and exit."
33
+
34
+ exit
35
+ end
36
+
37
+ ARGV.each do |arg|
38
+ key = valid_options[arg]
39
+ display_help(arg) unless key
40
+ options[key] = arg
41
+ end
42
+
43
+ display_help if options[:help]
44
+
45
+ case options[:reader]
46
+ when 'local'
47
+ require_relative '../lib/mini_readline'
48
+ puts "", "Option(local). Loaded mini_readline from the local code folder. Version #{MiniReadline::VERSION}"
49
+ when 'gem'
50
+ require 'mini_readline'
51
+ puts "", "Loaded mini_readline from the system gem. Version #{MiniReadline::VERSION}"
52
+ when 'old'
53
+ require 'readline'
54
+ class MiniReadlineEOI < StandardError; end #Compatibility stub.
55
+ puts "", "Loaded the standard readline gem. Version #{Readline::VERSION}"
56
+ end
57
+
58
+ MiniReadline = Readline unless defined?(MiniReadline)
59
+
60
+ class Object
61
+ # Generate the class lineage of the object.
62
+ def classes
63
+ begin
64
+ result = ""
65
+ klass = self.instance_of?(Class) ? self : self.class
66
+
67
+ begin
68
+ result << klass.to_s
69
+ klass = klass.superclass
70
+ result << " < " if klass
71
+ end while klass
72
+
73
+ result
74
+ end
75
+ end
76
+
77
+ private
78
+
79
+ # Quit the interactive session.
80
+ def quit
81
+ puts "Quit command.", ""
82
+ exit
83
+ end
84
+
85
+ # Get a mapped keystroke.
86
+ def get_mapped
87
+ if old?
88
+ puts 'The get_mapped method is not supported by old readline.'
89
+ else
90
+ print 'Press a key: '
91
+ MiniTerm.get_mapped_char
92
+ end
93
+ end
94
+
95
+ # Test spawning a process. This breaks the regular readline gem.
96
+ def run(command)
97
+ IO.popen(command, "r+") do |io|
98
+ io.close_write
99
+ return io.read
100
+ end
101
+ end
102
+
103
+ def old?
104
+ defined?(Readline)
105
+ end
106
+
107
+ end
108
+
109
+ if options[:map] == 'map1'
110
+ if old?
111
+ puts 'Remapping is not supported by old readline.'
112
+ exit
113
+ end
114
+
115
+ puts "Remapping keyboard to WordStar(TM)."
116
+
117
+ [:windows, :ansi].each do |target|
118
+ MiniTerm.add_map(target) do |map|
119
+ map[" ".."~"] = :insert_text
120
+
121
+ #Left Arrows
122
+ map["\x13"] = :go_left
123
+ map["\x01"] = :word_left
124
+
125
+ #Right Arrows
126
+ map["\x04"] = :go_right
127
+ map["\x06"] = :word_right
128
+
129
+ #Up Arrows
130
+ map["\x05"] = :previous_history
131
+
132
+ #Down Arrows
133
+ map["\x18"] = :next_history
134
+
135
+ #The Home and End keys
136
+ map["\x17"] = :go_home
137
+ map["\x12"] = :go_end
138
+
139
+ #The Backspace and Delete keys
140
+ map["\x08"] = :delete_left
141
+ map["\x7F"] = :delete_right
142
+ map["\x11\x13"] = :delete_all_left
143
+ map["\x11\x04"] = :delete_all_right
144
+
145
+ #Auto-completion.
146
+ map["\t"] = :auto_complete
147
+
148
+ #The Enter key
149
+ map["\x0D"] = :enter
150
+
151
+ #The Escape key
152
+ map["\e"] = :cancel
153
+
154
+ #End of Input
155
+ map["\x1A"] = :end_of_input
156
+ end
157
+ end
158
+ end
159
+
160
+ #The SIRE module contains a simplistic R.E.P.L. to test out mini_readline.
161
+ module SIRE
162
+
163
+ # Run the interactive session.
164
+ def self.run_sire(evaluator)
165
+ @evaluator = evaluator
166
+
167
+ unless old?
168
+ MiniReadline::BASE_OPTIONS[:auto_complete] = true
169
+ MiniReadline::BASE_OPTIONS[:eoi_detect] = true
170
+ end
171
+
172
+ puts
173
+ puts "Welcome to a Simple Interactive Ruby Environment\n"
174
+ puts "Use the command 'quit' to exit.\n\n"
175
+
176
+ loop do
177
+ exec_line(get_line)
178
+ end
179
+
180
+ puts "\n\n"
181
+
182
+ rescue MiniReadlineEOI, Interrupt => e
183
+ puts "\n"
184
+ end
185
+
186
+ private
187
+
188
+ # Get a line of input from the user.
189
+ def self.get_line
190
+ initial_input = MiniReadline.readline("SIRE>", true)
191
+ get_extra_input(initial_input)
192
+ end
193
+
194
+ # Get any continuations of the inputs
195
+ def self.get_extra_input(str)
196
+ if /\\\s*$/ =~ str
197
+ get_extra_input($PREMATCH + "\n" + MiniReadline.readline("SIRE\\", true))
198
+ else
199
+ str
200
+ end
201
+ end
202
+
203
+ # Execute a single line.
204
+ def self.exec_line(line)
205
+ result = @evaluator.eval(line)
206
+ pp result unless line.length == 0
207
+
208
+ rescue Interrupt => e
209
+ puts "", "Execution Interrupted!",
210
+ "", "#{e.class} detected: #{e}", ""
211
+
212
+ rescue StandardError, ScriptError => e
213
+ puts "", "#{e.class} detected: #{e}", ""
214
+ end
215
+
216
+ end
217
+
218
+ SIRE.run_sire(sire_binding)
data/lib/mini_readline.rb CHANGED
@@ -14,12 +14,6 @@ require_relative "mini_readline/read_line"
14
14
  # The MiniReadline main module.
15
15
  module MiniReadline
16
16
 
17
- private_constant :Prompt
18
- private_constant :Edit
19
- private_constant :EditWindow
20
- private_constant :History
21
- private_constant :NoHistory
22
-
23
17
  # The (limited) compatibility module function.
24
18
  def self.readline(prompt = "", history = nil, options = {})
25
19
  get_reader.readline(options.merge({prompt: prompt, history: history}))
@@ -4,27 +4,32 @@
4
4
  module MiniReadline
5
5
 
6
6
  # The base options shared by all instances.
7
- BASE_OPTIONS = {:scroll_step => 12, #The amount scrolled.
7
+ BASE_OPTIONS = {
8
+ :scroll_step => 12, # The amount scrolled.
8
9
 
9
- :prompt => ">", #The default prompt.
10
- :alt_prompt => "<< ", #The prompt when scrolled.
11
- #Set to nil to use main prompt.
10
+ :prompt => ">", # The default prompt.
11
+ :alt_prompt => "<< ", # The prompt when scrolled.
12
+ # Set to nil to use main prompt.
12
13
 
13
- :auto_complete => false, #Is auto complete enabled?
14
- :auto_source => nil, #Filled in by auto_complete.rb
15
- #MiniReadline::QuotedFileFolderSource
14
+ :auto_complete => false, # Is auto complete enabled?
15
+ :auto_source => nil, # Filled in by auto_complete.rb
16
+ # MiniReadline::QuotedFileFolderSource
16
17
 
17
- :eoi_detect => false, #Is end of input detection enabled?
18
+ :chomp => false, # Remove the trailing new-line?
18
19
 
19
- :history => false, #Is the history buffer enabled?
20
- :log => [], #Default is no previous history
21
- :no_blanks => true, #No empty lines in history.
22
- :no_dups => true, #No duplicate lines in history.
20
+ :eoi_detect => false, # Is end of input detection enabled?
23
21
 
24
- :secret_mask => nil, #No secret password mask. Use the
25
- #string "*" to use stars or " "
26
- #for invisible secrets.
22
+ :history => false, # Is the history buffer enabled?
23
+ :log => [], # Default is no previous history
24
+ :no_blanks => true, # No empty lines in history.
25
+ :no_dups => true, # No duplicate lines in history.
26
+ :no_move => false, # Don't move history entries.
27
27
 
28
- :initial => ""} #The initial text for the entry.
29
- #An empty string for none.
28
+ :secret_mask => nil, # No secret password mask. Use the
29
+ # string "*" to use stars or " "
30
+ # for invisible secrets.
31
+
32
+ :initial => "" # The initial text for the entry.
33
+ # An empty string for none.
34
+ }
30
35
  end
@@ -8,9 +8,10 @@ require_relative 'read_line/no_history'
8
8
  # The ReadLine class that does the actual work.
9
9
  module MiniReadline
10
10
 
11
- #The Readline class that does the actual work of getting lines from the
12
- #user. Note that each instance of this class maintains its own copy of
13
- #the optional command history.
11
+ # The Readline class that does the actual work of getting lines from the
12
+ # user. Note that each instance of this class maintains its own copy of
13
+ # the optional command history.
14
+ # :reek:TooManyInstanceVariables -- Yes and it needs them!
14
15
  class Readline
15
16
 
16
17
  # The options specifically associated with this instance.
@@ -32,6 +32,7 @@ require_relative 'edit/unmapped'
32
32
  module MiniReadline
33
33
 
34
34
  # The line editor.
35
+ # :reek:TooManyInstanceVariables -- Yes and it needs them!
35
36
  class Edit
36
37
 
37
38
  # Set up the edit instance.
@@ -60,7 +61,7 @@ module MiniReadline
60
61
  def edit_process
61
62
  result = edit_loop
62
63
  @history.append_history(result)
63
- result + "\n"
64
+ result + (@options[:chomp] ? "" : "\n")
64
65
  end
65
66
 
66
67
  # The line editor processing loop.
@@ -7,6 +7,7 @@ require_relative 'edit_window/sync_cursor'
7
7
  module MiniReadline
8
8
 
9
9
  # Support for the edit window.
10
+ # :reek:TooManyInstanceVariables -- Yes and it needs them!
10
11
  class EditWindow
11
12
 
12
13
  # Determine the edit window limits.
@@ -7,6 +7,7 @@ module MiniReadline
7
7
  class Edit
8
8
 
9
9
  # An unmapped key was pressed. Beep!
10
+ # :reek:UtilityFunction -- Does not depend on state.
10
11
  def unmapped(_keyboard_args)
11
12
  MiniTerm.beep
12
13
  end
@@ -45,8 +45,15 @@ module MiniReadline
45
45
 
46
46
  # Append a string to the history buffer if enabled.
47
47
  def append_history(str)
48
- return if @options[:no_blanks] && str.strip.empty?
49
- history.delete(str) if @options[:no_dups]
48
+ return if @options[:no_blanks] && str.strip.empty?
49
+
50
+ if history.include?(str)
51
+ if @options[:no_dups]
52
+ return if @options[:no_move]
53
+
54
+ history.delete(str)
55
+ end
56
+ end
50
57
 
51
58
  history << str
52
59
  end
@@ -3,8 +3,8 @@
3
3
  # Version info for the gem.
4
4
  module MiniReadline
5
5
  #The current version of the mini_readline gem.
6
- VERSION = "0.9.0".freeze
6
+ VERSION = "0.9.5".freeze
7
7
 
8
8
  # A brief description.
9
- DESCRIPTION = "Get console input with edit, history, and auto-complete.".freeze
9
+ DESCRIPTION = "mini_readline: Get console input with edit, history, and auto-complete.".freeze
10
10
  end
@@ -9,12 +9,13 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Peter Camilleri"]
10
10
  spec.email = ["peter.c.camilleri@gmail.com"]
11
11
 
12
- spec.summary = "Get console input with edit, history, and auto-complete."
13
- spec.description = %{A gem, for console command entry with line edit and
14
- history, inspired by the standard readline gem. Also
15
- included are four sample auto-complete agents and the
16
- irbm utility, which is irb + mini_readline and not an
17
- Intermediate Range Ballistic Missile.
12
+ spec.summary = "mini_readline: Get console input with edit, history, and auto-complete."
13
+ spec.description = %{mini_readline: A compact, little gem for console
14
+ command entry with line edit and history, inspired by
15
+ the standard readline gem. Also included are four
16
+ sample auto-complete agents and the irbm utility,
17
+ which is irb + mini_readline and not an Intermediate
18
+ Range Ballistic Missile.
18
19
  }.gsub(/\s+/, ' ').strip
19
20
 
20
21
  spec.homepage = "https://github.com/PeterCamilleri/mini_readline"
@@ -29,10 +30,9 @@ Gem::Specification.new do |spec|
29
30
 
30
31
  spec.add_runtime_dependency 'mini_term', "~> 0.1.0"
31
32
 
32
- spec.add_development_dependency "rake", "~> 12.0"
33
- spec.add_development_dependency "bundler", "~> 1.11"
33
+ spec.add_development_dependency "rake", ">= 12.3.3"
34
+ spec.add_development_dependency "bundler", ">= 2.1.0"
34
35
  spec.add_development_dependency 'minitest', "~> 5.7"
35
- spec.add_development_dependency 'minitest_visible', "~> 0.1"
36
36
  spec.add_development_dependency 'reek', ">= 5.0.2"
37
37
 
38
38
  end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+
3
+ require_relative '../lib/mini_readline'
4
+ gem 'minitest'
5
+ require 'minitest/autorun'
6
+
7
+ class SomeHistoryTester < Minitest::Test
8
+
9
+ def test_some_history_options
10
+ buffer = ["one", "two", "three"]
11
+ options = {:no_blanks => true,
12
+ :no_dups => true,
13
+ :no_move => false}
14
+
15
+ history = MiniReadline::History.new(buffer)
16
+ history.initialize_parms(options)
17
+
18
+ assert_equal(3, history.history.length)
19
+ assert_equal(["one", "two", "three"], history.history)
20
+
21
+ history.append_history("four")
22
+ assert_equal(4, history.history.length)
23
+ assert_equal(["one", "two", "three", "four"], history.history)
24
+
25
+ history.append_history("two")
26
+ assert_equal(4, history.history.length)
27
+ assert_equal(["one", "three", "four", "two"], history.history)
28
+
29
+ options[:no_move] = true
30
+ history.append_history("three")
31
+ assert_equal(4, history.history.length)
32
+ assert_equal(["one", "three", "four", "two"], history.history)
33
+ end
34
+
35
+ end
@@ -3,14 +3,10 @@
3
3
  require_relative '../lib/mini_readline'
4
4
  gem 'minitest'
5
5
  require 'minitest/autorun'
6
- require 'minitest_visible'
7
6
 
8
7
  #Test the monkey patches applied to the Object class.
9
8
  class MiniReadlineTester < Minitest::Test
10
9
 
11
- #Track mini-test progress.
12
- include MinitestVisible
13
-
14
10
  def test_that_it_has_a_version_number
15
11
  refute_nil ::MiniReadline::VERSION
16
12
  assert(::MiniReadline::VERSION.frozen?)
@@ -47,7 +43,7 @@ class MiniReadlineTester < Minitest::Test
47
43
  result = ''
48
44
 
49
45
  loop do
50
- result = edit.readline(prompt: ">", history: true).chomp
46
+ result = edit.readline(prompt: ">", chomp: true, history: true)
51
47
  puts result.inspect
52
48
  break unless result != "quit"
53
49
  end
@@ -64,12 +60,12 @@ class MiniReadlineTester < Minitest::Test
64
60
  result = ''
65
61
 
66
62
  loop do
67
- result = edit.readline(prompt: ">").chomp
63
+ result = edit.readline(prompt: ">")
68
64
  puts result.inspect
69
- break unless result != "quit"
65
+ break unless result != "quit\n"
70
66
  end
71
67
 
72
- assert_equal("quit", result)
68
+ assert_equal("quit\n", result)
73
69
  end
74
70
 
75
71
  def test_reading_with_a_default
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.9.0
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Camilleri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-05 00:00:00.000000000 Z
11
+ date: 2021-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mini_term
@@ -28,30 +28,30 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '12.0'
33
+ version: 12.3.3
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: '12.0'
40
+ version: 12.3.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.11'
47
+ version: 2.1.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '1.11'
54
+ version: 2.1.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '5.7'
69
- - !ruby/object:Gem::Dependency
70
- name: minitest_visible
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '0.1'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '0.1'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: reek
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -94,23 +80,26 @@ dependencies:
94
80
  - - ">="
95
81
  - !ruby/object:Gem::Version
96
82
  version: 5.0.2
97
- description: A gem, for console command entry with line edit and history, inspired
98
- by the standard readline gem. Also included are four sample auto-complete agents
99
- and the irbm utility, which is irb + mini_readline and not an Intermediate Range
100
- Ballistic Missile.
83
+ description: 'mini_readline: A compact, little gem for console command entry with
84
+ line edit and history, inspired by the standard readline gem. Also included are
85
+ four sample auto-complete agents and the irbm utility, which is irb + mini_readline
86
+ and not an Intermediate Range Ballistic Missile.'
101
87
  email:
102
88
  - peter.c.camilleri@gmail.com
103
89
  executables:
104
90
  - irbm
91
+ - sire
105
92
  extensions: []
106
93
  extra_rdoc_files: []
107
94
  files:
108
95
  - ".gitignore"
96
+ - ".reek.yml"
109
97
  - CODE_OF_CONDUCT.md
110
98
  - Gemfile
111
99
  - LICENSE.txt
112
100
  - README.md
113
101
  - bin/irbm
102
+ - bin/sire
114
103
  - irbt.rb
115
104
  - lib/mini_readline.rb
116
105
  - lib/mini_readline/exceptions.rb
@@ -149,10 +138,9 @@ files:
149
138
  - lib/mini_readline/read_line/prompt.rb
150
139
  - lib/mini_readline/version.rb
151
140
  - mini_readline.gemspec
152
- - mini_readline.reek
153
141
  - rakefile.rb
154
142
  - reek.txt
155
- - sire.rb
143
+ - tests/history_tests.rb
156
144
  - tests/mini_readline_tests.rb
157
145
  homepage: https://github.com/PeterCamilleri/mini_readline
158
146
  licenses:
@@ -173,9 +161,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
161
  - !ruby/object:Gem::Version
174
162
  version: '0'
175
163
  requirements: []
176
- rubyforge_project:
177
- rubygems_version: 2.5.2
164
+ rubygems_version: 3.2.17
178
165
  signing_key:
179
166
  specification_version: 4
180
- summary: Get console input with edit, history, and auto-complete.
167
+ summary: 'mini_readline: Get console input with edit, history, and auto-complete.'
181
168
  test_files: []
data/mini_readline.reek DELETED
@@ -1,115 +0,0 @@
1
- ---
2
- Attribute:
3
- enabled: false
4
- exclude: []
5
- BooleanParameter:
6
- enabled: true
7
- exclude: []
8
- ClassVariable:
9
- enabled: true
10
- exclude: []
11
- ControlParameter:
12
- enabled: true
13
- exclude: []
14
- DataClump:
15
- enabled: true
16
- exclude: []
17
- max_copies: 2
18
- min_clump_size: 2
19
- DuplicateMethodCall:
20
- enabled: true
21
- exclude: []
22
- max_calls: 1
23
- allow_calls: []
24
- FeatureEnvy:
25
- enabled: true
26
- exclude: []
27
- InstanceVariableAssumption:
28
- enabled: false
29
- exclude: []
30
- IrresponsibleModule:
31
- enabled: true
32
- exclude: []
33
- LongParameterList:
34
- enabled: true
35
- exclude: []
36
- max_params: 3
37
- overrides:
38
- initialize:
39
- max_params: 5
40
- LongYieldList:
41
- enabled: true
42
- exclude: []
43
- max_params: 3
44
- NestedIterators:
45
- enabled: true
46
- exclude: []
47
- max_allowed_nesting: 1
48
- ignore_iterators: []
49
- NilCheck:
50
- enabled: true
51
- exclude: []
52
- PrimaDonnaMethod:
53
- enabled: true
54
- exclude: []
55
- RepeatedConditional:
56
- enabled: true
57
- exclude: []
58
- max_ifs: 2
59
- TooManyInstanceVariables:
60
- enabled: true
61
- exclude: []
62
- max_instance_variables: 9
63
- TooManyMethods:
64
- enabled: true
65
- exclude: []
66
- max_methods: 25
67
- TooManyStatements:
68
- enabled: true
69
- exclude:
70
- - initialize
71
- max_statements: 7
72
- UncommunicativeMethodName:
73
- enabled: true
74
- exclude: []
75
- reject:
76
- - !ruby/regexp /^[a-z]$/
77
- - !ruby/regexp /[0-9]$/
78
- - !ruby/regexp /[A-Z]/
79
- accept: []
80
- UncommunicativeModuleName:
81
- enabled: true
82
- exclude: []
83
- reject:
84
- - !ruby/regexp /^.$/
85
- - !ruby/regexp /[0-9]$/
86
- accept:
87
- - Inline::C
88
- UncommunicativeParameterName:
89
- enabled: true
90
- exclude: []
91
- reject:
92
- - !ruby/regexp /^.$/
93
- - !ruby/regexp /[0-9]$/
94
- - !ruby/regexp /[A-Z]/
95
- - !ruby/regexp /^_/
96
- accept: []
97
- UncommunicativeVariableName:
98
- enabled: true
99
- exclude: []
100
- reject:
101
- - !ruby/regexp /^.$/
102
- - !ruby/regexp /[0-9]$/
103
- - !ruby/regexp /[A-Z]/
104
- accept:
105
- - _
106
- UnusedParameters:
107
- enabled: true
108
- exclude: []
109
- UnusedPrivateMethod:
110
- enabled: false
111
- exclude: []
112
- UtilityFunction:
113
- enabled: true
114
- exclude: []
115
- max_helper_calls: 1
data/sire.rb DELETED
@@ -1,145 +0,0 @@
1
- # coding: utf-8
2
- # A Simple Interactive Ruby Environment
3
-
4
- require 'pp'
5
-
6
- #Some SIRE control variables.
7
- $sire_done = false
8
- $sire_binding = binding
9
- $sire_old = (ARGV[0] == 'old') || defined?(Readline)
10
-
11
- if $sire_old
12
- require 'readline'
13
- class MiniReadlineEOI < StandardError; end #Compatibility stub.
14
- puts "\nLoaded the standard readline gem. Version #{Readline::VERSION}"
15
- elsif ARGV[0] == 'local'
16
- require './lib/mini_readline'
17
- puts "\nOption(local). Loaded mini_readline from the local code folder. Version #{MiniReadline::VERSION}"
18
- elsif defined?(MiniReadline)
19
- puts "\nThe mini_readline gem is already loaded. Version #{MiniReadline::VERSION}"
20
- else
21
- begin
22
- require 'mini_readline'
23
- puts "\nLoaded mini_readline from the system gem. Version #{MiniReadline::VERSION}"
24
- rescue LoadError
25
- begin
26
- require './lib/mini_readline'
27
- puts "\nLoaded mini_readline from the local code folder. Version #{MiniReadline::VERSION}"
28
- rescue LoadError
29
- require 'readline'
30
- puts "\nLoaded the standard readline gem. Version #{Readline::VERSION}"
31
- end
32
- end
33
- end
34
-
35
- Readline = MiniReadline unless defined?(Readline)
36
-
37
- class Object
38
- #Generate the class lineage of the object.
39
- def classes
40
- begin
41
- result = ""
42
- klass = self.instance_of?(Class) ? self : self.class
43
-
44
- begin
45
- result << klass.to_s
46
- klass = klass.superclass
47
- result << " < " if klass
48
- end while klass
49
-
50
- result
51
- end
52
- end
53
-
54
- private
55
-
56
- #Quit the interactive session.
57
- def quit
58
- $sire_done = true
59
- puts
60
- "Quit command."
61
- end
62
-
63
- #Get a mapped keystroke.
64
- def get_mapped
65
- if $sire_old
66
- puts 'Not supported by old readline.'
67
- else
68
- print 'Press a key:'
69
- MiniTerm.get_mapped_char
70
- end
71
- end
72
-
73
- #Test spawning a process. This breaks the regular readline gem.
74
- def run(command)
75
- IO.popen(command, "r+") do |io|
76
- io.close_write
77
- return io.read
78
- end
79
- end
80
-
81
- end
82
-
83
- #The SIRE class contains the simplistic R.E.P.L.
84
- class SIRE
85
-
86
- #Run the interactive session.
87
- def run_sire
88
- unless $sire_old
89
- MiniReadline::BASE_OPTIONS[:auto_complete] = true
90
- MiniReadline::BASE_OPTIONS[:eoi_detect] = true
91
- end
92
-
93
- puts
94
- puts "Welcome to a Simple Interactive Ruby Environment\n"
95
- puts "Use the command 'quit' to exit.\n\n"
96
-
97
- until $sire_done
98
- exec_line(get_line)
99
- end
100
-
101
- puts "\n\n"
102
-
103
- rescue MiniReadlineEOI, Interrupt => e
104
- puts "\n"
105
- end
106
-
107
- private
108
-
109
- #Get a line of input from the user.
110
- def get_line
111
- initial_input = Readline.readline("SIRE>", true)
112
- get_extra_input(initial_input)
113
- end
114
-
115
- #Get any continuations of the inputs
116
- def get_extra_input(str)
117
- if /\\\s*$/ =~ str
118
- get_extra_input($PREMATCH + "\n" + Readline.readline("SIRE\\", true))
119
- else
120
- str
121
- end
122
- end
123
-
124
- #Execute a single line.
125
- def exec_line(line)
126
- result = $sire_binding.eval(line)
127
- pp result unless line.length == 0
128
-
129
- rescue Interrupt => e
130
- puts "\nExecution Interrupted!"
131
- puts "\n#{e.class} detected: #{e}\n"
132
- puts e.backtrace
133
- puts "\n"
134
-
135
- rescue Exception => e
136
- puts "\n#{e.class} detected: #{e}\n"
137
- puts e.backtrace
138
- puts
139
- end
140
-
141
- end
142
-
143
- if __FILE__ == $0
144
- SIRE.new.run_sire
145
- end