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
@@ -6,31 +6,31 @@ require_relative 'auto_complete/auto_file_source'
6
6
  require_relative 'auto_complete/quoted_file_folder_source'
7
7
  require_relative 'auto_complete/array_source'
8
8
 
9
- #* read_line/window/edit/auto_complete.rb - Process :auto_complete
9
+ # Process :auto_complete
10
10
  module MiniReadline
11
11
 
12
- #Set up the default auto-complete data source.
12
+ # Set up the default auto-complete data source.
13
13
  BASE_OPTIONS[:auto_source] = QuotedFileFolderSource
14
14
 
15
- #* read_line/window/edit/auto_complete.rb - Process :auto_complete
15
+ # Process :auto_complete
16
16
  class Edit
17
17
 
18
- #The auto-complete command.
18
+ # The auto-complete command.
19
19
  def auto_complete(_keyboard_args)
20
20
  if @options[:auto_complete] && (new_buffer = auto_manager.next(auto_trim))
21
21
  @edit_buffer = new_buffer
22
22
  @edit_posn = length
23
23
  else
24
- @term.beep
24
+ MiniTerm.beep
25
25
  end
26
26
  end
27
27
 
28
- #Get the base part of the edit buffer.
28
+ # Get the base part of the edit buffer.
29
29
  def auto_trim
30
30
  @edit_buffer[0...(@edit_posn)]
31
31
  end
32
32
 
33
- #Get the auto-complete manager
33
+ # Get the auto-complete manager
34
34
  def auto_manager
35
35
  @_auto_manager ||= AutoManager.new{@options[:auto_source].new(@options)}
36
36
  end
@@ -1,17 +1,17 @@
1
1
  # coding: utf-8
2
2
 
3
- #* array_source.rb - An array as the source for auto-complete.
3
+ # An array as the source for auto-complete.
4
4
  module MiniReadline
5
5
 
6
- #* array_source.rb - An array as the source for auto-complete.
6
+ # An array as the source for auto-complete.
7
7
  class ArraySource
8
8
 
9
- #Create a new file/folder auto-data source. NOP
9
+ # Create a new file/folder auto-data source. NOP
10
10
  def initialize(options)
11
11
  @options = options
12
12
  end
13
13
 
14
- #Construct a new data list for auto-complete
14
+ # Construct a new data list for auto-complete
15
15
  def rebuild(str)
16
16
  extract_root_pivot(str)
17
17
 
@@ -20,12 +20,12 @@ module MiniReadline
20
20
  @cycler = list.empty? ? nil : list.cycle
21
21
  end
22
22
 
23
- #Parse the string into the two basic components.
23
+ # Parse the string into the two basic components.
24
24
  def extract_root_pivot(str)
25
25
  @root, @pivot = /\S+$/ =~ str ? [$PREMATCH, $MATCH] : [str, ""]
26
26
  end
27
27
 
28
- #Get the array of data from either an array or a block.
28
+ # Get the array of data from either an array or a block.
29
29
  def get_array
30
30
  if (src = @options[:array_src]).is_a?(Proc)
31
31
  src.call
@@ -34,7 +34,7 @@ module MiniReadline
34
34
  end
35
35
  end
36
36
 
37
- #Get the next string for auto-complete
37
+ # Get the next string for auto-complete
38
38
  def next
39
39
  @root + @cycler.next
40
40
  end
@@ -1,17 +1,17 @@
1
1
  # coding: utf-8
2
2
 
3
- #* auto_file.rb - The data source for mysh file name auto-complete.
3
+ # The data source for mysh file name auto-complete.
4
4
  module MiniReadline
5
5
 
6
- #* auto_file_source.rb - A flexible file source for shell emulation.
6
+ # A flexible file source for shell emulation.
7
7
  class AutoFileSource
8
8
 
9
- #Create a new file/folder auto-data source. NOP
9
+ # Create a new file/folder auto-data source. NOP
10
10
  def initialize(_options)
11
11
  #Do nothing here!
12
12
  end
13
13
 
14
- #Construct a new data list for auto-complete
14
+ # Construct a new data list for auto-complete
15
15
  def rebuild(str)
16
16
  extract_root_pivot(str)
17
17
 
@@ -20,46 +20,46 @@ module MiniReadline
20
20
  @cycler = list.empty? ? nil : list.cycle
21
21
  end
22
22
 
23
- #The regex for extraction of the root and pivot.
23
+ # The regex for extraction of the root and pivot.
24
24
  EXTRACT = /("[^"\s][^"]*"?$)|(\S+$)/
