mini_readline 0.2.0 → 0.3.0

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: a8482183c12c0303a39f18bc9618078108f9c223
4
- data.tar.gz: 09d16bd02e569d657acad881922a10f5ffb5f196
3
+ metadata.gz: 2485e678176d166843920e6f17956c7b839d90e3
4
+ data.tar.gz: 16afd9de803f9b3d3aae4c8f32318edef88ffbd2
5
5
  SHA512:
6
- metadata.gz: 09d3ed8de2584e5637f3b6fc832b0ee74971fca0d215bc1c108aa14cb6af6e450afda6e67773cafeac2f688f93b56745e42eaba3e77923ce4baecd7bd98d0893
7
- data.tar.gz: ed8ef74313404c8e253ee2ff773d487d79f724427d826bdc23f656772766a70dd41b5f6b0335519c494bed483ca90f10987b028e2cfe44b6f074480ba5480b09
6
+ metadata.gz: 48fb1ac610d575f4b622f45531842a2ead3b493b7261b4f376181c763dea76942a8058e8594386b02bb1df4835fb8931c21d40e4fa10cddbca7818f915ca7f4c
7
+ data.tar.gz: e7f170a4f2404366bb00db4d5482ada1e6fa927cd044707ed9e6d0a44b517fd62ac1f6c675e4791d3c5c8b1b2e9e3fa5b66fc6b636f32d279385d182976cc2b1
data/README.md CHANGED
@@ -4,24 +4,13 @@ This gem is used to get console style input from the user, with support for
4
4
  inline editing and command history.
5
5
 
6
6
  The mini readline gem is an experiment in replacing the standard readline gem
7
- that is part of Ruby. The reasons for doing this are somewhat shaky, but here
8
- is a list of what is hoped to be accomplished here.
9
-
10
- * The standard readline gem works poorly under Windows.
11
- <br>- The keypad arrow keys do not work.
12
- <br>- If the program attempts to send data to a subprocess, it breaks.
13
- * The code is so convoluted that it is difficult to fix or re-factor.
14
- * The code is just plain UGLY! With all we've learned about object oriented
15
- design, there just HAD to be a better way!
16
- * Finally, since this code will borrow a lot from the original, it is hoped
17
- that I will see the same bugs and fix them. Then perhaps it can be seen how
18
- the original code can also be fixed. In the long run, this is perhaps the
19
- most important goal.
20
-
21
- <br>The mini_readline gem is designed for use with MRI version 1.9.3 or later.
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.
22
9
 
23
- ## Installation
10
+ The mini_readline gem is designed for use with MRI version 1.9.3 or later.
11
+ The original readline which tries to support older versions of Ruby.
24
12
 
13
+ ## Installation
25
14
  Add this line to your application's Gemfile:
26
15
 
27
16
  ```ruby
@@ -30,7 +19,6 @@ gem 'mini_readline'
30
19
  And then execute:
31
20
 
32
21
  $ bundle
33
-
34
22
  Or install it yourself as:
35
23
 
36
24
  $ gem install mini_readline
@@ -119,13 +107,13 @@ as instance level options.
119
107
  <br>Once an instance is created it may be used as follows:
120
108
 
121
109
  ```ruby
122
- edit.readline(options)
110
+ user_entry = edit.readline(options)
123
111
  ```
124
- Where an optional hash of options settings. For example, to specify a prompt,
125
- use the following:
112
+ Where an optional hash of options settings. For example, to specify a
113
+ non-default prompt with history enabled, use the following:
126
114
 
127
115
  ```ruby
128
- edit.readline(prompt: '>')
116
+ user_entry = edit.readline(prompt: '? ', history: true)
129
117
  ```
130
118
 
131
119
 
@@ -174,6 +162,7 @@ BASE_OPTIONS = {
174
162
 
175
163
  :auto_complete => false, #Is auto complete enabled?
176
164
  :auto_source => nil, #Filled in by auto_complete.rb
165
+ #MiniReadline::QuotedFileFolderSource
177
166
 
178
167
  :eoi_detect => false, #Is end of input detection enabled?
179
168
 
@@ -183,6 +172,7 @@ BASE_OPTIONS = {
183
172
  :no_dups => true, #No duplicate lines in history.
184
173
 
185
174
  :term => nil, #Filled in by raw_term.rb
175
+ #MiniReadline::RawTerm
186
176
 
187
177
  :debug => false} #Used during development only.
188
178
  ```
@@ -199,7 +189,7 @@ MiniReadline::BASE_OPTION[:auto_complete] = true
199
189
  ```
200
190
  * :auto_source is the class of the source for auto-complete data. By default this
201
191
  is MiniReadline::FileFolderSource. This option can be changed up to get auto-complete
202
- data other than files and folders.
192
+ data other than files and folders. See Auto-Compete below for more details.
203
193
  * :eoi_detect is used to control the end of input detection logic. If disabled,
204
194
  eoi inputs are treated as unmapped. If enabled, they raise a MiniReadlineEOI
205
195
  exception.
@@ -214,6 +204,14 @@ from the user and control what is displayed. This gem automatically adapts to
214
204
  the environment and plugs in the needed object. This can be overridden where
215
205
  special io needs exist.
216
206
 
207
+ ### Auto-Complete
208
+ The mini readline gem comes with two auto-complete engines. These are:
209
+ * MiniReadline::FileFolderSource - A simple, in-line auto-complete for files
210
+ and folders that do **not** contain embedded spaces.
211
+ * MiniReadline::QuotedFileFolderSource - A simple, in-line auto-complete for
212
+ files and folders embedded in quotes "foo bar.rb" that may contain spaces.
213
+ This is the default auto-complete data source.
214
+
217
215
  ## Demo
218
216
  A simple demo of mini_readline in action is available. To access this demo use
219
217
  the following from the mini_readline root folder:
data/lib/mini_readline.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
+ require "English"
3
4
  require_relative "mini_readline/version"
4
5
  require_relative "mini_readline/exceptions"
5
6
  require_relative "mini_readline/options"
@@ -13,6 +13,7 @@ module MiniReadline
13
13
 
14
14
  :auto_complete => false, #Is auto complete enabled?
15
15
  :auto_source => nil, #Filled in by auto_complete.rb
16
+ #MiniReadline::QuotedFileFolderSource
16
17
 
17
18
  :eoi_detect => false, #Is end of input detection enabled?
18
19
 
@@ -22,6 +23,7 @@ module MiniReadline
22
23
  :no_dups => true, #No duplicate lines in history.
23
24
 
24
25
  :term => nil, #Filled in by raw_term.rb
26
+ #MiniReadline::RawTerm
25
27
 
26
28
  :debug => false #Used during development only.
27
29
  }
@@ -6,8 +6,6 @@ require_relative 'raw_term/mapper'
6
6
  module MiniReadline
7
7
 
8
8
  #The class used to manipulate console i/o on a low level.
9
- #<br>Endemic Code Smells
10
- # :reek:TooManyInstanceVariables
11
9
  class RawTerm
12
10
 
13
11
  #Create a mapper.
@@ -11,8 +11,6 @@ module MiniReadline
11
11
  PLATFORM = :other
12
12
 
13
13
  #The class used to manipulate console i/o on a low level.
14
- #<br>Endemic Code Smells
15
- # :reek:TooManyInstanceVariables
16
14
  class RawTerm
17
15
 
18
16
  #Carriage return
@@ -11,8 +11,6 @@ module MiniReadline
11
11
  #The \Readline class that does the actual work of getting lines from the
12
12
  #user. Note that each instance of this class maintains its own copy of
13
13
  #the optional command history.
14
- #<br>Endemic Code Smells
15
- # :reek:TooManyInstanceVariables
16
14
  class Readline
17
15
 
18
16
  #The options specifically associated with this instance.
@@ -30,8 +30,6 @@ require_relative 'edit/unmapped'
30
30
  module MiniReadline
31
31
 
32
32
  #* read_line/edit.rb - The line editor.
33
- #<br>Endemic Code Smells
34
- # :reek:TooManyInstanceVariables
35
33
  class Edit
36
34
 
37
35
  #Set up the edit instance.
@@ -2,12 +2,13 @@
2
2
 
3
3
  require_relative 'auto_complete/auto_manager'
4
4
  require_relative 'auto_complete/file_folder_source'
5
+ require_relative 'auto_complete/quoted_file_folder_source'
5
6
 
6
7
  #* read_line/window/edit/auto_complete.rb - Process :auto_complete
7
8
  module MiniReadline
8
9
 
9
10
  #Set up the default auto-complete data source.
10
- BASE_OPTIONS[:auto_source] = FileFolderSource
11
+ BASE_OPTIONS[:auto_source] = QuotedFileFolderSource
11
12
 
12
13
  #* read_line/window/edit/auto_complete.rb - Process :auto_complete
13
14
  class Edit
@@ -7,14 +7,15 @@ module MiniReadline
7
7
  class FileFolderSource
8
8
 
9
9
  #Create a new file/folder auto-data source. NOP
10
- def initialize(_options)
10
+ def initialize(options)
11
+ @options = options
11
12
  end
12
13
 
13
14
  #Construct a new data list for auto-complete
14
15
  def rebuild(str)
15
- @root, pivot = /\S+$/ =~ str ? [$`.to_s, $~.to_s] : [str, ""]
16
+ extract_root_pivot(str)
16
17
 
