mini_readline 0.0.5 → 0.0.6

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: 5cb399d7a4ffc7fcf703330024c6422386ff2c67
4
- data.tar.gz: 748e2eacc096c0eadd51b84f79586b411d1abfa6
3
+ metadata.gz: 8e937dfc43b28cefc768efd3bdbce315d86dbb57
4
+ data.tar.gz: 3970f861094c4db5807291447aeb70a1e2144a4a
5
5
  SHA512:
6
- metadata.gz: 63c11cfeaf488a056405e9b8f6b0c07536b6ef3727d7d584b516f2252c1af8272fe35c2f35f9c5b41d7d2c5de13f8b5b7bc09a9329b3e12db23e03c7da2db939
7
- data.tar.gz: acc1855c61e90bba831229f9a05bbfc125371075ba48a4bd8baf2a5fbd695c18495ca4244c1ca19d76ea5bda978a72dfcc56aa65df3622bfbab9ab50e05834d3
6
+ metadata.gz: 7fbccdab691c99d79feed201ccee633a04ac9c609b4d18318bc2425b544c7b8e578baa77b905b2deb6f597f22dde52f30b06a392d5d402e997194576893dde3b
7
+ data.tar.gz: 8a34bd1a0c44816dab5f6b7e709811be0a6cf19463cd8468c7eb6ff9dbd80c667d8975297982fa3132277860f924a144535f6a68fa020ff3b79ad06745cdd24d
data/README.md CHANGED
@@ -52,9 +52,10 @@ Go to start | Home, Pad Home | Home, Ctrl-A
52
52
  Go to end | End, Pad End | End, Ctrl-E
53
53
  Previous History | Up Arrow, Pad Up | Up Arrow, Ctrl-R
54
54
  Next History | Down Arrow, Pad Down | Down Arrow
55
- Erase Left | Backspace | Backspace, Ctrl-H
55
+ Erase Left | Backspace, Ctrl-H | Backspace, Ctrl-H
56
56
  Erase Right | Delete, Ctrl-Backspace | Delete, Ctrl-Backspace
57
57
  Erase All | Escape | Ctrl-L
58
+ Auto-complete | Tab, Ctrl-I | Tab, Ctrl-I
58
59
 
59
60
  ### Notes
60
61
  * The label "Other" is an umbrella that bundles together the Linux, Mac,
@@ -231,10 +232,11 @@ system gem, use this:
231
232
 
232
233
  ## Testing
233
234
  To date this code has been tested under:
234
- * Windows 7 with MRI ruby 2.1.6p336 (2015-04-13 revision 50298) [i386-mingw32]
235
- * Windows 7 + Cygwin with ruby 2.2.3p173 (2015-08-18 revision 51636) [i386-cygwin]
235
+ * Windows 7 with ruby 1.9.3p484 (2013-11-22) [i386-mingw32]
236
+ * Windows 7 with ruby 2.1.6p336 (2015-04-13 revision 50298) [i386-mingw32]
237
+ * Windows 7+Cygwin with ruby 2.2.3p173 (2015-08-18 revision 51636) [i386-cygwin]
236
238
 
237
- <br>More testing is clearly called for.
239
+ <br>**More testing is clearly called for.**
238
240
 
239
241
  ## Contributing
240
242
 
@@ -9,6 +9,9 @@ module MiniReadline
9
9
  :alt_prompt => "<< ", #The prompt when scrolled.
10
10
  #Set to nil to use main prompt.
11
11
 
12
+ :auto_complete => true, #Is auto complete enabled?
13
+ :auto_source => nil, #Filled in by auto_complete.rb
14
+
12
15
  :history => false, #Is the history buffer enabled?
13
16
  :no_blanks => true, #No empty lines in history.
14
17
  :no_dups => true, #No duplicate lines in history.
@@ -51,6 +51,9 @@ module MiniReadline
51
51
  MAP["\x1F"] = [:delete_right]
52
52
  MAP["\e[3~"] = [:delete_right]
53
53
 
54
+ #Auto-completion.
55
+ MAP["\t"] = [:auto_complete]
56
+
54
57
  #The Enter key
55
58
  MAP["\x0D"] = [:enter]
56
59
 
@@ -48,6 +48,9 @@ module MiniReadline
48
48
  MAP["\x00S"] = [:delete_right]
49
49
  MAP[pfx+"S"] = [:delete_right]
50
50
 
51
+ #Auto-completion.
52
+ MAP["\t"] = [:auto_complete]
53
+
51
54
  #The Enter key