25
25
 
26
- #Parse the string into the two basic components.
26
+ # Parse the string into the two basic components.
27
27
  def extract_root_pivot(str)
28
28
  @root, @pivot = EXTRACT =~ str ? [$PREMATCH, $MATCH] : [str, ""]
29
29
  end
30
30
 
31
- #Get the next string for auto-complete
31
+ # Get the next string for auto-complete
32
32
  def next
33
33
  @root + dress_up(@cycler.next)
34
34
  end
35
35
 
36
- #Prepare the file name for internal use.
37
- #<br>Endemic Code Smells
38
- #* :reek:UtilityFunction
36
+ # Prepare the file name for internal use.
37
+ # Endemic Code Smells
38
+ # :reek:UtilityFunction
39
39
  def dress_down(name)
40
40
  name.gsub("\\", "/").gsub('"', '')
41
41
  end
42
42
 
43
- #Prepare the file name for external use.
44
- #<br>Endemic Code Smells
45
- #* :reek:UtilityFunction
43
+ # Prepare the file name for external use.
44
+ # Endemic Code Smells
45
+ # :reek:UtilityFunction
46
46
  def dress_up(name)
47
47
  dress_up_quotes(dress_up_slashes(name))
48
48
  end
49
49
 
50
- #Dress up slashes and backslashes.
50
+ # Dress up slashes and backslashes.
51
51
  def dress_up_slashes(name)
52
52
  backslash? ? name.gsub("/", "\\") : name
53
53
  end
54
54
 
55
- #Dress up in quotes if needed.
56
- #<br>Endemic Code Smells
57
- #* :reek:UtilityFunction
55
+ # Dress up in quotes if needed.
56
+ # Endemic Code Smells
57
+ # :reek:UtilityFunction
58
58
  def dress_up_quotes(name)
59
59
  name[' '] ? "\"#{name}\"" : name
60
60
  end
61
61
 
62
- #Does this file name use backslashes?
62
+ # Does this file name use backslashes?
63
63
  def backslash?
64
64
  if @pivot.end_with?("\\")
65
65
  true
@@ -70,7 +70,7 @@ module MiniReadline
70
70
  elsif @pivot["/"]
71
71
  false
72
72
  else
73
- MiniReadline::PLATFORM == :windows
73
+ MiniTerm.windows?
74
74
  end
75
75
  end
76
76
 
@@ -1,18 +1,18 @@
1
1
  # coding: utf-8
2
2
 
3
- #* auto_manager.rb - The controller for auto-complete.
3
+ # The controller for auto-complete.
4
4
  module MiniReadline
5
5
 
6
- #* auto_manager.rb - The controller for auto-complete.
6
+ # The controller for auto-complete.
7
7
  class AutoManager
8
8
 
9
- #Create a new auto-complete manager.
9
+ # Create a new auto-complete manager.
10
10
  def initialize(&block)
11
11
  @_block = block
12
12
  @active = nil
13
13
  end
14
14
 
15
- #Get the next buffer string
15
+ # Get the next buffer string
16
16
  def next(buffer)
17
17
  unless @active && @old_buffer == buffer
18
18
  @active = source.rebuild(buffer)
@@ -25,7 +25,7 @@ module MiniReadline
25
25
  end
26
26
  end
27
27
 
28
- #Get the data source
28
+ # Get the data source
29
29
  def source
30
30
  @_source ||= @_block.call
31
31
  end
@@ -1,15 +1,15 @@
1
1
  # coding: utf-8
2
2
 
3
- #* file_folder_source.rb - The data source for auto-complete.
3
+ # The data source for auto-complete.
4
4
  module MiniReadline
5
5
 
6
- #* file_folder_source.rb - The data source for auto-complete.
6
+ # The data source for auto-complete.
7
7
  class FileFolderSource
8
8
 
9
- #Create a new file/folder auto-data source. NOP
9
+ # Create a new file/folder auto-data source. NOP
10
10
  def initialize(_options); end
11
11
 
12
- #Construct a new data list for auto-complete
12
+ # Construct a new data list for auto-complete
13
13
  def rebuild(str)
14
14
  extract_root_pivot(str)
15
15
 
@@ -18,12 +18,12 @@ module MiniReadline
18
18
  @cycler = list.empty? ? nil : list.cycle
19
19
  end
20
20
 
21
- #Parse the string into the two basic components.
21
+ # Parse the string into the two basic components.
22
22
  def extract_root_pivot(str)
