mini_readline 0.1.3 → 0.2.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: 634b35a4a125886de4969dd4f807fdf2b35e5ec3
4
- data.tar.gz: d6be43dd1584f371fea17f7600ee5b5e49ccefc4
3
+ metadata.gz: a8482183c12c0303a39f18bc9618078108f9c223
4
+ data.tar.gz: 09d16bd02e569d657acad881922a10f5ffb5f196
5
5
  SHA512:
6
- metadata.gz: 09a90d21011cc4e47143fda7e2b01d2ae88bbea694e5c1bf350214a9af3d69f874211d26aa3cd7c065254f95b3b7ccca4fd102db2d21260eda190afe14606bd2
7
- data.tar.gz: f713ffa03366f00f15203215656f4225c36e2e929f298bedd824e908885c005ddaf60c5581f8b46ca852ef0ad003c6cd6a932ac2f6b40002ba6e48b2016260f0
6
+ metadata.gz: 09d3ed8de2584e5637f3b6fc832b0ee74971fca0d215bc1c108aa14cb6af6e450afda6e67773cafeac2f688f93b56745e42eaba3e77923ce4baecd7bd98d0893
7
+ data.tar.gz: ed8ef74313404c8e253ee2ff773d487d79f724427d826bdc23f656772766a70dd41b5f6b0335519c494bed483ca90f10987b028e2cfe44b6f074480ba5480b09
data/README.md CHANGED
@@ -27,7 +27,6 @@ Add this line to your application's Gemfile:
27
27
  ```ruby
28
28
  gem 'mini_readline'
29
29
  ```
30
-
31
30
  And then execute:
32
31
 
33
32
  $ bundle
@@ -62,7 +61,8 @@ End of Input | Ctrl-Z | Alt-z
62
61
  * The label "Other" is an umbrella that bundles together the Linux, Mac,
63
62
  and Cygwin platforms.
64
63
  * References to Pad keys under Windows assume that Num Lock is not engaged.
65
- * Support for End of Input is controlled by the eoi_detect option.
64
+ * Support for End of Input is controlled by the eoi_detect option. See options
65
+ below.
66
66
 
67
67
  ## Usage
68
68
 
@@ -71,8 +71,7 @@ The typical way of utilizing this gem is to place the following:
71
71
  ```ruby
72
72
  require 'mini_readline'
73
73
  ```
74
-
75
- <br>By default, the constant Readline is set to the MiniReadline module. If this
74
+ By default, the constant Readline is set to the MiniReadline module. If this
76
75
  is not desired use the following:
77
76
 
78
77
  ```ruby
@@ -114,19 +113,23 @@ In native mode, instances of the Readline class are used to get user input.
114
113
  edit = MiniReadline::Readline.new()
115
114
  ```
116
115
 
117
- The constructor takes two optional arguments. The first is either:
118
- * An array of strings; A history buffer pre-loaded with commands.
119
- * An empty array; A history buffer with no pre-load.
120
-
121
- <br>The second is a hash of options that are used as instance level options.
116
+ The constructor takes an optional argument. A hash of options that are used
117
+ as instance level options.
122
118
 
123
119
  <br>Once an instance is created it may be used as follows:
124
120
 
125
121
  ```ruby
126
- edit.readline(prompt, options)
122
+ edit.readline(options)
127
123
  ```
128
- Where prompt is a prompt string and options is an optional hash of options
129
- settings. In addition, it is possible to get a hold
124
+ Where an optional hash of options settings. For example, to specify a prompt,
125
+ use the following:
126
+
127
+ ```ruby
128
+ edit.readline(prompt: '>')
129
+ ```
130
+
131
+
132
+ In addition, it is possible to get a hold
130
133
  of the history buffer of the edit object with:
131
134
  ```ruby
132
135
  hist = edit.history
@@ -164,6 +167,8 @@ entries.
164
167
  BASE_OPTIONS = {
165
168
  :window_width => 79, #The width of the edit area.
166
169
  :scroll_step => 12, #The amount scrolled.
170
+
171
+ :prompt => ">", #The default prompt.
167
172
  :alt_prompt => "<< ", #The prompt when scrolled.
168
173
  #Set to nil for no alt prompt.
169
174
 
@@ -173,6 +178,7 @@ BASE_OPTIONS = {
173
178
  :eoi_detect => false, #Is end of input detection enabled?
174
179
 
175
180
  :history => false, #Is the history buffer enabled?
181
+ :log => [], #Default is no previous history
176
182
  :no_blanks => true, #No empty lines in history.
177
183
  :no_dups => true, #No duplicate lines in history.
178
184
 
data/lib/mini_readline.rb CHANGED
@@ -18,7 +18,7 @@ module MiniReadline
18
18
 
19
19
  #The (limited) compatibility module function.
20
20
  def self.readline(prompt, history = nil)
21
- @reader.readline(prompt, history: history)
21
+ @reader.readline(prompt: prompt, history: history)
22
22
  end
23
23
  end
24
24
 
@@ -6,6 +6,8 @@ module MiniReadline
6
6
  #The base options shared by all instances.
7
7
  BASE_OPTIONS = {:window_width => 79, #The width of the edit area.
8
8
  :scroll_step => 12, #The amount scrolled.
9
+
10
+ :prompt => ">", #The default prompt.
9
11
  :alt_prompt => "<< ", #The prompt when scrolled.
10
12
  #Set to nil to use main prompt.
11
13
 
@@ -15,6 +17,7 @@ module MiniReadline
15
17
  :eoi_detect => false, #Is end of input detection enabled?
16
18
 
17
19
  :history => false, #Is the history buffer enabled?
20
+ :log => [], #Default is no previous history
18
21
  :no_blanks => true, #No empty lines in history.
19
22
  :no_dups => true, #No duplicate lines in history.
20
23
 
@@ -6,6 +6,8 @@ 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
9
11
  class RawTerm
10
12
 
11
13
  #Create a mapper.
@@ -11,6 +11,8 @@ 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
14
16
  class RawTerm
15
17
 
16
18
  #Carriage return
@@ -11,6 +11,8 @@ module MiniReadline
11
11
  PLATFORM = :windows
12
12
 
13
13
  #The class used to manipulate console i/o on a low level.
14
+ #<br>Endemin Code Smells
15
+ # :reek:TooManyInstanceVariables
14
16
  class RawTerm
15
17
 
16
18
  #The sleep interval waiting for a key to be pressed.
@@ -11,6 +11,8 @@ 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
14
16
  class Readline
15
17
 
16
18
  #The options specifically associated with this instance.
@@ -18,14 +20,11 @@ module MiniReadline
18
20
 
19
21
  #Setup the instance of the mini line editor.
20
22
  #<br>Parameters:
21
- #* buffer - An array of strings used to contain the history. Use an empty
22
- # array to have a history buffer with no initial entries.
23
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={})
24
+ def initialize(instance_options={})
27
25
  @instance_options = instance_options
28
- @history = History.new(buffer)
26
+ log = (@instance_options[:log] || BASE_OPTIONS[:log] || []).clone
27
+ @history = History.new(log)
29
28
  @no_history = NoHistory.new
30
29
  end
31
30
 
@@ -38,8 +37,8 @@ module MiniReadline
38
37
  #<br>Parameters:
39
38
  #* prompt - A string used to prompt the user. '>' is popular.
40
39
  #* options - A hash of options; Typically symbol: value
41
- def readline(prompt, options = {})
42
- initialize_parms(prompt, options)
40
+ def readline(options = {})
41
+ initialize_parms(options)
43
42
  @edit.edit_process
44
43
  ensure
45
44
  @term.conclude
@@ -47,9 +46,8 @@ module MiniReadline
47
46
 
48
47
  #Initialize the read line process. This basically process the arguments
49
48
  #of the readline method.
50
- def initialize_parms(prompt, options)
49
+ def initialize_parms(options)
51
50
  set_options(options)
52
- set_prompt(prompt)
53
51
 
54
52
  history = @options[:history] ? @history : @no_history
55
53
  @edit = Edit.new(history, @options)
@@ -62,6 +60,7 @@ module MiniReadline
62
60
  @options = MiniReadline::BASE_OPTIONS.merge(instance_options)
63
61
  @options.merge!(options)
64
62
  (@term = @options[:term]).initialize_parms
63
+ set_prompt(@options[:prompt])
65
64
  end
66
65
 
67
66
  #Set up the prompt.
@@ -30,6 +30,8 @@ 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
33
35
  class Edit
34
36
 
35
37
  #Set up the edit instance.
@@ -7,6 +7,8 @@ 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
10
12
  class EditWindow
11
13
 
12
14
  #Determine the edit window limits.
@@ -20,7 +22,7 @@ module MiniReadline
20
22
  end
21
23
 
22
24
  #What is the offset of the window's left margin?
23
- attr_accessor :left_margin
25
+ attr_reader :left_margin
24
26
 
25
27
  #What is the offset of the window's right margin?
26
28
  def right_margin
@@ -41,7 +43,7 @@ module MiniReadline
41
43
  end
42
44
 
43
45
  #The shadow copy of what is actually on the screen?
44
- attr_accessor :window_buffer
46
+ attr_reader :window_buffer
45
47
 
46
48
  #The width of the window with the base prompt
47
49
  attr_reader :base_width
@@ -19,9 +19,9 @@ module MiniReadline
19
19
  old_margins = [left_margin, right_margin]
20
20
 
21
21
  if length < base_width
22
- self.left_margin = 0
22
+ @left_margin = 0
23
23
  elsif edit_posn < left_margin
24
- self.left_margin = [edit_posn - scroll_step, 0].max
24
+ @left_margin = [edit_posn - scroll_step, 0].max
25
25
  elsif edit_posn > right_margin
26
26
  self.right_margin = edit_posn + scroll_step
27
27
  end
@@ -1,4 +1,4 @@
1
1
  module MiniReadline
2
2
  #The current version of the mini_readline gem.
3
- VERSION = "0.1.3"
3
+ VERSION = "0.2.0"
4
4
  end
data/sire.rb CHANGED
@@ -87,6 +87,11 @@ class SIRE
87
87
  (\g<x>|\g<y>)$
88
88
  }x
89
89
 
90
+ #Test the WRE
91
+ def wre(str)
92
+ WRE.match str
93
+ end
94
+
90
95
  #Rubified Windows Regex.
91
96
  # a File name character, no spaces.
92
97
  # b File name character, with spaces.
@@ -103,6 +108,11 @@ class SIRE
103
108
  (\g<x>|\g<y>)$
104
109
  }x
105
110
 
111
+ #Test the RRE
112
+ def rre(str)
113
+ RRE.match str
114
+ end
115
+
106
116
  #Other Platforms Regex.
107
117
  # a File name character, no spaces.
108
118
  # b File name character, with spaces.
@@ -119,6 +129,10 @@ class SIRE
119
129
  (\g<x>|\g<y>)$
120
130
  }x
121
131
 
132
+ #Test the ORE
133
+ def ore(str)
134
+ ORE.match str
135
+ end
122
136
 
123
137
  #Execute a single line.
124
138
  def exec_line(line)
@@ -46,7 +46,24 @@ class MiniReadlineTester < Minitest::Test
46
46
  result = ''
47
47
 
48
48
  loop do
49
- result = edit.readline(">", history: true)
49
+ result = edit.readline(prompt: ">", history: true)
50
+ puts result.inspect
51
+ break unless result != 'quit'
52
+ end
53
+
54
+ assert_equal("quit", result)
55
+ end
56
+
57
+ def test_reading_a_line_no_history
58
+ puts
59
+ puts "No history: To finish this test, enter the word: quit"
60
+
61
+ edit = MiniReadline::Readline.new
62
+
63
+ result = ''
64
+
65
+ loop do
66
+ result = edit.readline(prompt: ">")
50
67
  puts result.inspect
51
68
  break unless result != 'quit'
52
69
  end
@@ -57,13 +74,13 @@ class MiniReadlineTester < Minitest::Test
57
74
  def test_end_of_input_detection
58
75
  edit = MiniReadline::Readline.new()
59
76
  puts "Exit by signaling end of input"
60
- assert_raises(MiniReadlineEOI) {edit.readline(">", eoi_detect: true)}
77
+ assert_raises(MiniReadlineEOI) {edit.readline(prompt: ">", eoi_detect: true)}
61
78
  end
62
79
 
63
80
  def test_prompt_verification
64
- opts = {:window_width => 39}
81
+ opts = {prompt: ">"*20, window_width: 39}
65
82
  edit = MiniReadline::Readline.new()
66
- assert_raises(RuntimeError) {edit.readline(">"*20, opts)}
83
+ assert_raises(RuntimeError) {edit.readline(opts)}
67
84
  end
68
85
 
69
86
 
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.1.3
4
+ version: 0.2.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-19 00:00:00.000000000 Z
11
+ date: 2016-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest