mini_readline 0.0.4 → 0.0.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
2
  SHA1:
3
- metadata.gz: 93b007ca4b55761c9dc6f4ddae5e6d45bd118a63
4
- data.tar.gz: d1f1f3750bbe1b621b8a2c624d6e009e40eec839
3
+ metadata.gz: 5cb399d7a4ffc7fcf703330024c6422386ff2c67
4
+ data.tar.gz: 748e2eacc096c0eadd51b84f79586b411d1abfa6
5
5
  SHA512:
6
- metadata.gz: 2a2a9ff735c9918757542baf9ae5800d63154d0c0ad795f2b172ba4d7063de5bf89865efa42aa4c87929966e474e7c22ec9e87c5047b6bed730fd3568d09c114
7
- data.tar.gz: ea4ef0dfc1a29f67dec243961bcee04e8f419098f6b3168ef966a01068ec6bc4eebd56f5386d3cbc9bf23d8e3286429fe63d2a876bdcb26ee54060f70c5c49cd
6
+ metadata.gz: 63c11cfeaf488a056405e9b8f6b0c07536b6ef3727d7d584b516f2252c1af8272fe35c2f35f9c5b41d7d2c5de13f8b5b7bc09a9329b3e12db23e03c7da2db939
7
+ data.tar.gz: acc1855c61e90bba831229f9a05bbfc125371075ba48a4bd8baf2a5fbd695c18495ca4244c1ca19d76ea5bda978a72dfcc56aa65df3622bfbab9ab50e05834d3
data/README.md CHANGED
@@ -59,7 +59,7 @@ Erase All | Escape | Ctrl-L
59
59
  ### Notes
60
60
  * The label "Other" is an umbrella that bundles together the Linux, Mac,
61
61
  and Cygwin platforms.
62
- * References to Keypad keys under Windows assume that Num Lock is not engaged.
62
+ * References to Pad keys under Windows assume that Num Lock is not engaged.
63
63
 
64
64
  ## Usage
65
65
 
@@ -135,11 +135,25 @@ hist << "launch --weapons:nuclear --all"
135
135
  ```
136
136
 
137
137
  ### Options
138
- In mini_readline, options exist at two levels:
138
+ In mini_readline, options exist at three levels:
139
139
  * The MiniReadline module hash BASE_OPTIONS. These options are shared by
140
- all instances of the Readline class.
140
+ all instances of the Readline class. These options can be modified by
141
+ changing entries in the MiniReadline::BASE_OPTIONS hash.
142
+ * The instance options associated with each instance of the Readline class.
143
+ These options may be specified when a Readline instance is created (with new)
144
+ or by getting the instance options with the instance_options property and
145
+ adding/changing entries to/in it.
141
146
  * The options hash argument of the Readline class's readline instance method.
142
147
 
148
+ <br>The options in effect during a read line operation are expressed as:
149
+
150
+ ```ruby
151
+ MiniReadline::BASE_OPTIONS.merge(instance_options).merge(options)
152
+ ```
153
+ <br>This means that instance_options entries override those in BASE_OPTION and
154
+ readline parameter option entries override both instance_options and BASE_OPTION
155
+ entries.
156
+
143
157
  <br>The available options are described below:
144
158
  ```ruby
