mini_readline 0.6.3 → 0.6.4

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: c5ddc6a871c38d411642616cbac4de44c9a1c70f
4
- data.tar.gz: 56493ba01fa93eb825956fcfb9618d002da8b676
3
+ metadata.gz: 4cfcf3f362557c6f4ab5ec93418b4ca44ae54a07
4
+ data.tar.gz: cf0b61fd89ff2bb18d1b8b9a3d06d343e8e2d896
5
5
  SHA512:
6
- metadata.gz: 57fa6ee1baa1af25e8730abb94495c7f2493e731b1f1f8ee1293c7e0d6e601e26b067be321b1bd6414ebe375416fad72f9ab59e48f208ac4645a60abd50fbfb6
7
- data.tar.gz: 6fa28ed47391a1d295db390b82b1c8adf9610b28cf58d0778a79004d52f9b9459f8756f71d2fc0a054d1429da3d979e7979f5d9162e672c7dacf8ad27ebae666
6
+ metadata.gz: 709d6bac30409e21669602e21cc55d0caa9ff198b9599ddfdcc73cbe45f6b6acb4ccc4655e894314af175fc01679b57fa2ca299b4cdf149a3eb11080654952b8
7
+ data.tar.gz: 6cb9c33a15db38317a2a7d933cc61acf4f01d83d996d739316821ac21de9eb6eaf3b9865d0701be63971756c69629f9860e1179757cec830001b8966b93e955f
data/README.md CHANGED
@@ -126,7 +126,7 @@ MiniReadline.readline('>', false)
126
126
  ```
127
127
  While it does require some small changes, the latter form is the preferred one.
128
128
 
129
- ##### Module Aliasing
129
+ ##### Module Aliasing [Deprecated]
130
130
 
131
131
  For enhanced compatibility, the mini_readline gem has the ability to alias
132
132
  itself as the readline gem. This ability is subject to the following list
@@ -173,6 +173,10 @@ porting to switch to the mini_readline gem.
173
173
  For the most part, compatible mode exists to make that porting process an
174
174
  easier one.
175
175
 
176
+ **IMPORTANT NOTE: The module aliasing feature is now deprecated. For now there
177
+ will be no change, soon warnings will ensue, then errors. Look for this
178
+ feature to go away by version 0.7.0 unless some feedback is received.**
179
+
176
180
  ### Native Mode
177
181
 
178
182
  In native mode, instances of the Readline class are used to get user input.
@@ -251,6 +255,10 @@ BASE_OPTIONS = {
251
255
  :no_blanks => true, #No empty lines in history.
252
256
  :no_dups => true, #No duplicate lines in history.
253
257
 
258
+ :secret_mask => nil, #No secret password mask. Use the
259
+ #string "*" to use stars or " "
260
+ #for invisible secrets.
261
+
254
262
  :term => nil, #Filled in by raw_term.rb
255
263
  #MiniReadline::RawTerm
256
264
 
@@ -278,6 +286,9 @@ more details.
278
286
  * :eoi_detect is used to control the end of input detection logic. If disabled,
279
287
  eoi inputs are treated as unmapped. If enabled, they raise a MiniReadlineEOI
280
288
  exception.
289
+ * :secret_mask is a masking character to be used for sensitive input like a
290
+ password or missile launch code. This should be exactly one character long.
291
+ Typical values are "*" or " ".
281
292
  * :term is the interactive source of data, the console by default. The raw
282
293
  terminal console driver automatically adapts to the system environment
283
294
  (Windows or Other) so that correct operation is normally achieved with no
@@ -20,12 +20,14 @@ module MiniReadline
20
20
  private_constant :History
21
21
  private_constant :NoHistory
22
22
 
23
- #The shared instance of Readline.
24
- @reader = MiniReadline::Readline.new()
23
+ #Get the shared instance of Readline.
24
+ def self.get_reader
25
+ @reader ||= Readline.new()
26
+ end
25
27
 
26
28
  #The (limited) compatibility module function.
27
29
  def self.readline(prompt = "", history = nil)
28
- @reader.readline(prompt: prompt, history: history)
30
+ get_reader.readline(prompt: prompt, history: history)
29
31
  end
30
32
 
31
33
  end
@@ -22,6 +22,10 @@ module MiniReadline
22
22
  :no_blanks => true, #No empty lines in history.
23
23
  :no_dups => true, #No duplicate lines in history.
24
24
 
25
+ :secret_mask => nil, #No secret password mask. Use the
26
+ #string "*" to use stars or " "
27
+ #for invisible secrets.
28
+
25
29
  :term => nil, #Filled in by raw_term.rb
26
30
  #MiniReadline::RawTerm
27
31
 
@@ -62,6 +62,7 @@ module MiniReadline
62
62
  @options.merge!(options)
63
63
  (@term = @options[:term]).initialize_parms
64
64
  set_prompt(@options[:prompt])
65
+ verify_mask(@options[:secret_mask])
65
66
  end
66
67
 
67
68
  #Set up the prompt.
@@ -81,6 +82,13 @@ module MiniReadline
81
82
  end
82
83
  end
83
84
 
85
+ #Verify the secret mask
86
+ def verify_mask(secret)
87
+ if secret && secret.length != 1
88
+ fail "Secret mask must be nil or a single character string."
89
+ end
90
+ end
91
+
84
92
  #No warnings please!
85
93
  def suppress_warnings
86
94
  @old_stderr = $stderr
@@ -35,7 +35,13 @@ module MiniReadline
35
35
 
36
36
  #Compute what should be on the screen.
37
37
  def build_screen_image(edit_buffer)
38
- edit_buffer[left_margin..right_margin].ljust(active_width)
38
+ working_region = edit_buffer[left_margin..right_margin]
39
+
40
+ if (mask = @options[:secret_mask])
41
+ mask[0] * working_region.length
42
+ else
43
+ working_region
44
+ end.ljust(active_width)
39
45
  end
40
46
 
41
47
  #Bring the screen into agreement with the image.
@@ -1,4 +1,4 @@
1
1
  module MiniReadline
2
2
  #The current version of the mini_readline gem.
3
- VERSION = "0.6.3"
3
+ VERSION = "0.6.4"
4
4
  end
@@ -73,6 +73,40 @@ class MiniReadlineTester < Minitest::Test
73
73
  assert_equal("quit", result)
74
74
  end
75
75
 
76
+ def test_reading_a_password
77
+ puts
78
+ puts "To finish this test, enter the word: password"
79
+
80
+ edit = MiniReadline::Readline.new
81
+
82
+ result = ''
83
+
84
+ loop do
85
+ result = edit.readline(prompt: ">", secret_mask: "*").chomp
86
+ puts result.inspect
87
+ break unless result != "password"
88
+ end
89
+
90
+ assert_equal("password", result)
91
+ end
92
+
93
+ def test_reading_blanked
94
+ puts
95
+ puts "To finish this test, enter the word: password"
96
+
97
+ edit = MiniReadline::Readline.new
98
+
99
+ result = ''
100
+
101
+ loop do
102
+ result = edit.readline(prompt: ">", secret_mask: " ").chomp
103
+ puts result.inspect
104
+ break unless result != "password"
105
+ end
106
+
107
+ assert_equal("password", result)
108
+ end
109
+
76
110
  def test_array_complete
77
111
  puts "\nPlease select an approved fruit."
78
112
 
@@ -151,6 +185,14 @@ class MiniReadlineTester < Minitest::Test
151
185
  assert_raises(RuntimeError) {edit.readline(opts)}
152
186
  end
153
187
 
188
+ def test_mask_verification
189
+ opts = {prompt: ">", secret_mask: ""}
190
+ edit = MiniReadline::Readline.new()
191
+ assert_raises(RuntimeError) {edit.readline(opts)}
154
192
 
193
+ opts = {prompt: ">", secret_mask: "xx"}
194
+ edit = MiniReadline::Readline.new()
195
+ assert_raises(RuntimeError) {edit.readline(opts)}
196
+ end
155
197
 
156
198
  end
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.6.3
4
+ version: 0.6.4
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-09-08 00:00:00.000000000 Z
11
+ date: 2016-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest