mini_readline 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -37
  3. data/lib/mini_readline.rb +14 -10
  4. data/lib/mini_readline/exceptions.rb +0 -3
  5. data/lib/mini_readline/maps.rb +126 -0
  6. data/lib/mini_readline/options.rb +3 -7
  7. data/lib/mini_readline/read_line.rb +17 -25
  8. data/lib/mini_readline/read_line/edit.rb +10 -11
  9. data/lib/mini_readline/read_line/edit/auto_complete.rb +7 -7
  10. data/lib/mini_readline/read_line/edit/auto_complete/array_source.rb +7 -7
  11. data/lib/mini_readline/read_line/edit/auto_complete/auto_file_source.rb +19 -19
  12. data/lib/mini_readline/read_line/edit/auto_complete/auto_manager.rb +5 -5
  13. data/lib/mini_readline/read_line/edit/auto_complete/file_folder_source.rb +6 -6
  14. data/lib/mini_readline/read_line/edit/auto_complete/quoted_file_folder_source.rb +7 -7
  15. data/lib/mini_readline/read_line/edit/cancel.rb +3 -3
  16. data/lib/mini_readline/read_line/edit/delete_all_left.rb +4 -4
  17. data/lib/mini_readline/read_line/edit/delete_all_right.rb +4 -4
  18. data/lib/mini_readline/read_line/edit/delete_left.rb +4 -4
  19. data/lib/mini_readline/read_line/edit/delete_right.rb +4 -4
  20. data/lib/mini_readline/read_line/edit/edit_window.rb +17 -19
  21. data/lib/mini_readline/read_line/edit/edit_window/sync_cursor.rb +4 -4
  22. data/lib/mini_readline/read_line/edit/edit_window/sync_window.rb +9 -9
  23. data/lib/mini_readline/read_line/edit/end_of_input.rb +4 -4
  24. data/lib/mini_readline/read_line/edit/enter.rb +3 -3
  25. data/lib/mini_readline/read_line/edit/go_end.rb +3 -3
  26. data/lib/mini_readline/read_line/edit/go_home.rb +3 -3
  27. data/lib/mini_readline/read_line/edit/go_left.rb +4 -4
  28. data/lib/mini_readline/read_line/edit/go_right.rb +4 -4
  29. data/lib/mini_readline/read_line/edit/insert_text.rb +3 -3
  30. data/lib/mini_readline/read_line/edit/next_history.rb +4 -4
  31. data/lib/mini_readline/read_line/edit/previous_history.rb +4 -4
  32. data/lib/mini_readline/read_line/edit/unmapped.rb +4 -4
  33. data/lib/mini_readline/read_line/edit/word_left.rb +4 -4
  34. data/lib/mini_readline/read_line/edit/word_right.rb +4 -4
  35. data/lib/mini_readline/read_line/history.rb +9 -9
  36. data/lib/mini_readline/read_line/no_history.rb +8 -8
  37. data/lib/mini_readline/read_line/prompt.rb +7 -7
  38. data/lib/mini_readline/version.rb +7 -1
  39. data/mini_readline.gemspec +5 -4
  40. data/rakefile.rb +8 -23
  41. data/sire.rb +1 -1
  42. data/tests/mini_readline_tests.rb +13 -14
  43. metadata +23 -34
  44. data/lib/mini_readline/raw_term.rb +0 -47
  45. data/lib/mini_readline/raw_term/ansi.rb +0 -70
  46. data/lib/mini_readline/raw_term/ansi/map.rb +0 -68
  47. data/lib/mini_readline/raw_term/ansi/set_posn.rb +0 -22
  48. data/lib/mini_readline/raw_term/ansi/window_width.rb +0 -17
  49. data/lib/mini_readline/raw_term/mapped_term.rb +0 -23
  50. data/lib/mini_readline/raw_term/mapped_term/mapper.rb +0 -53
  51. data/lib/mini_readline/raw_term/windows.rb +0 -100
  52. data/lib/mini_readline/raw_term/windows/map.rb +0 -63
  53. data/lib/mini_readline/raw_term/windows/set_posn.rb +0 -19
  54. data/lib/mini_readline/raw_term/windows/win_32_api.rb +0 -31
  55. data/lib/mini_readline/raw_term/windows/window_width.rb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '03240235936a20a5408ecd9162d0633b81f75d5c'
4
- data.tar.gz: 0e5e19408057351bdd835f84d8f4256627a84fd3
3
+ metadata.gz: 13d29a79c8b695d0491081997bfd2f78c2d6b6f4
4
+ data.tar.gz: a13e598d917734a3448e4d9316aee17cabc701b3
5
5
  SHA512:
6
- metadata.gz: 492cf0e29207d1daec3f523672aa8e33b6d157978b1cb949668862049312a5cdbb06a10dfa2b4c94d303568e435e419f7269f7b98ff2d75dbd496b71003c61ff
7
- data.tar.gz: f4a29768fdf9de8ef867de94257d1978b168a39ef21bf150bc06845aeb339ad503a79fe00d65143da7c3728cb1d9790bcce680664e6a23c917e249e4db106de5
6
+ metadata.gz: a92268026fa1ac6abfd573cb6debd80b4055fbe047dd58bae5a666f39745831397c089b54615537ad1aee765a19d480375fe208234ca2f957bb640abb46c2570
7
+ data.tar.gz: 568fa17fc7a40b0bf8f4bc7d01214e947f1503b8f49166a56636c049be91b595fd7284b86499942a91187cf75049855cc8eb0a13815400f56cf2ba2c3f6a7b1c
data/README.md CHANGED
@@ -225,11 +225,8 @@ BASE_OPTIONS = {
225
225
  #string "*" to use stars or " "
226
226
  #for invisible secrets.
227
227
 
228
- :initial => "", #The initial text for the entry.
228
+ :initial => ""} #The initial text for the entry.
229
229
  #An empty string for none.
230
-
231
- :term => nil} #Filled in by raw_term.rb
232
- #MiniReadline::RawTerm
233
230
  ```
234
231
 
235
232
  <br>While most of these options are self explanatory, a few could stand some
@@ -260,12 +257,6 @@ the history option **TURNED OFF**. Otherwise later entries will be able to
260
257
  retrieve the secret codes by just scrolling through previous entries.
261
258
  * :initial is the initial text used to prefill the readline edit area with the
262
259
  specified text. Leave as an empty string to default to the empty edit area.
263
- * :term is the interactive source of data, the console by default. The raw
264
- terminal console driver automatically adapts to the system environment
265
- (Windows or Other) so that correct operation is normally achieved with no
266
- further actions on the part of the user. The terminal support class can be
267
- changed, to a user supplied class, to get data from another source, such as
268
- a serial attached terminal.
269
260
 
270
261
  Finally the :window_width option is now ignored. Screen width now automatically
271
262
  determined.
@@ -274,10 +265,6 @@ determined.
274
265
  #### Notes
275
266
  * Since the compatibility mode does not accept an options hash, the only way to
276
267
  affect options in this case is to modify the MiniReadline::BASE_OPTIONS hash.
277
- * The :term option is the low level console io object used to get data
278
- from the user and control what is displayed. This gem automatically adapts to
279
- the environment and plugs in the needed object. This can be overridden where
280
- special io needs exist.
281
268
 
282
269
  ### Auto-Complete
283
270
  The mini readline gem comes with four auto-complete engines. These are:
@@ -417,29 +404,14 @@ system gem, use this:
417
404
  ## Cross Platform Portability Progress
418
405
 
419
406
  The mini_readline gem was initially designed for use with MRI version 1.9.3 or
420
- later. The long term goal is to be as portable to as many versions of Ruby and
421
- on as many operating systems platforms as is possible. So far the matrix of
422
- support looks like:
423
-
424
- Ruby | Win32 | Win64 | Cygwin | Linux | Mac
425
- ---------------|---------|---------|---------|---------|---------
426
- ruby 1.9.3p484 | Yes | Yes | ? | ? | ?
427
- ruby 2.1.6p336 | Yes | ? | ? | ? | ?
428
- ruby 2.2.3p173 | ? | ? | Yes | ? | ?
429
- ruby 2.3.3p222 | ? | Yes | ? | ? | ?
430
- jruby 9.1.5.0 | Mostly | ? | Planned | Planned | Planned
431
- rubinius | N/A | N/A | N/A | Maybe | Maybe
432
-
433
- <br>Where:
434
-
435
- * 'Yes' means good to go! Coded and tested OK!
436
- * 'Mostly' is mostly working but still some minor issues (See issue #7).
437
- * '?' _should_ work but are untested.
438
- * 'Planned' are not there yet and some work and much testing are needed.
439
- * 'N/A' entries reflect the fact that Rubinius does not run under Windows.
440
- * 'Maybe' entries are not on the radar now, but maybe later.
441
-
442
- There is clearly a lot of work to do.
407
+ later. With version 0.9.0, the internal raw_term code is replaced with the new
408
+ mini_term gem. That gem requires Ruby 2.0.0 or greater and now so does
409
+ mini_readline.
410
+
411
+ As almost all of the platform specific responsibility has been moved to the
412
+ mini_term gem, the tracking of portability progress issues now resides there
413
+ as well. Please see [mini_term](https://github.com/PeterCamilleri/mini_term)
414
+ for more information.
443
415
 
444
416
  ## Contributing
445
417
 
@@ -1,14 +1,17 @@
1
1
  # coding: utf-8
2
2
 
3
- require "English"
3
+ require "English"
4
+
5
+ require "mini_term"
6
+ MiniTerm.open(quiet: true, pass_ctrl_s: true)
7
+
8
+ require_relative "mini_readline/maps"
4
9
  require_relative "mini_readline/version"
5
10
  require_relative "mini_readline/exceptions"
6
11
  require_relative "mini_readline/options"
7
- require_relative "mini_readline/raw_term"
8
12
  require_relative "mini_readline/read_line"
9
13
 
10
- #The \MiniReadline module.
11
- #* mini_readline.rb - The root file that gathers up all the system's parts.
14
+ # The MiniReadline main module.
12
15
  module MiniReadline
13
16
 
14
17
  private_constant :Prompt
@@ -17,14 +20,15 @@ module MiniReadline
17
20
  private_constant :History
18
21
  private_constant :NoHistory
19
22
 
20
- #Get the shared instance of Readline.
21
- def self.get_reader
22
- @reader ||= Readline.new()
23
- end
24
-
25
- #The (limited) compatibility module function.
23
+ # The (limited) compatibility module function.
26
24
  def self.readline(prompt = "", history = nil, options = {})
27
25
  get_reader.readline(options.merge({prompt: prompt, history: history}))
28
26
  end
29
27
 
28
+ private
29
+
30
+ # Get the shared instance of Readline.
31
+ def self.get_reader
32
+ @reader ||= Readline.new()
33
+ end
30
34
  end
@@ -3,9 +3,6 @@
3
3
  # The exception raised when an enabled EOI is detected in a readline operation.
4
4
  class MiniReadlineEOI < StandardError; end
5
5
 
6
- # The exception raised when the keyboard mapping is invalid.
7
- class MiniReadlineKME < RuntimeError; end
8
-
9
6
  # The exception raised when the prompt is too long to fit.
10
7
  class MiniReadlinePLE < RuntimeError; end
11
8
 
@@ -0,0 +1,126 @@
1
+ # coding: utf-8
2
+
3
+ # Create the keyboard maps used by mini_readline.
4
+
5
+ # The Windows mapping.
6
+ MiniTerm.add_map(:windows) do |map|
7
+ # Make local copies of the prefixes for brevity.
8
+ x00 = MiniTerm::PREFIX_00
9
+ xe0 = MiniTerm::PREFIX_E0
10
+
11
+ map[" ".."~"] = :insert_text
12
+
13
+ #Left Arrows
14
+ map[x00+"K"] = :go_left
15
+ map[xe0+"K"] = :go_left
16
+
17
+ map[x00+"s"] = :word_left
18
+ map[xe0+"s"] = :word_left
19
+
20
+ #Right Arrows
21
+ map[x00+"M"] = :go_right
22
+ map[xe0+"M"] = :go_right
23
+
24
+ map[x00+"t"] = :word_right
25
+ map[xe0+"t"] = :word_right
26
+
27
+ #Up Arrows
28
+ map[x00+"H"] = :previous_history
29
+ map[xe0+"H"] = :previous_history
30
+
31
+ #Down Arrows
32
+ map[x00+"P"] = :next_history
33
+ map[xe0+"P"] = :next_history
34
+
35
+ #The Home keys
36
+ map[x00+"G"] = :go_home
37
+ map[xe0+"G"] = :go_home
38
+
39
+ #The End keys
40
+ map[x00+"O"] = :go_end
41
+ map[xe0+"O"] = :go_end
42
+
43
+ #The Backspace key
44
+ map["\x08"] = :delete_left
45
+
46
+ #The Delete keys
47
+ map["\x7F"] = :delete_right
48
+ map[x00+"S"] = :delete_right
49
+ map[xe0+"S"] = :delete_right
50
+
51
+ #Auto-completion.
52
+ map["\t"] = :auto_complete
53
+
54
+ #The Enter key
55
+ map["\x0D"] = :enter
56
+
57
+ #The Escape key
58
+ map["\e"] = :cancel
59
+
60
+ #End of Input
61
+ map["\x1A"] = :end_of_input
62
+ end
63
+
64
+ # The ANSI mapping.
65
+ MiniTerm.add_map(:ansi) do |map|
66
+
67
+ map[" ".."~"] = :insert_text
68
+
69
+ #Left Arrows
70
+ map["\e[D"] = :go_left
71
+ map["\eOD"] = :go_left
72
+ map["\x02"] = :go_left
73
+
74
+ map["\e[1;5D"] = :word_left
75
+ map["\eb"] = :word_left
76
+
77
+ #Right Arrows
78
+ map["\e[C"] = :go_right
79
+ map["\eOC"] = :go_right
80
+ map["\x06"] = :go_right
81
+
82
+ map["\e[1;5C"] = :word_right
83
+ map["\ef"] = :word_right
84
+
85
+ #Up Arrows
86
+ map["\e[A"] = :previous_history
87
+ map["\eOA"] = :previous_history
88
+ map["\x12"] = :previous_history
89
+
90
+ #Down Arrows
91
+ map["\e[B"] = :next_history
92
+ map["\eOB"] = :next_history
93
+
94
+ #The Home keys
95
+ map["\e[H"] = :go_home
96
+ map["\eOH"] = :go_home
97
+ map["\x01"] = :go_home
98
+
99
+ #The End keys
100
+ map["\e[F"] = :go_end
101
+ map["\eOF"] = :go_end
102
+ map["\x05"] = :go_end
103
+
104
+ #The Backspace key
105
+ map["\x7F"] = :delete_left
106
+ map["\x08"] = :delete_left
107
+ map["\x15"] = :delete_all_left
108
+
109
+ #The Delete keys
110
+ map["\x1F"] = :delete_right
111
+ map["\e[3~"] = :delete_right
112
+ map["\x0B"] = :delete_all_right
113
+
114
+ #Auto-completion.
115
+ map["\t"] = :auto_complete
116
+
117
+ #The Enter key
118
+ map["\x0D"] = :enter
119
+
120
+ #The Cancel key
121
+ map["\f"] = :cancel
122
+
123
+ #End of Input
124
+ map["\ez"] = :end_of_input
125
+ end
126
+
@@ -1,9 +1,9 @@
1
1
  # coding: utf-8
2
2
 
3
- #* options.rb - Options selection, control, and access
3
+ # Options selection, control, and access
4
4
  module MiniReadline
5
5
 
6
- #The base options shared by all instances.
6
+ # The base options shared by all instances.
7
7
  BASE_OPTIONS = {:scroll_step => 12, #The amount scrolled.
8
8
 
9
9
  :prompt => ">", #The default prompt.
@@ -25,10 +25,6 @@ module MiniReadline
25
25
  #string "*" to use stars or " "
26
26
  #for invisible secrets.
27
27
 
28
- :initial => "", #The initial text for the entry.
28
+ :initial => ""} #The initial text for the entry.
29
29
  #An empty string for none.
30
-
31
- :term => nil} #Filled in by raw_term.rb
32
- #MiniReadline::RawTerm
33
-
34
30
  end
@@ -5,21 +5,18 @@ require_relative 'read_line/edit'
5
5
  require_relative 'read_line/history'
6
6
  require_relative 'read_line/no_history'
7
7
 
8
-
9
- #* read_line.rb - The ReadLine class that does the actual work.
8
+ # The ReadLine class that does the actual work.
10
9
  module MiniReadline
11
10
 
12
- #The \Readline class that does the actual work of getting lines from the
11
+ #The Readline class that does the actual work of getting lines from the
13
12
  #user. Note that each instance of this class maintains its own copy of
14
13
  #the optional command history.
15
14
  class Readline
16
15
 
17
- #The options specifically associated with this instance.
16
+ # The options specifically associated with this instance.
18
17
  attr_reader :instance_options
19
18
 
20
- #Setup the instance of the mini line editor.
21
- #<br>Parameters:
22
- #* instance_options - A hash of options owned by this \Readline instance.
19
+ # Setup the instance of the mini line editor.
23
20
  def initialize(instance_options={})
24
21
  @instance_options = instance_options
25
22
  log = (@instance_options[:log] || BASE_OPTIONS[:log] || []).clone
@@ -27,26 +24,23 @@ module MiniReadline
27
24
  @no_history = NoHistory.new
28
25
  end
29
26
 
30
- #Get the history buffer of this read line instance.
27
+ # Get the history buffer of this read line instance.
31
28
  def history
32
29
  @history.history
33
30
  end
34
31
 
35
- #Read a line from the console with edit and history.
36
- #<br>Parameters:
37
- #* prompt - A string used to prompt the user. '>' is popular.
38
- #* options - A hash of options; Typically symbol: value
32
+ # Read a line from the console with edit and history.
39
33
  def readline(options = {})
40
34
  suppress_warnings
41
35
  initialize_parms(options)
42
- @edit.edit_process
36
+ MiniTerm.raw { @edit.edit_process }
43
37
  ensure
44
- @term.conclude
45
38
  restore_warnings
39
+ puts
46
40
  end
47
41
 
48
- #Initialize the read line process. This basically process the arguments
49
- #of the readline method.
42
+ # Initialize the read line process. This basically process the arguments
43
+ # of the readline method.
50
44
  def initialize_parms(options)
51
45
  set_options(options)
52
46
 
@@ -56,20 +50,18 @@ module MiniReadline
56
50
  @history.initialize_parms(@options)
57
51
  end
58
52
 
59
- #Set up the options
53
+ # Set up the options
60
54
  def set_options(options)
61
55
  @options = MiniReadline::BASE_OPTIONS
62
56
  .merge(instance_options)
63
57
  .merge(options)
64
58
 
65
- (@term = @options[:term]).initialize_parms
66
-
67
- @options[:window_width] = @term.window_width - 1
59
+ @options[:window_width] = MiniTerm.width - 1
68
60
  set_prompt(@options[:prompt])
69
61
  verify_mask(@options[:secret_mask])
70
62
  end
71
63
 
72
- #Set up the prompt.
64
+ # Set up the prompt.
73
65
  def set_prompt(prompt)
74
66
  @options[:base_prompt] = Prompt.new(prompt)
75
67
  @options[:scroll_prompt] = Prompt.new(@options[:alt_prompt] || prompt)
@@ -78,7 +70,7 @@ module MiniReadline
78
70
  verify_prompt(@options[:scroll_prompt])
79
71
  end
80
72
 
81
- #Verify that the prompt will fit!
73
+ # Verify that the prompt will fit!
82
74
  def verify_prompt(prompt)
83
75
  unless (@options[:window_width] - prompt.length) >
84
76
  (@options[:scroll_step] * 2)
@@ -86,20 +78,20 @@ module MiniReadline
86
78
  end
87
79
  end
88
80
 
89
- #Verify the secret mask
81
+ # Verify the secret mask
90
82
  def verify_mask(secret)
91
83
  if secret && secret.length != 1
92
84
  fail MiniReadlineSME, "Secret mask must be nil or a single character string."
93
85
  end
94
86
  end
95
87
 
96
- #No warnings please!
88
+ # No warnings please!
97
89
  def suppress_warnings
98
90
  @old_stderr = $stderr
99
91
  $stderr = File.open(File::NULL, 'w')
100
92
  end
101
93
 
102
- #Restore warnings to their typical ugliness.
94
+ # Restore warnings to their typical ugliness.
103
95
  def restore_warnings
104
96
  $stderr.close
105
97
  $stderr = @old_stderr
@@ -28,17 +28,16 @@ require_relative 'edit/end_of_input'
28
28
 
29
29
  require_relative 'edit/unmapped'
30
30
 
31
- #* read_line/edit.rb - The line editor.
31
+ # The line editor.
32
32
  module MiniReadline
33
33
 
34
- #* read_line/edit.rb - The line editor.
34
+ # The line editor.
35
35
  class Edit
36
36
 
37
- #Set up the edit instance.
37
+ # Set up the edit instance.
38
38
  def initialize(history, options)
39
39
  @options = options
40
40
  @history = history
41
- @term = @options[:term]
42
41
  @edit_buffer = @options[:initial]
43
42
  @edit_posn = @edit_buffer.length
44
43
  @working = true
@@ -46,36 +45,36 @@ module MiniReadline
46
45
  @edit_window = EditWindow.new(@options)
47
46
  end
48
47
 
49
- #The main edit buffer
48
+ # The main edit buffer
50
49
  attr_reader :edit_buffer
51
50
 
52
- #The current edit position
51
+ # The current edit position
53
52
  attr_reader :edit_posn
54
53
 
55
- #How long is the current string?
54
+ # How long is the current string?
56
55
  def length
57
56
  edit_buffer.length
58
57
  end
59
58
 
60
- #Interact with the user
59
+ # Interact with the user
61
60
  def edit_process
62
61
  result = edit_loop
63
62
  @history.append_history(result)
64
63
  result + "\n"
65
64
  end
66
65
 
67
- #The line editor processing loop.
66
+ # The line editor processing loop.
68
67
  def edit_loop
69
68
  while @working
70
69
  @edit_window.sync_window(edit_buffer, edit_posn)
71
70
  @edit_window.sync_cursor(edit_posn)
72
- process_keystroke(@term.get_mapped_keystroke)
71
+ process_keystroke(MiniTerm.get_mapped_char)
73
72
  end
74
73
 
75
74
  edit_buffer
76
75
  end
77
76
 
78
- #Process a keystroke.
77
+ # Process a keystroke.
79
78
  def process_keystroke(key_cmd)
80
79
  send(key_cmd[0], key_cmd)
81
80
  end