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.
- checksums.yaml +4 -4
- data/README.md +9 -37
- data/lib/mini_readline.rb +14 -10
- data/lib/mini_readline/exceptions.rb +0 -3
- data/lib/mini_readline/maps.rb +126 -0
- data/lib/mini_readline/options.rb +3 -7
- data/lib/mini_readline/read_line.rb +17 -25
- data/lib/mini_readline/read_line/edit.rb +10 -11
- data/lib/mini_readline/read_line/edit/auto_complete.rb +7 -7
- data/lib/mini_readline/read_line/edit/auto_complete/array_source.rb +7 -7
- data/lib/mini_readline/read_line/edit/auto_complete/auto_file_source.rb +19 -19
- data/lib/mini_readline/read_line/edit/auto_complete/auto_manager.rb +5 -5
- data/lib/mini_readline/read_line/edit/auto_complete/file_folder_source.rb +6 -6
- data/lib/mini_readline/read_line/edit/auto_complete/quoted_file_folder_source.rb +7 -7
- data/lib/mini_readline/read_line/edit/cancel.rb +3 -3
- data/lib/mini_readline/read_line/edit/delete_all_left.rb +4 -4
- data/lib/mini_readline/read_line/edit/delete_all_right.rb +4 -4
- data/lib/mini_readline/read_line/edit/delete_left.rb +4 -4
- data/lib/mini_readline/read_line/edit/delete_right.rb +4 -4
- data/lib/mini_readline/read_line/edit/edit_window.rb +17 -19
- data/lib/mini_readline/read_line/edit/edit_window/sync_cursor.rb +4 -4
- data/lib/mini_readline/read_line/edit/edit_window/sync_window.rb +9 -9
- data/lib/mini_readline/read_line/edit/end_of_input.rb +4 -4
- data/lib/mini_readline/read_line/edit/enter.rb +3 -3
- data/lib/mini_readline/read_line/edit/go_end.rb +3 -3
- data/lib/mini_readline/read_line/edit/go_home.rb +3 -3
- data/lib/mini_readline/read_line/edit/go_left.rb +4 -4
- data/lib/mini_readline/read_line/edit/go_right.rb +4 -4
- data/lib/mini_readline/read_line/edit/insert_text.rb +3 -3
- data/lib/mini_readline/read_line/edit/next_history.rb +4 -4
- data/lib/mini_readline/read_line/edit/previous_history.rb +4 -4
- data/lib/mini_readline/read_line/edit/unmapped.rb +4 -4
- data/lib/mini_readline/read_line/edit/word_left.rb +4 -4
- data/lib/mini_readline/read_line/edit/word_right.rb +4 -4
- data/lib/mini_readline/read_line/history.rb +9 -9
- data/lib/mini_readline/read_line/no_history.rb +8 -8
- data/lib/mini_readline/read_line/prompt.rb +7 -7
- data/lib/mini_readline/version.rb +7 -1
- data/mini_readline.gemspec +5 -4
- data/rakefile.rb +8 -23
- data/sire.rb +1 -1
- data/tests/mini_readline_tests.rb +13 -14
- metadata +23 -34
- data/lib/mini_readline/raw_term.rb +0 -47
- data/lib/mini_readline/raw_term/ansi.rb +0 -70
- data/lib/mini_readline/raw_term/ansi/map.rb +0 -68
- data/lib/mini_readline/raw_term/ansi/set_posn.rb +0 -22
- data/lib/mini_readline/raw_term/ansi/window_width.rb +0 -17
- data/lib/mini_readline/raw_term/mapped_term.rb +0 -23
- data/lib/mini_readline/raw_term/mapped_term/mapper.rb +0 -53
- data/lib/mini_readline/raw_term/windows.rb +0 -100
- data/lib/mini_readline/raw_term/windows/map.rb +0 -63
- data/lib/mini_readline/raw_term/windows/set_posn.rb +0 -19
- data/lib/mini_readline/raw_term/windows/win_32_api.rb +0 -31
- data/lib/mini_readline/raw_term/windows/window_width.rb +0 -17
@@ -1,14 +1,14 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
# Keep the cursor in sync.
|
4
4
|
module MiniReadline
|
5
5
|
|
6
|
-
|
6
|
+
# Keep the cursor in sync.
|
7
7
|
class EditWindow
|
8
8
|
|
9
|
-
#Keep the cursor in sync!
|
9
|
+
# Keep the cursor in sync!
|
10
10
|
def sync_cursor(edit_posn)
|
11
|
-
|
11
|
+
MiniTerm.set_posn(column: edit_posn - left_margin + prompt.length)
|
12
12
|
end
|
13
13
|
|
14
14
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
# Keeping the screen in sync.
|
4
4
|
module MiniReadline
|
5
5
|
|
6
|
-
|
6
|
+
# Keeping the screen in sync.
|
7
7
|
class EditWindow
|
8
8
|
|
9
|
-
#Keep the edit window in sync!
|
9
|
+
# Keep the edit window in sync!
|
10
10
|
def sync_window(edit_buffer, edit_posn)
|
11
11
|
unless check_margins(edit_buffer.length, edit_posn)
|
12
12
|
window_buffer.clear
|
@@ -18,7 +18,7 @@ module MiniReadline
|
|
18
18
|
@window_buffer = image
|
19
19
|
end
|
20
20
|
|
21
|
-
#Verify/update the window margins. Returns true if they're fine.
|
21
|
+
# Verify/update the window margins. Returns true if they're fine.
|
22
22
|
def check_margins(length, edit_posn)
|
23
23
|
old_margins = [left_margin, right_margin]
|
24
24
|
|
@@ -33,7 +33,7 @@ module MiniReadline
|
|
33
33
|
old_margins == [left_margin, right_margin]
|
34
34
|
end
|
35
35
|
|
36
|
-
#Compute what should be on the screen.
|
36
|
+
# Compute what should be on the screen.
|
37
37
|
def build_screen_image(edit_buffer)
|
38
38
|
working_region = edit_buffer[left_margin..right_margin]
|
39
39
|
|
@@ -44,17 +44,17 @@ module MiniReadline
|
|
44
44
|
end.ljust(active_width)
|
45
45
|
end
|
46
46
|
|
47
|
-
#Bring the screen into agreement with the image.
|
47
|
+
# Bring the screen into agreement with the image.
|
48
48
|
def update_screen(image)
|
49
49
|
if @show_prompt
|
50
|
-
|
50
|
+
MiniTerm.print("\r#{prompt.text}\r")
|
51
51
|
@show_prompt = false
|
52
52
|
end
|
53
53
|
|
54
54
|
(0...active_width).each do |index|
|
55
55
|
if (image_char = image[index]) != window_buffer[index]
|
56
|
-
|
57
|
-
|
56
|
+
MiniTerm.set_posn(column: prompt.length + index)
|
57
|
+
MiniTerm.print(image_char)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
# Process :end_of_input
|
4
4
|
module MiniReadline
|
5
5
|
|
6
|
-
|
6
|
+
# Process :end_of_input
|
7
7
|
class Edit
|
8
8
|
|
9
|
-
#
|
9
|
+
# We are DONE!
|
10
10
|
def end_of_input(_keyboard_args)
|
11
11
|
if @options[:eoi_detect]
|
12
12
|
raise MiniReadlineEOI, "End of input detected."
|
13
13
|
else
|
14
|
-
|
14
|
+
MiniTerm.beep
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
# Process :enter
|
4
4
|
module MiniReadline
|
5
5
|
|
6
|
-
|
6
|
+
# Process :enter
|
7
7
|
class Edit
|
8
8
|
|
9
|
-
#The insert_text command.
|
9
|
+
# The insert_text command.
|
10
10
|
def enter(_keyboard_args)
|
11
11
|
@working = false
|
12
12
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
# Process :go_end
|
4
4
|
module MiniReadline
|
5
5
|
|
6
|
-
|
6
|
+
# Process :go_end
|
7
7
|
class Edit
|
8
8
|
|
9
|
-
#A lot to the right please!
|
9
|
+
# A lot to the right please!
|
10
10
|
def go_end(_keyboard_args)
|
11
11
|
@edit_posn = length
|
12
12
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
# Process :go_home
|
4
4
|
module MiniReadline
|
5
5
|
|
6
|
-
|
6
|
+
# Process :go_home
|
7
7
|
class Edit
|
8
8
|
|
9
|
-
#A lot to the left please!
|
9
|
+
# A lot to the left please!
|
10
10
|
def go_home(_keyboard_args)
|
11
11
|
@edit_posn = 0
|
12
12
|
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
# Process :go_left
|
4
4
|
module MiniReadline
|
5
5
|
|
6
|
-
|
6
|
+
# Process :go_left
|
7
7
|
class Edit
|
8
8
|
|
9
|
-
#A little to the left please!
|
9
|
+
# A little to the left please!
|
10
10
|
def go_left(_keyboard_args)
|
11
11
|
if @edit_posn > 0
|
12
12
|
@edit_posn -= 1
|
13
13
|
else
|
14
|
-
|
14
|
+
MiniTerm.beep
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
# Process :go_right
|
4
4
|
module MiniReadline
|
5
5
|
|
6
|
-
|
6
|
+
# Process :go_right
|
7
7
|
class Edit
|
8
8
|
|
9
|
-
#A little to the right please!
|
9
|
+
# A little to the right please!
|
10
10
|
def go_right(_keyboard_args)
|
11
11
|
if @edit_posn < edit_buffer.length
|
12
12
|
@edit_posn += 1
|
13
13
|
else
|
14
|
-
|
14
|
+
MiniTerm.beep
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
# Process :insert_text
|
4
4
|
module MiniReadline
|
5
5
|
|
6
|
-
|
6
|
+
# Process :insert_text
|
7
7
|
class Edit
|
8
8
|
|
9
|
-
#The insert_text command
|
9
|
+
# The insert_text command
|
10
10
|
def insert_text(keyboard_args)
|
11
11
|
@edit_buffer = @edit_buffer[0...@edit_posn] +
|
12
12
|
keyboard_args[1] +
|
@@ -1,18 +1,18 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
# Process :next_history
|
4
4
|
module MiniReadline
|
5
5
|
|
6
|
-
|
6
|
+
# Process :next_history
|
7
7
|
class Edit
|
8
8
|
|
9
|
-
#The insert_text command. We are DONE!
|
9
|
+
# The insert_text command. We are DONE!
|
10
10
|
def next_history(_keyboard_args)
|
11
11
|
if (temp = @history.get_next_history)
|
12
12
|
@edit_buffer = temp
|
13
13
|
@edit_posn = temp.length
|
14
14
|
else
|
15
|
-
|
15
|
+
MiniTerm.beep
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
# Process :previous_history
|
4
4
|
module MiniReadline
|
5
5
|
|
6
|
-
|
6
|
+
# Process :previous_history
|
7
7
|
class Edit
|
8
8
|
|
9
|
-
#The insert_text command. We are DONE!
|
9
|
+
# The insert_text command. We are DONE!
|
10
10
|
def previous_history(_keyboard_args)
|
11
11
|
if (temp = @history.get_previous_history)
|
12
12
|
@edit_buffer = temp
|
13
13
|
@edit_posn = temp.length
|
14
14
|
else
|
15
|
-
|
15
|
+
MiniTerm.beep
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
# Process :unmapped
|
4
4
|
module MiniReadline
|
5
5
|
|
6
|
-
|
6
|
+
# Process :unmapped
|
7
7
|
class Edit
|
8
8
|
|
9
|
-
#An unmapped key was pressed. Beep!
|
9
|
+
# An unmapped key was pressed. Beep!
|
10
10
|
def unmapped(_keyboard_args)
|
11
|
-
|
11
|
+
MiniTerm.beep
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
# Process :word_left
|
4
4
|
module MiniReadline
|
5
5
|
|
6
|
-
|
6
|
+
# Process :word_left
|
7
7
|
class Edit
|
8
8
|
|
9
|
-
#A little more to the left please!
|
9
|
+
# A little more to the left please!
|
10
10
|
def word_left(_keyboard_args)
|
11
11
|
if @edit_posn > 0
|
12
12
|
left = @edit_buffer[0...@edit_posn]
|
13
13
|
@edit_posn = (posn = left.rindex(/\s\S/)) ? posn+1 : 0
|
14
14
|
else
|
15
|
-
|
15
|
+
MiniTerm.beep
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
# Process :word_right
|
4
4
|
module MiniReadline
|
5
5
|
|
6
|
-
|
6
|
+
# Process :word_right
|
7
7
|
class Edit
|
8
8
|
|
9
|
-
#A little more to the right please!
|
9
|
+
# A little more to the right please!
|
10
10
|
def word_right(_keyboard_args)
|
11
11
|
if @edit_posn < length
|
12
12
|
right = @edit_buffer[(@edit_posn+1)..-1]
|
13
13
|
@edit_posn = (posn = right.index(/\s\S/)) ? @edit_posn+posn+2 : length
|
14
14
|
else
|
15
|
-
|
15
|
+
MiniTerm.beep
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -1,29 +1,29 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
# Edit history support
|
4
4
|
module MiniReadline
|
5
5
|
|
6
|
-
|
6
|
+
# Support for the edit history.
|
7
7
|
class History
|
8
8
|
|
9
|
-
#Setup the history array of the mini line editor.
|
9
|
+
# Setup the history array of the mini line editor.
|
10
10
|
def initialize(buffer)
|
11
11
|
@_buffer = buffer
|
12
12
|
goto_end_of_history
|
13
13
|
end
|
14
14
|
|
15
|
-
#Get the history object ready for the next read line operation.
|
15
|
+
# Get the history object ready for the next read line operation.
|
16
16
|
def initialize_parms(options)
|
17
17
|
@options = options
|
18
18
|
goto_end_of_history
|
19
19
|
end
|
20
20
|
|
21
|
-
#Go to the end of the history array.
|
21
|
+
# Go to the end of the history array.
|
22
22
|
def goto_end_of_history
|
23
23
|
@history_cursor = history.length
|
24
24
|
end
|
25
25
|
|
26
|
-
#Get the previous history string.
|
26
|
+
# Get the previous history string.
|
27
27
|
def get_previous_history
|
28
28
|
if @history_cursor > 0
|
29
29
|
@history_cursor -= 1
|
@@ -33,7 +33,7 @@ module MiniReadline
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
#Get the next history string
|
36
|
+
# Get the next history string
|
37
37
|
def get_next_history
|
38
38
|
if @history_cursor < history.length
|
39
39
|
@history_cursor += 1
|
@@ -43,7 +43,7 @@ module MiniReadline
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
#Append a string to the history buffer if enabled.
|
46
|
+
# Append a string to the history buffer if enabled.
|
47
47
|
def append_history(str)
|
48
48
|
return if @options[:no_blanks] && str.strip.empty?
|
49
49
|
history.delete(str) if @options[:no_dups]
|
@@ -51,7 +51,7 @@ module MiniReadline
|
|
51
51
|
history << str
|
52
52
|
end
|
53
53
|
|
54
|
-
#Get the history buffer associated with this instance.
|
54
|
+
# Get the history buffer associated with this instance.
|
55
55
|
def history
|
56
56
|
@_buffer
|
57
57
|
end
|
@@ -1,34 +1,34 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
# Support for the edit without history.
|
4
4
|
module MiniReadline
|
5
5
|
|
6
|
-
|
6
|
+
# Support for the edit without history.
|
7
7
|
class NoHistory
|
8
8
|
|
9
|
-
#Get the history object ready for the next read line operation. NOP
|
9
|
+
# Get the history object ready for the next read line operation. NOP
|
10
10
|
def initialize_parms(_options)
|
11
11
|
end
|
12
12
|
|
13
|
-
#Go to the end of the history array. NOP
|
13
|
+
# Go to the end of the history array. NOP
|
14
14
|
def goto_end_of_history
|
15
15
|
end
|
16
16
|
|
17
|
-
#Get the previous history string. NOP
|
17
|
+
# Get the previous history string. NOP
|
18
18
|
def get_previous_history
|
19
19
|
false
|
20
20
|
end
|
21
21
|
|
22
|
-
#Get the next history string. NOP
|
22
|
+
# Get the next history string. NOP
|
23
23
|
def get_next_history
|
24
24
|
false
|
25
25
|
end
|
26
26
|
|
27
|
-
#Append a string to the history buffer if enabled. NOP
|
27
|
+
# Append a string to the history buffer if enabled. NOP
|
28
28
|
def append_history(_str)
|
29
29
|
end
|
30
30
|
|
31
|
-
#Get the history buffer associated with this instance. Empty
|
31
|
+
# Get the history buffer associated with this instance. Empty
|
32
32
|
def history
|
33
33
|
[]
|
34
34
|
end
|
@@ -1,25 +1,25 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
#Support for the specialized prompt string class.
|
3
|
+
# Support for the specialized prompt string class.
|
4
4
|
module MiniReadline
|
5
5
|
|
6
|
-
#A class used to hold prompt strings that may contain ANSI terminal
|
7
|
-
#control embellishments.
|
6
|
+
# A class used to hold prompt strings that may contain ANSI terminal
|
7
|
+
# control embellishments.
|
8
8
|
class Prompt
|
9
9
|
|
10
|
-
#Get the text.
|
10
|
+
# Get the text.
|
11
11
|
attr_reader :text
|
12
12
|
|
13
|
-
#Get the length without ANSI sequences.
|
13
|
+
# Get the length without ANSI sequences.
|
14
14
|
attr_reader :length
|
15
15
|
|
16
|
-
#Create a special prompt text.
|
16
|
+
# Create a special prompt text.
|
17
17
|
def initialize(text)
|
18
18
|
@text = text
|
19
19
|
@length = text.gsub(/\x1B\[(\d|;)*[@-~]/, "").length
|
20
20
|
end
|
21
21
|
|
22
|
-
#Inspect the prompt
|
22
|
+
# Inspect the prompt
|
23
23
|
def inspect
|
24
24
|
"<Prompt: #{@text.inspect}>"
|
25
25
|
end
|