17
- list = Dir.glob(pivot + '*')
18
+ list = Dir.glob(@pivot + '*')
18
19
 
19
20
  unless list.empty?
20
21
  @cycler = list.cycle
@@ -23,6 +24,11 @@ module MiniReadline
23
24
  end
24
25
  end
25
26
 
27
+ #Parse the string into the two basic components.
28
+ def extract_root_pivot(str)
29
+ @root, @pivot = /\S+$/ =~ str ? [$PREMATCH, $MATCH] : [str, ""]
30
+ end
31
+
26
32
  #Get the next string for auto-complete
27
33
  def next
28
34
  @root + @cycler.next
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+
3
+ #* quoted_file_folder_source.rb - The data source for auto-complete.
4
+ module MiniReadline
5
+
6
+ #* quoted_file_folder_source.rb - The data source for auto-complete.
7
+ class QuotedFileFolderSource
8
+
9
+ #Create a new file/folder auto-data source. NOP
10
+ def initialize(options)
11
+ @options = options
12
+ end
13
+
14
+ #Construct a new data list for auto-complete
15
+ def rebuild(str)
16
+ extract_root_pivot(str)
17
+
18
+ list = Dir.glob(@pivot + '*')
19
+
20
+ unless list.empty?
21
+ @cycler = list.cycle
22
+ else
23
+ @cycler = nil
24
+ end
25
+ end
26
+
27
+ #Parse the string into the two basic components.
28
+ def extract_root_pivot(str)
29
+ @root, @pivot = /(?<=\")([^\"\s][^\"]*)?(?=\"?$)/ =~ str ? [$PREMATCH, $MATCH] : [str + '"', ""]
30
+ end
31
+
32
+ #Get the next string for auto-complete
33
+ def next
34
+ "#{@root}#{@cycler.next}\""
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -7,8 +7,6 @@ require_relative 'edit_window/sync_cursor'
7
7
  module MiniReadline
8
8
 
9
9
  #* read_line/edit_window.rb - Support for the edit window.
10
- #<br>Endemic Code Smells
11
- # :reek:TooManyInstanceVariables
12
10
  class EditWindow
13
11
 
14
12
  #Determine the edit window limits.
@@ -29,14 +27,6 @@ module MiniReadline
29
27
  left_margin + active_width - 1
30
28
  end
31
29
 
32
- #Set the right margin
33
- #<br>Notes
34
- #* If the right_margin is being set, then we must be scrolling. That is
35
- # why the scroll_width is used instead of active_width here.
36
- def right_margin=(value)
37
- @left_margin = value - scroll_width + 1
38
- end
39
-
40
30
  #Is the window currently in the scrolled state?
41
31
  def window_scrolled?
42
32
  left_margin > 0
@@ -19,11 +19,11 @@ module MiniReadline
19
19
  old_margins = [left_margin, right_margin]
20
20
 
21
21
  if length < base_width
22
- @left_margin = 0
22
+ set_left_margin(0)
23
23
  elsif edit_posn < left_margin
24
- @left_margin = [edit_posn - scroll_step, 0].max
24
+ set_left_margin([edit_posn - scroll_step, 0].max)
25
25
  elsif edit_posn > right_margin
26
- self.right_margin = edit_posn + scroll_step
26
+ set_right_margin(edit_posn + scroll_step)
27
27
  end
28
28
 
29
29
  old_margins == [left_margin, right_margin]
@@ -44,5 +44,19 @@ module MiniReadline
44
44
  end
45
45
  end
46
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
47
61
  end
48
62
  end
@@ -1,4 +1,4 @@
1
1
  module MiniReadline
2
2
  #The current version of the mini_readline gem.
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
@@ -0,0 +1,109 @@
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
+ IrresponsibleModule:
28
+ enabled: true
29
+ exclude: []
30
+ LongParameterList:
31
+ enabled: true
32
+ exclude: []
33
+ max_params: 3
34
+ overrides:
35
+ initialize:
36
+ max_params: 5
37
+ LongYieldList:
38
+ enabled: true
39
+ exclude: []
40
+ max_params: 3
41
+ NestedIterators:
42
+ enabled: true
43
+ exclude: []
44
+ max_allowed_nesting: 1
45
+ ignore_iterators: []
46
+ NilCheck:
47
+ enabled: true
48
+ exclude: []
49
+ PrimaDonnaMethod:
50
+ enabled: true
51
+ exclude: []
52
+ RepeatedConditional:
53
+ enabled: true
54
+ exclude: []
55
+ max_ifs: 2
56
+ TooManyInstanceVariables:
57
+ enabled: true
58
+ exclude: []
59
+ max_instance_variables: 9
60
+ TooManyMethods:
61
+ enabled: true
62
+ exclude: []
63
+ max_methods: 25
64
+ TooManyStatements:
65
+ enabled: true
66
+ exclude:
67
+ - initialize
68
+ max_statements: 7
69
+ UncommunicativeMethodName:
70
+ enabled: true
71
+ exclude: []
72
+ reject:
73
+ - !ruby/regexp /^[a-z]$/
74
+ - !ruby/regexp /[0-9]$/
75
+ - !ruby/regexp /[A-Z]/
76
+ accept: []
77
+ UncommunicativeModuleName:
78
+ enabled: true
79
+ exclude: []
80
+ reject:
81
+ - !ruby/regexp /^.$/
82
+ - !ruby/regexp /[0-9]$/
83
+ accept:
84
+ - Inline::C
85
+ UncommunicativeParameterName:
86
+ enabled: true
87
+ exclude: []
88
+ reject:
89
+ - !ruby/regexp /^.$/
90
+ - !ruby/regexp /[0-9]$/
91
+ - !ruby/regexp /[A-Z]/
92
+ - !ruby/regexp /^_/
93
+ accept: []
94
+ UncommunicativeVariableName:
95
+ enabled: true
96
+ exclude: []
97
+ reject:
98
+ - !ruby/regexp /^.$/
99
+ - !ruby/regexp /[0-9]$/
100
+ - !ruby/regexp /[A-Z]/
101
+ accept:
102
+ - _
103
+ UnusedParameters:
104
+ enabled: true
105
+ exclude: []
106
+ UtilityFunction:
107
+ enabled: true
108
+ exclude: []
109
+ max_helper_calls: 1
data/sire.rb CHANGED
@@ -54,7 +54,7 @@ class SIRE
54
54
  def q
55
55
  @_done = true
56
56
  puts
57
- "Bye bye for now!"
57
+ "Quit command."
58
58
  end
59
59
 
60
60
  #Get a mapped keystroke.
@@ -71,69 +71,6 @@ 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
- #Test the WRE
91
- def wre(str)
92
- WRE.match str
93
- end
94
-
95
- #Rubified Windows Regex.
96
- # a File name character, no spaces.
97
- # b File name character, with spaces.
98
- # c Drive specification.
99
- # x Non-quoted file spec.
100
- # y Quoted file spec.
101
- RRE = %r{
102
- (?<a> [^\/\\\:\*\?\<\>\"\s]){0}
103
- (?<b> [^\/\\\:\*\?\<\>\"]){0}
104
- (?<c> ([a-zA-z]\:)?\/){0}
105
- (?<x> \g<c>?(\g<a>*\/?)*){0}
106
- (?<y> \"\g<c>?(\g<a>(\g<b>*\g<a>)?\/?)*\"){0}
107
-
108
- (\g<x>|\g<y>)$
109
- }x
110
-
111
- #Test the RRE
112
- def rre(str)
113
- RRE.match str
114
- end
115
-
116
- #Other Platforms Regex.
117
- # a File name character, no spaces.
118
- # b File name character, with spaces.
119
- # c Root specification.
120
- # x Non-quoted file spec.
121
- # y Quoted file spec.
122
- ORE = %r{
123
- (?<a> [^\/\\\:\*\?\<\>\"\s]){0}
124
- (?<b> [^\/\\\:\*\?\<\>\"]){0}
125
- (?<c> \/){0}
126
- (?<x> \g<c>?(\g<a>*\/?)*){0}
127
- (?<y> \"\g<c>?(\g<a>(\g<b>*\g<a>)?\/?)*\"){0}
128
-
129
- (\g<x>|\g<y>)$
130
- }x
131
-
132
- #Test the ORE
133
- def ore(str)
134
- ORE.match str
135
- end
136
-
137
74
  #Execute a single line.
138
75
  def exec_line(line)
139
76
  result = eval line
@@ -153,17 +90,22 @@ class SIRE
153
90
 
154
91
  #Run the interactive session.
155
92
  def run_sire
93
+ edit = MiniReadline::Readline.new(prompt: 'SIRE>',
94
+ auto_complete: true,
95
+ history: true,
96
+ eoi_detect: true)
97
+
156
98
  puts
157
99
  puts "Welcome to a Simple Interactive Ruby Environment\n"
158
100
  puts "Use the command 'q' to quit.\n\n"
159
101
 
160
102
  until @_done
161
- exec_line(Readline.readline('SIRE>', true))
103
+ exec_line(edit.readline)
162
104
  end
163
105
 
164
106
  puts "\n\n"
165
107
 
166
- rescue Interrupt => e
108
+ rescue MiniReadlineEOI, Interrupt => e
167
109
  puts "\n"
168
110
  end
169
111
 
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.2.0
4
+ version: 0.3.0
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-21 00:00:00.000000000 Z
11
+ date: 2016-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -97,6 +97,7 @@ files:
97
97
  - lib/mini_readline/read_line/edit/auto_complete.rb
98
98
  - lib/mini_readline/read_line/edit/auto_complete/auto_manager.rb
99
99
  - lib/mini_readline/read_line/edit/auto_complete/file_folder_source.rb
100
+ - lib/mini_readline/read_line/edit/auto_complete/quoted_file_folder_source.rb
100
101
  - lib/mini_readline/read_line/edit/cancel.rb
101
102
  - lib/mini_readline/read_line/edit/delete_left.rb
102
103
  - lib/mini_readline/read_line/edit/delete_right.rb
@@ -119,6 +120,7 @@ files:
119
120
  - lib/mini_readline/read_line/no_history.rb
120
121
  - lib/mini_readline/version.rb
121
122
  - mini_readline.gemspec
123
+ - mini_readline.reek
122
124
  - reek.txt
123
125
  - sire.rb
124
126
  - tests/mini_readline_tests.rb