mini_readline 0.9.0 → 0.9.1

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: 13d29a79c8b695d0491081997bfd2f78c2d6b6f4
4
- data.tar.gz: a13e598d917734a3448e4d9316aee17cabc701b3
3
+ metadata.gz: ba0cff3f1c82679c0bdf6c1c6e65a04c3b9f2354
4
+ data.tar.gz: f1935e5795e939426f20991657a8d12a95d22468
5
5
  SHA512:
6
- metadata.gz: a92268026fa1ac6abfd573cb6debd80b4055fbe047dd58bae5a666f39745831397c089b54615537ad1aee765a19d480375fe208234ca2f957bb640abb46c2570
7
- data.tar.gz: 568fa17fc7a40b0bf8f4bc7d01214e947f1503b8f49166a56636c049be91b595fd7284b86499942a91187cf75049855cc8eb0a13815400f56cf2ba2c3f6a7b1c
6
+ metadata.gz: a9258f743e1c7fc664d065587adfc684c64eb61429b6f11dc2252bffa7b0e32596caf2f9656362b02aeb65e91495f69dcb5608dd6f81f5d0fcf004a1d600d9e2
7
+ data.tar.gz: 973efb417ef924216fcbf9a8523987bf86f9974ed70ba77fbde7390fd5452a9aee4f30ae1c026724534652d593813b0a51ee423e9fff11316a83dc426152c1d0
@@ -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!
@@ -203,30 +216,35 @@ entries.
203
216
 
204
217
  <br>The available options are described below:
205
218
  ```ruby
219
+ # The base options shared by all instances.
206
220
  BASE_OPTIONS = {
207
- :scroll_step => 12, #The amount horizontally scrolled.
221
+ :scroll_step => 12, # The amount scrolled.
222
+
223
+ :prompt => ">", # The default prompt.
224
+ :alt_prompt => "<< ", # The prompt when scrolled.
225
+ # Set to nil to use main prompt.
208
226
 
209
- :prompt => ">", #The default prompt.
210
- :alt_prompt => "<< ", #The prompt when scrolled.
211
- #Set to nil for no alt prompt.
227
+ :auto_complete => false, # Is auto complete enabled?
228
+ :auto_source => nil, # Filled in by auto_complete.rb
229
+ # MiniReadline::QuotedFileFolderSource
212
230
 
213
- :auto_complete => false, #Is auto complete enabled?
214
- :auto_source => nil, #Filled in by auto_complete.rb
215
- #MiniReadline::QuotedFileFolderSource
231
+ :chomp => false, # Remove the trailing new-line?
216
232
 
217
- :eoi_detect => false, #Is end of input detection enabled?
233
+ :eoi_detect => false, # Is end of input detection enabled?
218
234
 
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.
235
+ :history => false, # Is the history buffer enabled?
236
+ :log => [], # Default is no previous history
237
+ :no_blanks => true, # No empty lines in history.
238
+ :no_dups => true, # No duplicate lines in history.
239
+ :no_move => false, # Don't move history entries.
223
240
 
224
- :secret_mask => nil, #No secret password mask. Use the
225
- #string "*" to use stars or " "
226
- #for invisible secrets.
241
+ :secret_mask => nil, # No secret password mask. Use the
242
+ # string "*" to use stars or " "
243
+ # for invisible secrets.
227
244
 
228
- :initial => ""} #The initial text for the entry.
229
- #An empty string for none.
245
+ :initial => "" # The initial text for the entry.
246
+ # An empty string for none.
247
+ }
230
248
  ```
231
249
 
232
250
  <br>While most of these options are self explanatory, a few could stand some
@@ -247,9 +265,17 @@ MiniReadline::BASE_OPTION[:auto_complete] = true
247
265
  this is MiniReadline::QuotedFileFolderSource. This option can be changed up to
248
266
  get auto-complete data other than files and folders. See Auto-Compete below for
249
267
  more details.
268
+ * :chomp is used to remove the trailing new-line character that garnishes the
269
+ text from the user. Set to true for clean text, and to false for parsley to
270
+ throw out.
250
271
  * :eoi_detect is used to control the end of input detection logic. If disabled,
251
272
  eoi inputs are treated as unmapped. If enabled, they raise a MiniReadlineEOI
252
273
  exception.
274
+ * A few options control the history buffer. With the history option on, lines
275
+ entered are retained in a buffer. Otherwise, no record is kept of entered text.
276
+ When no_blanks is set, blank lines are not saved. When no_dups is set,
277
+ duplicate lines are not saved. If so, when duplicates do occur, the no_move
278
+ option keeps the older copy. Otherwise the newer copy is retained.
253
279
  * :secret_mask is a masking character to be used for sensitive input like a