52
55
  MAP["\x0D"] = [:enter]
53
56
 
@@ -3,29 +3,22 @@
3
3
  #* windows/win_32_api.rb - Support for selected low level Win32 API entry points.
4
4
  module MiniReadline
5
5
 
6
- require 'fiddle'
6
+ require 'dl'
7
7
 
8
- #The classic \Win32API gem is deprecated, so we emulate it with fiddle.
8
+ #The classic \Win32API gem is deprecated, so we emulate it with DL.
9
9
  class Win32API
10
10
 
11
- #Use standard calling conventions
12
- STDCALL = 1
13
-
14
11
  #A hash of DLL files used for one or more API entry points.
15
12
  DLL = {}
16
13
 
17
- #Type mappings.
18
- TYPES = {"0" => Fiddle::TYPE_VOID,
19
- "S" => Fiddle::TYPE_VOIDP,
20
- "I" => Fiddle::TYPE_LONG}
14
+ #Type mappings
15
+ TYPEMAP = {"0" => DL::TYPE_VOID, "S" => DL::TYPE_VOIDP, "I" => DL::TYPE_LONG}
21
16
 
22
17
  #Set up an API entry point.
23
- def initialize(dllname, func, import)
24
- @proto = import.join.tr("VPpNnLlIi", "0SSI").chomp('0').split('')
25
-
26
- handle = DLL[dllname] ||= Fiddle.dlopen(dllname)
27
-
28
- @func = Fiddle::Function.new(handle[func], TYPES.values_at(*@proto), STDCALL)
18
+ def initialize(dllname, func, import, export = "0", calltype = :stdcall)
19
+ @proto = [import].join.tr("VPpNnLlIi", "0SSI").sub(/^(.)0*$/, '\1')
20
+ handle = DLL[dllname] ||= DL.dlopen(dllname)
21
+ @func = DL::CFunc.new(handle[func], TYPEMAP[export.tr("VPpNnLlIi", "0SSI")], func, calltype)
29
22
  end
30
23
 
31
24
  #Call the Win 32 API entry point with appropriate arguments.
@@ -41,7 +34,8 @@ module MiniReadline
41
34
  end
42
35
  end
43
36
 
44
- @func.call(*args).to_i || 0
37
+ @func.call(args).to_i || 0
45
38
  end
39
+
46
40
  end
47
41
  end
@@ -24,14 +24,14 @@ module MiniReadline
24
24
 
25
25
  #Set up the Windows Raw Terminal.
26
26
  def initialize
27
- @_getch = Win32API.new("msvcrt", "_getch", [])
28
- @_kbhit = Win32API.new("msvcrt", "_kbhit", [])
27
+ @_getch = Win32API.new("msvcrt", "_getch", [], 'I')
28
+ @_kbhit = Win32API.new("msvcrt", "_kbhit", [], 'I')
29
29
  @_beep = Win32API.new("user32", "MessageBeep", ['L'])
30
30
  @_set_cursor_posn = Win32API.new("kernel32", "SetConsoleCursorPosition",
31
- ['L','L'])
31
+ ['L','L'], 'L')
32
32
  @_get_screen_info = Win32API.new("kernel32", "GetConsoleScreenBufferInfo",
33
- ['L','P'])
34
- @_get_handle = Win32API.new("kernel32", "GetStdHandle", ['L'])
33
+ ['L','P'], 'L')
34
+ @_get_handle = Win32API.new("kernel32", "GetStdHandle", ['L'], 'L')
35
35
  end
36
36
 
