mini_readline 0.6.8 → 0.6.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mini_readline.rb +1 -4
- data/lib/mini_readline/raw_term.rb +23 -19
- data/lib/mini_readline/raw_term/{other.rb → ansi.rb} +11 -7
- data/lib/mini_readline/raw_term/{other → ansi}/map.rb +0 -0
- data/lib/mini_readline/raw_term/{other → ansi}/set_posn.rb +2 -2
- data/lib/mini_readline/raw_term/mapped_term.rb +23 -0
- data/lib/mini_readline/raw_term/{mapper.rb → mapped_term/mapper.rb} +9 -0
- data/lib/mini_readline/raw_term/windows.rb +53 -22
- data/lib/mini_readline/raw_term/windows/set_posn.rb +2 -2
- data/lib/mini_readline/read_line/prompt.rb +1 -0
- data/lib/mini_readline/version.rb +1 -1
- data/rakefile.rb +10 -1
- data/tests/mini_readline_tests.rb +3 -3
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 020c03986052ff49549a37360b56b803d5b36cc0
|
4
|
+
data.tar.gz: 0e789a40a83f7cbc4ed39c72e2dd3fa05be64160
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09caa12ad44af13e3707315c87c0d822518d801bdb6eb8b3bf1aea00ca4135ce129d89b068c038176a4c7574b93d45a93af2c49e7aa934bcc92321917a84b563
|
7
|
+
data.tar.gz: 0aec83925d482a7a3861105f650e13cd3a5b86c58957288de9a753879d9576c5c838de49626a4115c64c6c0d45f53045005380dbc762b077f97a31785f3d14f9
|
data/lib/mini_readline.rb
CHANGED
@@ -7,10 +7,7 @@ require_relative "mini_readline/options"
|
|
7
7
|
require_relative "mini_readline/raw_term"
|
8
8
|
require_relative "mini_readline/read_line"
|
9
9
|
|
10
|
-
#The \MiniReadline module.
|
11
|
-
#on the notion/hope that the code shouldn't smell like an abandoned fish
|
12
|
-
#processing plant. To this end, it drops the pretext of being compatible
|
13
|
-
#with the GNU readline library and instead embraces OOD principles. I hope.
|
10
|
+
#The \MiniReadline module.
|
14
11
|
#* mini_readline.rb - The root file that gathers up all the system's parts.
|
15
12
|
module MiniReadline
|
16
13
|
|
@@ -1,33 +1,37 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
require 'rbconfig'
|
4
4
|
|
5
5
|
#* raw_term.rb - Platform determination for raw terminal access.
|
6
6
|
module MiniReadline
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
8
|
+
host_os = RbConfig::CONFIG['host_os']
|
9
|
+
|
10
|
+
#What operating platform is in effect?
|
11
|
+
TERM_PLATFORM =
|
12
|
+
case host_os
|
13
|
+
when /mswin|msys|mingw|bccwin|wince|emc/
|
14
|
+
:windows
|
15
|
+
when /cygwin/
|
16
|
+
:cygwin
|
17
|
+
when /darwin|mac os/
|
18
|
+
:macosx
|
19
|
+
when /linux/
|
20
|
+
:linux
|
21
|
+
when /solaris|bsd/
|
22
|
+
:unix
|
23
|
+
else
|
24
|
+
raise "Unknown os: #{host_os.inspect}"
|
18
25
|
end
|
19
26
|
|
20
|
-
|
21
|
-
|
22
|
-
MAP.get_mapped_keystroke {get_raw_char}
|
23
|
-
end
|
24
|
-
end
|
27
|
+
#Is Java present in the environment?
|
28
|
+
TERM_JAVA = RUBY_PLATFORM =~ /java/
|
25
29
|
|
26
30
|
#Select the type of platform in use.
|
27
|
-
if
|
28
|
-
require_relative 'raw_term/other'
|
29
|
-
else
|
31
|
+
if TERM_PLATFORM == :windows
|
30
32
|
require_relative 'raw_term/windows'
|
33
|
+
else
|
34
|
+
require_relative 'raw_term/ansi'
|
31
35
|
end
|
32
36
|
|
33
37
|
#Get an instance of a raw terminal controller object.
|
@@ -1,14 +1,16 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
require 'io/console'
|
4
|
-
|
5
|
-
require_relative '
|
4
|
+
|
5
|
+
require_relative 'mapped_term'
|
6
|
+
require_relative 'ansi/map'
|
7
|
+
require_relative 'ansi/set_posn'
|
6
8
|
|
7
9
|
#* raw_term/other.rb - Support for raw terminal access in non-windows systems.
|
8
10
|
module MiniReadline
|
9
11
|
|
10
12
|
#The detected platform is not windows.
|
11
|
-
PLATFORM = :
|
13
|
+
PLATFORM = :ansi
|
12
14
|
|
13
15
|
#The class used to manipulate console i/o on a low level.
|
14
16
|
class RawTerm
|
@@ -22,7 +24,7 @@ module MiniReadline
|
|
22
24
|
#Output a string
|
23
25
|
def put_string(str)
|
24
26
|
scan_string(str)
|
25
|
-
print(str)
|
27
|
+
STDOUT.print(str)
|
26
28
|
end
|
27
29
|
|
28
30
|
#Home the cursor and start at a known state.
|
@@ -32,17 +34,19 @@ module MiniReadline
|
|
32
34
|
end
|
33
35
|
|
34
36
|
#Conclude the terminal state.
|
37
|
+
#<br>Endemic Code Smells
|
38
|
+
#* :reek:UtilityFunction
|
35
39
|
def conclude
|
36
40
|
STDIN.cooked!
|
37
|
-
print("\n")
|
41
|
+
STDOUT.print("\n")
|
38
42
|
end
|
39
43
|
|
40
44
|
#Sound a beep
|
41
45
|
#<br>Endemic Code Smells
|
42
46
|
#* :reek:UtilityFunction
|
43
47
|
def beep
|
44
|
-
|
45
|
-
|
48
|
+
STDERR.write(BELL)
|
49
|
+
STDERR.flush
|
46
50
|
end
|
47
51
|
|
48
52
|
#Get a uncooked character keystroke.
|
File without changes
|
@@ -11,9 +11,9 @@ module MiniReadline
|
|
11
11
|
if new_posn == 0
|
12
12
|
put_string(CARRIAGE_RETURN)
|
13
13
|
elsif new_posn > @cursor_posn
|
14
|
-
print("\e[#{new_posn - @cursor_posn}C")
|
14
|
+
STDOUT.print("\e[#{new_posn - @cursor_posn}C")
|
15
15
|
elsif new_posn < @cursor_posn
|
16
|
-
print("\e[#{@cursor_posn - new_posn}D")
|
16
|
+
STDOUT.print("\e[#{@cursor_posn - new_posn}D")
|
17
17
|
end
|
18
18
|
|
19
19
|
@cursor_posn = new_posn
|
@@ -0,0 +1,23 @@
|
|
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
|
@@ -18,6 +18,15 @@ module MiniReadline
|
|
18
18
|
@map[index] = value
|
19
19
|
end
|
20
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
|
+
|
21
30
|
#Handle the preamble characters in the command sequence.
|
22
31
|
def process_non_terminals(index)
|
23
32
|
seq = ""
|
@@ -1,6 +1,12 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
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'
|
4
10
|
require_relative 'windows/map'
|
5
11
|
require_relative 'windows/set_posn'
|
6
12
|
|
@@ -11,8 +17,6 @@ module MiniReadline
|
|
11
17
|
PLATFORM = :windows
|
12
18
|
|
13
19
|
#The class used to manipulate console i/o on a low level.
|
14
|
-
#<br>Endemic Code Smells
|
15
|
-
# :reek:TooManyInstanceVariables
|
16
20
|
class RawTerm
|
17
21
|
|
18
22
|
#The sleep interval waiting for a key to be pressed.
|
@@ -25,45 +29,72 @@ module MiniReadline
|
|
25
29
|
STD_OUTPUT_HANDLE = -11
|
26
30
|
|
27
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.
|
28
39
|
def initialize
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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 }
|
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
|
+
|
37
71
|
end
|
38
72
|
|
39
73
|
#Output a string
|
74
|
+
#<br>Endemic Code Smells
|
75
|
+
#* :reek:UtilityFunction
|
40
76
|
def put_string(str)
|
41
|
-
print(str)
|
77
|
+
STDOUT.print(str)
|
42
78
|
end
|
43
79
|
|
44
80
|
#Home the cursor and start at a known state.
|
45
81
|
def initialize_parms
|
46
|
-
@_out_handle =
|
47
|
-
put_string
|
82
|
+
@_out_handle = get_handle(STD_OUTPUT_HANDLE)
|
83
|
+
put_string(CARRIAGE_RETURN)
|
48
84
|
end
|
49
85
|
|
50
86
|
#Conclude the terminal state.
|
51
87
|
def conclude
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
#Sound a beep
|
56
|
-
def beep
|
57
|
-
@_beep.call(0)
|
88
|
+
put_string("\n")
|
58
89
|
end
|
59
90
|
|
60
91
|
#Get a uncooked character keystroke.
|
61
92
|
def get_raw_char
|
62
|
-
while (
|
93
|
+
while (kbhit == 0)
|
63
94
|
sleep(WAIT_SLEEP)
|
64
95
|
end
|
65
96
|
|
66
|
-
|
97
|
+
getch
|
67
98
|
end
|
68
99
|
end
|
69
100
|
end
|
@@ -9,10 +9,10 @@ module MiniReadline
|
|
9
9
|
#Move the cursor using windows voodoo API.
|
10
10
|
def set_posn(new_posn)
|
11
11
|
raw_buffer = 0.chr * 24
|
12
|
-
|
12
|
+
get_screen_info(raw_buffer)
|
13
13
|
y_posn = (raw_buffer[6,2].unpack('S'))[0]
|
14
14
|
|
15
|
-
|
15
|
+
set_cursor_posn(y_posn * 65536 + new_posn)
|
16
16
|
end
|
17
17
|
|
18
18
|
end
|
data/rakefile.rb
CHANGED
@@ -10,7 +10,7 @@ RDoc::Task.new do |rdoc|
|
|
10
10
|
rdoc.rdoc_dir = "rdoc"
|
11
11
|
|
12
12
|
#List out all the files to be documented.
|
13
|
-
rdoc.rdoc_files.include("lib/**/*.rb", "license.txt"
|
13
|
+
rdoc.rdoc_files.include("lib/**/*.rb", "license.txt")
|
14
14
|
|
15
15
|
#Make all access levels visible.
|
16
16
|
rdoc.options << '--visibility' << 'private'
|
@@ -43,3 +43,12 @@ task :vers do |t|
|
|
43
43
|
puts
|
44
44
|
puts "mini_readline version = #{MiniReadline::VERSION}"
|
45
45
|
end
|
46
|
+
|
47
|
+
desc "What is the module load out?"
|
48
|
+
task :vls do |t|
|
49
|
+
require 'vls'
|
50
|
+
|
51
|
+
puts
|
52
|
+
VersionLS.print_vls(/./)
|
53
|
+
end
|
54
|
+
|
@@ -32,10 +32,10 @@ class MiniReadlineTester < Minitest::Test
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_platform_detection
|
35
|
-
if (
|
36
|
-
assert_equal(:other, MiniReadline::PLATFORM)
|
37
|
-
else
|
35
|
+
if (MiniReadline::TERM_PLATFORM == :windows)
|
38
36
|
assert_equal(:windows, MiniReadline::PLATFORM)
|
37
|
+
else
|
38
|
+
assert_equal(:other, MiniReadline::PLATFORM)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
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.6.
|
4
|
+
version: 0.6.9
|
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-10-
|
11
|
+
date: 2016-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -88,10 +88,11 @@ files:
|
|
88
88
|
- lib/mini_readline/exceptions.rb
|
89
89
|
- lib/mini_readline/options.rb
|
90
90
|
- lib/mini_readline/raw_term.rb
|
91
|
-
- lib/mini_readline/raw_term/
|
92
|
-
- lib/mini_readline/raw_term/
|
93
|
-
- lib/mini_readline/raw_term/
|
94
|
-
- lib/mini_readline/raw_term/
|
91
|
+
- lib/mini_readline/raw_term/ansi.rb
|
92
|
+
- lib/mini_readline/raw_term/ansi/map.rb
|
93
|
+
- lib/mini_readline/raw_term/ansi/set_posn.rb
|
94
|
+
- lib/mini_readline/raw_term/mapped_term.rb
|
95
|
+
- lib/mini_readline/raw_term/mapped_term/mapper.rb
|
95
96
|
- lib/mini_readline/raw_term/windows.rb
|
96
97
|
- lib/mini_readline/raw_term/windows/map.rb
|
97
98
|
- lib/mini_readline/raw_term/windows/set_posn.rb
|