23
23
  @root, @pivot = /\S+$/ =~ str ? [$PREMATCH, $MATCH] : [str, ""]
24
24
  end
25
25
 
26
- #Get the next string for auto-complete
26
+ # Get the next string for auto-complete
27
27
  def next
28
28
  @root + @cycler.next
29
29
  end
@@ -1,15 +1,15 @@
1
1
  # coding: utf-8
2
2
 
3
- #* quoted_file_folder_source.rb - The data source for auto-complete.
3
+ # The data source for auto-complete.
4
4
  module MiniReadline
5
5
 
6
- #* quoted_file_folder_source.rb - The data source for auto-complete.
6
+ # The data source for auto-complete.
7
7
  class QuotedFileFolderSource
8
8
 
9
- #Create a new file/folder auto-data source. NOP
9
+ # Create a new file/folder auto-data source. NOP
10
10
  def initialize(_options); end
11
11
 
12
- #Construct a new data list for auto-complete
12
+ # Construct a new data list for auto-complete
13
13
  def rebuild(str)
14
14
  extract_root_pivot(str)
15
15
 
@@ -18,15 +18,15 @@ module MiniReadline
18
18
  @cycler = list.empty? ? nil : list.cycle
19
19
  end
20
20
 
21
- #The parsing regular expression.
21
+ # The parsing regular expression.
22
22
  REGEX = /(?<=\")([^\"\s][^\"]*)?(?=\"?$)/
23
23
 
24
- #Parse the string into the two basic components.
24
+ # Parse the string into the two basic components.
25
25
  def extract_root_pivot(str)
26
26
  @root, @pivot = REGEX =~ str ? [$PREMATCH, $MATCH] : [str + '"', ""]
27
27
  end
28
28
 
29
- #Get the next string for auto-complete
29
+ # Get the next string for auto-complete
30
30
  def next
31
31
  "#{@root}#{@cycler.next}\""
32
32
  end
@@ -1,12 +1,12 @@
1
1
  # coding: utf-8
2
2
 
3
- #* read_line/window/edit/cancel.rb - Process :cancel
3
+ # Process :cancel
4
4
  module MiniReadline
5
5
 
6
- #* read_line/window/edit/cancel.rb - Process :cancel - delete all text.
6
+ # Process :cancel - delete all text.
7
7
  class Edit
8
8
 
9
- #All right! Scrap all of this and start over!
9
+ # All right! Scrap all of this and start over!
10
10
  def cancel(_keyboard_args)
11
11
  @edit_buffer = ""
12
12
  @edit_posn = 0
@@ -1,18 +1,18 @@
1
1
  # coding: utf-8
2
2
 
3
- #* read_line/window/edit/delete_left.rb - Process :delete_left
3
+ # Process :delete_left
4
4
  module MiniReadline
5
5
 
6
- #* read_line/window/edit/delete_all_left.rb - Process :delete_all_left
6
+ # Process :delete_all_left
7
7
  class Edit
8
8
 
9
- #The delete to the left command
9
+ # The delete to the left command
10
10
  def delete_all_left(_keyboard_args)
11
11
  if @edit_posn > 0
12
12
  @edit_buffer = @edit_buffer[@edit_posn..-1]
13
13
  @edit_posn = 0
14
14
  else
15
- @term.beep
15
+ MiniTerm.beep
16
16
  end
17
17
  end
18
18
  end
@@ -1,17 +1,17 @@
1
1
  # coding: utf-8
2
2
 
3
- #* read_line/window/edit/delete_all_right.rb - Process :delete_all_right
3
+ # Process :delete_all_right
4
4
  module MiniReadline
5
5
 
6
- #* read_line/window/edit/delete_right.rb - Process :delete_right
6
+ # Process :delete_right
7
7
  class Edit
8
8
 
9
- #The delete to the right
9
+ # The delete to the right
10
10
  def delete_all_right(_keyboard_args)
11
11
  if @edit_posn < self.length
12
12
  @edit_buffer = @edit_buffer[0...@edit_posn]
13
13
  else
14
- @term.beep
14
+ MiniTerm.beep
15
15
  end
16
16
  end
17
17
  end
@@ -1,12 +1,12 @@
1
1
  # coding: utf-8
2
2
 
3
- #* read_line/window/edit/delete_left.rb - Process :delete_left
3
+ # Process :delete_left
4
4
  module MiniReadline
5
5
 
6
- #* read_line/window/edit/delete_left.rb - Process :delete_left
6
+ # Process :delete_left
7
7
  class Edit
8
8
 
9
- #The delete to the left command
9
+ # The delete to the left command
10
10
  def delete_left(_keyboard_args)
11
11
  if @edit_posn > 0
12
12
  @edit_buffer = @edit_buffer[0...(@edit_posn-1)] +
@@ -14,7 +14,7 @@ module MiniReadline
14
14
 
15
15
  @edit_posn -= 1
16
16
  else
17
- @term.beep
17
+ MiniTerm.beep
18
18
  end
19
19
  end
20
20
  end
@@ -1,18 +1,18 @@
1
1
  # coding: utf-8
2
2
 
3
- #* read_line/window/edit/delete_right.rb - Process :delete_right
3
+ # Process :delete_right
4
4
  module MiniReadline
5
5
 
6
- #* read_line/window/edit/delete_right.rb - Process :delete_right
6
+ # Process :delete_right
7
7
  class Edit
8
8
 
9
- #The delete to the right
9
+ # The delete to the right
10
10
  def delete_right(_keyboard_args)
11
11
  if @edit_posn < self.length
12
12
  @edit_buffer = @edit_buffer[0...(@edit_posn)] +
13
13
  @edit_buffer[@edit_posn+1..-1]
14
14
  else
15
- @term.beep
15
+ MiniTerm.beep
16
16
  end
17
17
  end
18
18
  end
@@ -3,75 +3,73 @@
3
3
  require_relative 'edit_window/sync_window'
4
4
  require_relative 'edit_window/sync_cursor'
5
5
 
6
- #* read_line/edit_window.rb - Edit window support.
6
+ # Edit window support.
7
7
  module MiniReadline
8
8
 
9
- #* read_line/edit_window.rb - Support for the edit window.
9
+ # Support for the edit window.
10
10
  class EditWindow
11
11
 
12
- #Determine the edit window limits.
12
+ # Determine the edit window limits.
13
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
17
- @term = @options[:term]
18
17
 
19
18
  @left_margin, @window_buffer, @show_prompt = 0, "", true
20
19
  end
21
20
 
22
- #What is the offset of the window's left margin?
21
+ # What is the offset of the window's left margin?
23
22
  attr_reader :left_margin
24
23
 
25
- #What is the offset of the window's right margin?
24
+ # What is the offset of the window's right margin?
26
25
  def right_margin
27
26
  left_margin + active_width - 1
28
27
  end
29
28
 
30
- #Is the window currently in the scrolled state?
29
+ # Is the window currently in the scrolled state?
31
30
  def window_scrolled?
32
31
  left_margin > 0
33
32
  end
34
33
 
35
- #The shadow copy of what is actually on the screen?
34
+ # The shadow copy of what is actually on the screen?
36
35
  attr_reader :window_buffer
37
36
 
38
- #The width of the window with the base prompt
37
+ # The width of the window with the base prompt
39
38
  attr_reader :base_width
40
39
 
41
- #The width of the window with the alternate prompt
40
+ # The width of the window with the alternate prompt
42
41
  attr_reader :scroll_width
43
42
 
44
- #What is the full window width?
43
+ # What is the full window width?
45
44
  def window_width
46
45
  @options[:window_width]
47
46
  end
48
47
 
49
- #How wide is the active region of the window now?
48
+ # How wide is the active region of the window now?
50
49
  def active_width
51
50
  window_scrolled? ? scroll_width : base_width
52
51
  end
53
52
 
54
- #What is the current prompt?
53
+ # What is the current prompt?
55
54
  def prompt
56
55
  window_scrolled? ? @options[:scroll_prompt] : @options[:base_prompt]
57
56
  end
58
57
 
59
- #What is the scroll step?
58
+ # What is the scroll step?
60
59
  def scroll_step
61
60
  @options[:scroll_step]
62
61
  end
63
62
 
64
63
  private
65
64
 
66
- #Set the left margin
65
+ # Set the left margin
67
66
  def set_left_margin(value)
68
67
  @left_margin = value
69
68
  end
70
69
 
71
- #Set the right margin
72
- #<br>Notes
73
- #* If the right_margin is being set, then we must be scrolling. That is
74
- # why the scroll_width is used instead of active_width here.
70
+ # Set the right margin
71
+ # If the right_margin is being set, then we must be scrolling. That is
72
+ # why the scroll_width is used instead of active_width here.
75
73
  def set_right_margin(value)
76
74
  @left_margin = value - scroll_width + 1
77
75
  end