37
37
  #Output a string
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+
3
+ #* auto_manager.rb - The controller for auto-complete.
4
+ module MiniReadline
5
+
6
+ #* auto_manager.rb - The controller for auto-complete.
7
+ class AutoManager
8
+
9
+ #Create a new auto-complete manager.
10
+ def initialize(&block)
11
+ @_block = block
12
+ end
13
+
14
+ #Get the next pivot string
15
+ def next(pivot)
16
+ unless @cycler && @old_pivot == pivot
17
+ @cycler = source.rebuild(pivot)
18
+ end
19
+
20
+ if @cycler
21
+ @old_pivot = @cycler.next
22
+ else
23
+ @old_pivot = nil
24
+ end
25
+ end
26
+
27
+ #Get the data source
28
+ def source
29
+ @_source ||= @_block.call
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+
3
+ #* file_folder_source.rb - The data source for auto-complete.
4
+ module MiniReadline
5
+
6
+ #* file_folder_source.rb - The data source for auto-complete.
7
+ class FileFolderSource
8
+
9
+ #Construct a new data list for auto-complete
10
+ def rebuild(pivot)
11
+ list = Dir.glob(pivot + '*')
12
+
13
+ unless list.empty?
14
+ list.cycle
15
+ else
16
+ nil
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,43 @@
1
+ # coding: utf-8
2
+
3
+ require_relative 'auto_complete/auto_manager'
4
+ require_relative 'auto_complete/file_folder_source'
5
+
6
+ #* read_line/window/edit/auto_complete.rb - Process :auto_complete
7
+ module MiniReadline
8
+
9
+ #Set up the default auto-complete data source.
10
+ BASE_OPTIONS[:auto_source] = FileFolderSource
11
+
12
+ #* read_line/window/edit/auto_complete.rb - Process :auto_complete
13
+ class Edit
14
+
15
+ #The auto-complete command.
16
+ def auto_complete(_keyboard_args)
17
+ root, pivot = get_root_pivot
18
+
19
+ if (new_pivot = auto_manager.next(pivot))
20
+ @edit_buffer = root + new_pivot
21
+ @edit_posn = length
22
+ else
23
+ @term.beep
24
+ end
25
+ end
26
+
27
+ #Get the key components of the auto-complete process.
28
+ def get_root_pivot
29
+ /\S+$/ =~ (str = auto_trim) ? [$`.to_s, $~.to_s] : [str, ""]
30
+ end
31
+
32
+ #Get the base part of the edit buffer.
33
+ def auto_trim
34
+ @edit_buffer[0...(@edit_posn)]
35
+ end
36
+
37
+ #Get the auto-complete manager
38
+ def auto_manager
39
+ @_auto_manager ||= AutoManager.new { @options[:auto_source].new }
40
+ end
41
+ end
42
+
43
+ end
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
- require_relative 'edit_window'
3
+ require_relative 'edit/edit_window'
4
4
 
5
5
  require_relative 'edit/insert_text'
6
6
  require_relative 'edit/enter'
@@ -21,6 +21,8 @@ require_relative 'edit/cancel'
21
21
  require_relative 'edit/previous_history'
22
22
  require_relative 'edit/next_history'
23
23
 
24
+ require_relative 'edit/auto_complete'
25
+
24
26
  require_relative 'edit/unmapped'
25
27
 
26
28
  #* read_line/edit.rb - The line editor.
@@ -1,4 +1,4 @@
1
1
  module MiniReadline
2
2
  #The current version of the mini_readline gem.
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  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.0.5
4
+ version: 0.0.6
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-12 00:00:00.000000000 Z
11
+ date: 2016-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -93,9 +93,15 @@ files:
93
93
  - lib/mini_readline/raw_term/windows/win_32_api.rb
94
94
  - lib/mini_readline/read_line.rb
95
95
  - lib/mini_readline/read_line/edit.rb
96
+ - lib/mini_readline/read_line/edit/auto_complete.rb
97
+ - lib/mini_readline/read_line/edit/auto_complete/auto_manager.rb
98
+ - lib/mini_readline/read_line/edit/auto_complete/file_folder_source.rb
96
99
  - lib/mini_readline/read_line/edit/cancel.rb
97
100
  - lib/mini_readline/read_line/edit/delete_left.rb
98
101
  - lib/mini_readline/read_line/edit/delete_right.rb
102
+ - lib/mini_readline/read_line/edit/edit_window.rb
103
+ - lib/mini_readline/read_line/edit/edit_window/sync_cursor.rb
104
+ - lib/mini_readline/read_line/edit/edit_window/sync_window.rb
99
105
  - lib/mini_readline/read_line/edit/enter.rb
100
106
  - lib/mini_readline/read_line/edit/go_end.rb
101
107
  - lib/mini_readline/read_line/edit/go_home.rb
@@ -107,9 +113,6 @@ files:
107
113
  - lib/mini_readline/read_line/edit/unmapped.rb
108
114
  - lib/mini_readline/read_line/edit/word_left.rb
109
115
  - lib/mini_readline/read_line/edit/word_right.rb
110
- - lib/mini_readline/read_line/edit_window.rb
111
- - lib/mini_readline/read_line/edit_window/sync_cursor.rb
112
- - lib/mini_readline/read_line/edit_window/sync_window.rb
113
116
  - lib/mini_readline/read_line/history.rb
114
117
  - lib/mini_readline/read_line/no_history.rb
115
118
  - lib/mini_readline/version.rb