254
280
  password or missile launch code. This should be exactly one character long.
255
281
  Typical values are "\*" or " ". Also, any secret entries should be done with
@@ -261,11 +287,6 @@ specified text. Leave as an empty string to default to the empty edit area.
261
287
  Finally the :window_width option is now ignored. Screen width now automatically
262
288
  determined.
263
289
 
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
290
  ### Auto-Complete
270
291
  The mini readline gem comes with four auto-complete engines. These are:
271
292
 
@@ -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.1".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"
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+
3
+ require_relative '../lib/mini_readline'
4
+ gem 'minitest'
5
+ require 'minitest/autorun'
6
+ require 'minitest_visible'
7
+
8
+ class SomeHistoryTester < Minitest::Test
9
+
10
+ #Track mini-test progress.
11
+ include MinitestVisible
12
+
13
+ def test_some_history_options
14
+ buffer = ["one", "two", "three"]
15
+ options = {:no_blanks => true,
16
+ :no_dups => true,
17
+ :no_move => false}
18
+
19
+ history = MiniReadline::History.new(buffer)
20
+ history.initialize_parms(options)
21
+
22
+ assert_equal(3, history.history.length)
23
+ assert_equal(["one", "two", "three"], history.history)
24
+
25
+ history.append_history("four")
26
+ assert_equal(4, history.history.length)
27
+ assert_equal(["one", "two", "three", "four"], history.history)
28
+
29
+ history.append_history("two")
30
+ assert_equal(4, history.history.length)
31
+ assert_equal(["one", "three", "four", "two"], history.history)
32
+
33
+ options[:no_move] = true
34
+ history.append_history("three")
35
+ assert_equal(4, history.history.length)
36
+ assert_equal(["one", "three", "four", "two"], history.history)
37
+ end
38
+
39
+ end
@@ -47,7 +47,7 @@ class MiniReadlineTester < Minitest::Test
47
47
  result = ''
48
48
 
49
49
  loop do
50
- result = edit.readline(prompt: ">", history: true).chomp
50
+ result = edit.readline(prompt: ">", chomp: true, history: true)
51
51
  puts result.inspect
52
52
  break unless result != "quit"
53
53
  end
@@ -64,12 +64,12 @@ class MiniReadlineTester < Minitest::Test
64
64
  result = ''
65
65
 
66
66
  loop do
67
- result = edit.readline(prompt: ">").chomp
67
+ result = edit.readline(prompt: ">")
68
68
  puts result.inspect
69
- break unless result != "quit"
69
+ break unless result != "quit\n"
70
70
  end
71
71
 
72
- assert_equal("quit", result)
72
+ assert_equal("quit\n", result)
73
73
  end
74
74
 
75
75
  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.1
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: 2018-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mini_term
@@ -94,10 +94,10 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  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.
97
+ description: 'mini_readline: A compact, little gem for console command entry with
98
+ line edit and history, inspired by the standard readline gem. Also included are
99
+ four sample auto-complete agents and the irbm utility, which is irb + mini_readline
100
+ and not an Intermediate Range Ballistic Missile.'
101
101
  email:
102
102
  - peter.c.camilleri@gmail.com
103
103
  executables:
@@ -106,6 +106,7 @@ extensions: []
106
106
  extra_rdoc_files: []
107
107
  files:
108
108
  - ".gitignore"
109
+ - ".reek.yml"
109
110
  - CODE_OF_CONDUCT.md
110
111
  - Gemfile
111
112
  - LICENSE.txt
@@ -149,10 +150,10 @@ files:
149
150
  - lib/mini_readline/read_line/prompt.rb
150
151
  - lib/mini_readline/version.rb
151
152
  - mini_readline.gemspec
152
- - mini_readline.reek
153
153
  - rakefile.rb
154
154
  - reek.txt
155
155
  - sire.rb
156
+ - tests/history_tests.rb
156
157
  - tests/mini_readline_tests.rb
157
158
  homepage: https://github.com/PeterCamilleri/mini_readline
158
159
  licenses:
@@ -177,5 +178,5 @@ rubyforge_project:
177
178
  rubygems_version: 2.5.2
178
179
  signing_key:
179
180
  specification_version: 4
180
- summary: Get console input with edit, history, and auto-complete.
181
+ summary: 'mini_readline: Get console input with edit, history, and auto-complete.'
181
182
  test_files: []
@@ -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