145
159
  BASE_OPTIONS = {
@@ -148,6 +162,7 @@ BASE_OPTIONS = {
148
162
  :alt_prompt => "<< ", #The prompt when scrolled.
149
163
  #Set to nil for no alt prompt.
150
164
 
165
+ :history => false, #Is the history buffer enabled?
151
166
  :no_blanks => true, #No empty lines in history.
152
167
  :no_dups => true, #No duplicate lines in history.
153
168
 
@@ -210,7 +225,7 @@ and not go bannanas. To test the behavior of the standard readline library, use:
210
225
  $ ruby sire.rb old
211
226
 
212
227
  To test the local copy of mini_readline in the lib folder instead of the
213
- system gem, use this instead:
228
+ system gem, use this:
214
229
 
215
230
  $ ruby sire.rb local
216
231
 
data/lib/mini_readline.rb CHANGED
@@ -12,14 +12,12 @@ require_relative "mini_readline/raw_term"
12
12
  #* mini_readline.rb - The root file that gathers up all the system's parts.
13
13
  module MiniReadline
14
14
 
15
- #The instances of Readline with and without history.
16
- @readers = {true => Readline.new([]), false => Readline.new(nil)}
15
+ #The shared instance of Readline.
16
+ @reader = Readline.new()
17
17
 
18
18
  #The (limited) compatibility module function.
19
- #<br>Endemic Code Smells
20
- #* :reek:BooleanParameter -- Required for compatibility
21
- def self.readline(prompt, history = false)
22
- @readers[history].readline(prompt)
19
+ def self.readline(prompt, history = nil)
20
+ @reader.readline(prompt, history: history)
23
21
  end
24
22
  end
25
23
 
@@ -7,8 +7,9 @@ module MiniReadline
7
7
  BASE_OPTIONS = {:window_width => 79, #The width of the edit area.
8
8
  :scroll_step => 12, #The amount scrolled.
9
9
  :alt_prompt => "<< ", #The prompt when scrolled.
10
- #Set to nil for no alt prompt.
10
+ #Set to nil to use main prompt.
11
11
 
12
+ :history => false, #Is the history buffer enabled?
12
13
  :no_blanks => true, #No empty lines in history.
13
14
  :no_dups => true, #No duplicate lines in history.
14
15
 
@@ -1,6 +1,9 @@
1
1
  # coding: utf-8
2
2
 
3
3
  require_relative 'read_line/edit'
4
+ require_relative 'read_line/history'
5
+ require_relative 'read_line/no_history'
6
+
4
7
 
5
8
  #* read_line.rb - The ReadLine class that does the actual work.
6
9
  module MiniReadline
@@ -10,24 +13,31 @@ module MiniReadline
10
13
  #the optional command history.
11
14
  class Readline
12
15
 
16
+ #The options specifically associated with this instance.
17
+ attr_reader :instance_options
18
+
13
19
  #Setup the instance of the mini line editor.
14
20
  #<br>Parameters:
15
21
  #* buffer - An array of strings used to contain the history. Use an empty
16
- # array to have a history buffer with no initial entries. Use the
17
- # value nil (or false) to maintain no history at all.
18
- def initialize(buffer=[])
19
- @edit = Edit.new(buffer)
22
+ # array to have a history buffer with no initial entries.
23
+ #* instance_options - A hash of options owned by this \Readline instance.
24
+ #<br>Notes
25
+ #* In order to specify any instance options, buffer must also be specified.
26
+ def initialize(buffer=[], instance_options={})
27
+ @instance_options = instance_options
28
+ @history = History.new(buffer)
29
+ @no_history = NoHistory.new
20
30
  end
21
31
 
22
32
  #Get the history buffer of this read line instance.
23
33
  def history
24
- @edit.history
34
+ @history.history
25
35
  end
26
36
 
27
37
  #Read a line from the console with edit and history.
28
38
  #<br>Parameters:
29
39
  #* prompt - A string used to prompt the user. '>' is popular.
30
- #* options - A hash of options; Typically :symbol => value
40
+ #* options - A hash of options; Typically symbol: value
31
41
  def readline(prompt, options = {})
32
42
  initialize_parms(prompt, options)
33
43
  @edit.edit_process
@@ -38,14 +48,23 @@ module MiniReadline
38
48
  #Initialize the read line process. This basically process the arguments
39
49
  #of the readline method.
40
50
  def initialize_parms(prompt, options)
41
- @options = MiniReadline::BASE_OPTIONS.merge(options)
42
- (@term = @options[:term]).initialize_parms
43
-
51
+ set_options(options)
44
52
  set_prompt(prompt)
45
- @edit.initialize_edit_parms(@options)
53
+
54
+ history = @options[:history] ? @history : @no_history
55
+ @edit = Edit.new(history, @options)
56
+
57
+ @history.initialize_parms(@options)
58
+ end
59
+
60
+ #Set up the options
61
+ def set_options(options)
62
+ @options = MiniReadline::BASE_OPTIONS.merge(instance_options)
63
+ @options.merge!(options)
64
+ (@term = @options[:term]).initialize_parms
46
65
  end
47
66
 
48
- #Set up the prompt options.
67
+ #Set up the prompt.
49
68
  def set_prompt(prompt)
50
69
  @options[:base_prompt] = prompt
51
70
  @options[:scroll_prompt] = @options[:alt_prompt] || prompt
@@ -1,7 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
3
  require_relative 'edit_window'
4
- require_relative 'history'
5
4
 
6
5
  require_relative 'edit/insert_text'
7
6
  require_relative 'edit/enter'
@@ -31,21 +30,15 @@ module MiniReadline
31
30
  class Edit
32
31
 
33
32
  #Set up the edit instance.
34
- def initialize(buffer)
35
- @history = History.new(buffer)
36
- @edit_window = EditWindow.new
37
- end
38
-
39
- #Set up the initial edit settings.
40
- def initialize_edit_parms(options)
33
+ def initialize(history, options)
41
34
  @options = options
35
+ @history = history
42
36
  @term = @options[:term]
43
37
  @edit_posn = 0
44
38
  @edit_buffer = ""
45
39
  @working = true
46
40
 
47
- @edit_window.initialize_parms(@options)
48
- @history.initialize_parms(@options)
41
+ @edit_window = EditWindow.new(@options)
49
42
  end
50
43
 
51
44
  #The main edit buffer
@@ -59,11 +52,6 @@ module MiniReadline
59
52
  edit_buffer.length
60
53
  end
61
54
 
62
- #Get the history array for this edit instance.
63
- def history
64
- @history.history
65
- end
66
-
67
55
  #Interact with the user
68
56
  def edit_process
69
57
  result = edit_loop
@@ -9,8 +9,8 @@ module MiniReadline
9
9
  #A little more to the left please!
10
10
  def word_left(_keyboard_args)
11
11
  if @edit_posn > 0
12
- posn = @edit_buffer[0...@edit_posn].rstrip.rindex(' ')
13
- @edit_posn = posn ? posn + 1 : 0
12
+ left = @edit_buffer[0...@edit_posn]
13
+ @edit_posn = (posn = left.rindex(/\s\S/)) ? posn+1 : 0
14
14
  else
15
15
  @term.beep
16
16
  end
@@ -8,11 +8,9 @@ module MiniReadline
8
8
 
9
9
  #A little more to the right please!
10
10
  def word_right(_keyboard_args)
11
- len = edit_buffer.length
12
-
13
- if @edit_posn < len
11
+ if @edit_posn < length
14
12
  right = @edit_buffer[(@edit_posn+1)..-1]
15
- @edit_posn = (posn = /\s\S/ =~ right) ? @edit_posn + posn + 2 : len
13
+ @edit_posn = (posn = right.index(/\s\S/)) ? @edit_posn+posn+2 : length
16
14
  else
17
15
  @term.beep
18
16
  end
@@ -10,7 +10,7 @@ module MiniReadline
10
10
  class EditWindow
11
11
 
12
12
  #Determine the edit window limits.
13
- def initialize_parms(options)
13
+ def initialize(options)
14
14
  @options = options
15
15
  @base_width = window_width - @options[:base_prompt].length
16
16
  @scroll_width = window_width - @options[:scroll_prompt].length
@@ -53,7 +53,7 @@ module MiniReadline
53
53
 
54
54
  #Get the history buffer associated with this instance.
55
55
  def history
56
- @_buffer || []
56
+ @_buffer
57
57
  end
58
58
  end
59
59
  end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+
3
+ #* read_line/no_history.rb - Support for the edit without history.
4
+ module MiniReadline
5
+
6
+ #* read_line/no_history.rb - Support for the edit without history.
7
+ class NoHistory
8
+
9
+ #Get the history object ready for the next read line operation. NOP
10
+ def initialize_parms(_options)
11
+ end
12
+
13
+ #Go to the end of the history array. NOP
14
+ def goto_end_of_history
15
+ end
16
+
17
+ #Get the previous history string. NOP
18
+ def get_previous_history
19
+ false
20
+ end
21
+
22
+ #Get the next history string. NOP
23
+ def get_next_history
24
+ false
25
+ end
26
+
27
+ #Append a string to the history buffer if enabled. NOP
28
+ def append_history(_str)
29
+ end
30
+
31
+ #Get the history buffer associated with this instance. Empty
32
+ def history
33
+ []
34
+ end
35
+ end
36
+ end
@@ -1,4 +1,4 @@
1
1
  module MiniReadline
2
2
  #The current version of the mini_readline gem.
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
@@ -25,6 +25,8 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.required_ruby_version = '>=1.9.3'
27
27
 
28
+ spec.add_development_dependency "minitest", ">= 5.7"
29
+ spec.add_development_dependency "minitest_visible", ">= 0.0.2"
28
30
  spec.add_development_dependency "bundler", "~> 1.11"
29
31
  spec.add_development_dependency "rake", "~> 10.0"
30
32
  end
@@ -15,11 +15,20 @@ class MiniReadlineTester < Minitest::Test
15
15
  assert_equal(Module, MiniReadline.class)
16
16
  assert_equal(String, MiniReadline::VERSION.class)
17
17
  assert_equal(Class, MiniReadline::Readline.class)
18
+ assert_equal(Class, MiniReadline::History.class)
19
+ assert_equal(Class, MiniReadline::NoHistory.class)
18
20
  assert_equal(Class, MiniReadline::Edit.class)
19
21
  assert_equal(Class, MiniReadline::EditWindow.class)
20
22
  assert_equal(Class, MiniReadline::Mapper.class)
21
23
  end
22
24
 
25
+ def test_for_storage_of_options
26
+ assert_equal(Hash, MiniReadline::BASE_OPTIONS.class)
27
+ edit = MiniReadline::Readline.new()
28
+ assert_equal(Hash, edit.instance_options.class)
29
+ refute_equal(MiniReadline::BASE_OPTIONS, edit.instance_options)
30
+ end
31
+
23
32
  def test_platform_detection
24
33
  if (RUBY_PLATFORM =~ /\bcygwin\b/i) || (RUBY_PLATFORM !~ /mswin|mingw/)
25
34
  assert_equal(:other, MiniReadline::PLATFORM)
@@ -32,12 +41,12 @@ class MiniReadlineTester < Minitest::Test
32
41
  puts
33
42
  puts "To finish this test, enter the word: quit"
34
43
 
35
- edit = MiniReadline::Readline.new()
44
+ edit = MiniReadline::Readline.new
36
45
 
37
46
  result = ''
38
47
 
39
48
  loop do
40
- result = edit.readline(">")
49
+ result = edit.readline(">", history: true)
41
50
  puts result.inspect
42
51
  break unless result != 'quit'
43
52
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_readline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.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: 2016-01-11 00:00:00.000000000 Z
11
+ date: 2016-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest_visible
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.2
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -83,6 +111,7 @@ files:
83
111
  - lib/mini_readline/read_line/edit_window/sync_cursor.rb
84
112
  - lib/mini_readline/read_line/edit_window/sync_window.rb
85
113
  - lib/mini_readline/read_line/history.rb
114
+ - lib/mini_readline/read_line/no_history.rb
86
115
  - lib/mini_readline/version.rb
87
116
  - mini_readline.gemspec
88
117
  - reek.txt