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
@@ -1,17 +0,0 @@
1
- # coding: utf-8
2
-
3
- #* ansi/window_width.rb - Determine the available screen width.
4
- module MiniReadline
5
-
6
- #* ansi/window_width.rb - Determine the available screen width.
7
- class RawTerm
8
-
9
- #Determine the available screen width.
10
- #<br>Endemic Code Smells
11
- #* :reek:UtilityFunction
12
- def window_width
13
- IO.console.winsize[1]
14
- end
15
-
16
- end
17
- end
@@ -1,23 +0,0 @@
1
- # coding: utf-8
2
-
3
- require_relative 'mapped_term/mapper'
4
-
5
- #* raw_term/mapped_term.rb - Base class for a terminal with key mapping.
6
- module MiniReadline
7
-
8
- #The class used for terminal i/o that is mapped to command sequences.
9
- class RawTerm
10
-
11
- #Create a mapper.
12
- MAP = Mapper.new
13
-
14
- #Set up the printable characters.
15
- MAP.map_ascii(:insert_text)
16
-
17
- #Get a mapped sequence.
18
- def get_mapped_keystroke
19
- MAP.get_mapped_keystroke {get_raw_char}
20
- end
21
- end
22
-
23
- end
@@ -1,53 +0,0 @@
1
- # coding: utf-8
2
-
3
- #* raw_term/mapper.rb - Support for keystroke mapping.
4
- module MiniReadline
5
-
6
- #* raw_term/mapper.rb - Support for keystroke mapping.
7
- class Mapper
8
-
9
- #Set up the keystroke mapper.
10
- def initialize
11
- @map = Hash.new {|_hash, key| [:unmapped, key]}
12
- end
13
-
14
- #Add a map entry
15
- def []=(index, value)
16
- process_non_terminals(index)
17
- fail MiniReadlineKME, "Duplicate entry #{index.inspect}" if @map.has_key?(index)
18
- @map[index] = value
19
- end
20
-
21
- #Map the printable ascii key codes to a command.
22
- def map_ascii(command)
23
- #Map the printable characters.
24
- (32..126).each do |code|
25
- value = [command, char = code.chr]
26
- self[char] = value
27
- end
28
- end
29
-
30
- #Handle the preamble characters in the command sequence.
31
- def process_non_terminals(index)
32
- seq = ""
33
-
34
- index.chop.chars.each do |char|
35
- seq << char
36
- fail MiniReadlineKME, "Ambiguous entry #{index.inspect}" if @map.has_key?(seq) && @map[seq]
37
- @map[seq] = false
38
- end
39
- end
40
-
41
- #Get a mapped input sequence.
42
- def get_mapped_keystroke
43
- key_seq, key_cmd = "", nil
44
-
45
- begin
46
- key_seq << yield
47
- key_cmd = @map[key_seq]
48
- end until key_cmd
49
-
50
- key_cmd
51
- end
52
- end
53
- end
@@ -1,100 +0,0 @@
1
- # coding: utf-8
2
-
3
- if MiniReadline::TERM_JAVA
4
- require 'win32api'
5
- else
6
- require_relative 'windows/win_32_api'
7
- end
8
-
9
- require_relative 'mapped_term'
10
- require_relative 'windows/map'
11
- require_relative 'windows/set_posn'
12
- require_relative 'windows/window_width'
13
-
14
- #* raw_term/windows.rb - Support for raw terminal access in windows systems.
15
- module MiniReadline
16
-
17
- #The detected platform is windows.
18
- PLATFORM = :windows
19
-
20
- #The class used to manipulate console i/o on a low level.
21
- class RawTerm
22
-
23
- #The sleep interval waiting for a key to be pressed.
24
- WAIT_SLEEP = 0.02
25
-
26
- CARRIAGE_RETURN = "\x0D"
27
-
28
- #The magic number for standard out.
29
- STD_OUTPUT_HANDLE = -11
30
-
31
- #Set up the Windows Raw Terminal.
32
- #<br>Singleton Methods Added:
33
- #* getch - Low-level get char.
34
- #* kbhit - Low-level keyboard hit test.
35
- #* beep - Low-level beep.
36
- #* set_cursor_posn - Set the cursor position given coordinates (y*65536+x).
37
- #* get_screen_info - Get info about the console.
38
- #* get_handle - Get the internal handle associated with a file index.
39
- def initialize
40
- getch_proc = Win32API.new("msvcrt", "_getch", [], 'I')
41
- define_singleton_method(:getch) { getch_proc.call.chr }
42
-
43
- kbhit_proc = Win32API.new("msvcrt", "_kbhit", [], 'I')
44
- define_singleton_method(:kbhit) { kbhit_proc.call }
45
-
46
- beep_proc = Win32API.new("user32", "MessageBeep", ['L'], '0')
47
- define_singleton_method(:beep) { beep_proc.call(0) }
48
-
49
- set_cursor_posn_proc = Win32API.new("kernel32",
50
- "SetConsoleCursorPosition",
51
- ['L','L'], 'L')
52
-
53
- define_singleton_method(:set_cursor_posn) do |position|
54
- set_cursor_posn_proc.call(@_out_handle, position)
55
- end
56
-
57
- get_screen_info_proc = Win32API.new("kernel32",
58
- "GetConsoleScreenBufferInfo",
59
- ['L','P'], 'L')
60
-
61
- define_singleton_method(:get_screen_info) do |buffer|
62
- get_screen_info_proc.call(@_out_handle, buffer)
63
- end
64
-
65
- get_handle_proc = Win32API.new("kernel32", "GetStdHandle", ['L'], 'L')
66
-
67
- define_singleton_method(:get_handle) do |handle_index|
68
- get_handle_proc.call(handle_index)
69
- end
70
-
71
- end
72
-
73
- #Output a string
74
- #<br>Endemic Code Smells
75
- #* :reek:UtilityFunction
76
- def put_string(str)
77
- STDOUT.print(str)
78
- end
79
-
80
- #Home the cursor and start at a known state.
81
- def initialize_parms
82
- @_out_handle = get_handle(STD_OUTPUT_HANDLE)
83
- put_string(CARRIAGE_RETURN)
84
- end
85
-
86
- #Conclude the terminal state.
87
- def conclude
88
- put_string("\n")
89
- end
90
-
91
- #Get a uncooked character keystroke.
92
- def get_raw_char
93
- while (kbhit == 0)
94
- sleep(WAIT_SLEEP)
95
- end
96
-
97
- getch
98
- end
99
- end
100
- end
@@ -1,63 +0,0 @@
1
- # coding: utf-8
2
-
3
- #* windows/map.rb - Character mapping for windows systems.
4
- module MiniReadline
5
-
6
- #* windows/map.rb - Character mapping for windows systems.
7
- class RawTerm
8
-
9
- pfx = 0xE0.chr
10
-
11
- #Map the non-printing characters.
12
-
13
- #Left Arrows
14
- MAP["\x00K"] = [:go_left]
15
- MAP[pfx+"K"] = [:go_left]
16
-
17
- MAP["\x00s"] = [:word_left]
18
- MAP[pfx+"s"] = [:word_left]
19
-
20
- #Right Arrows
21
- MAP["\x00M"] = [:go_right]
22
- MAP[pfx+"M"] = [:go_right]
23
-
24
- MAP["\x00t"] = [:word_right]
25
- MAP[pfx+"t"] = [:word_right]
26
-
27
- #Up Arrows
28
- MAP["\x00H"] = [:previous_history]
29
- MAP[pfx+"H"] = [:previous_history]
30
-
31
- #Down Arrows
32
- MAP["\x00P"] = [:next_history]
33
- MAP[pfx+"P"] = [:next_history]
34
-
35
- #The Home keys
36
- MAP["\x00G"] = [:go_home]
37
- MAP[pfx+"G"] = [:go_home]
38
-
39
- #The End keys
40
- MAP["\x00O"] = [:go_end]
41
- MAP[pfx+"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["\x00S"] = [:delete_right]
49
- MAP[pfx+"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["\x1B"] = [:cancel]
59
-
60
- #End of Input
61
- MAP["\x1A"] = [:end_of_input]
62
- end
63
- end
@@ -1,19 +0,0 @@
1
- # coding: utf-8
2
-
3
- #* windows/set_posn.rb - Set the column of the cursor.
4
- module MiniReadline
5
-
6
- #* windows/set_posn.rb - Set the column of the cursor.
7
- class RawTerm
8
-
9
- #Move the cursor using windows voodoo API.
10
- def set_posn(new_posn)
11
- raw_buffer = 0.chr * 24
12
- get_screen_info(raw_buffer)
13
- y_posn = (raw_buffer[6,2].unpack('S'))[0]
14
-
15
- set_cursor_posn(y_posn * 65536 + new_posn)
16
- end
17
-
18
- end
19
- end
@@ -1,31 +0,0 @@
1
- # coding: utf-8
2
-
3
- #* windows/win_32_api.rb - Support for selected low level Win32 API entry points.
4
- module MiniReadline
5
-
6
- require 'fiddle'
7
-
8
- #The classic \Win32API gem is deprecated, so we emulate it with fiddle.
9
- class Win32API
10
-
11
- DLL = {}
12
- TYPEMAP = {"0" => Fiddle::TYPE_VOID, "S" => Fiddle::TYPE_VOIDP, "I" => Fiddle::TYPE_LONG}
13
- CALL_TYPE_TO_ABI = {:stdcall => 1, :cdecl => 1, nil => 1} #Taken from Fiddle::Importer
14
-
15
- def initialize(dllname, func, import, export = "0", calltype = :stdcall)
16
- @proto = import.join.tr("VPpNnLlIi", "0SSI").chomp('0').split('')
17
- handle = DLL[dllname] ||= Fiddle.dlopen(dllname)
18
- @func = Fiddle::Function.new(handle[func], TYPEMAP.values_at(*@proto), CALL_TYPE_TO_ABI[calltype])
19
- end
20
-
21
- def call(*args)
22
- args.each_with_index do |x, i|
23
- args[i], = [x == 0 ? nil : x].pack("p").unpack("l!*") if @proto[i] == "S" && !x.is_a?(Fiddle::Pointer)
24
- args[i], = [x].pack("I").unpack("i") if @proto[i] == "I"
25
- end
26
-
27
- @func.call(*args).to_i || 0
28
- end
29
-
30
- end
31
- end
@@ -1,17 +0,0 @@
1
- # coding: utf-8
2
-
3
- #* windows/window_width.rb - Determine the available screen width.
4
- module MiniReadline
5
-
6
- #* windows/window_width.rb - Determine the available screen width.
7
- class RawTerm
8
-
9
- #Determine the available screen width.
10
- def window_width
11
- raw_buffer = 0.chr * 24
12
- get_screen_info(raw_buffer)
13
- (raw_buffer[0,2].unpack('S'))[0]
14
- end
15
-
16
- end
17
- end