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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ae245afb8c0c06f6ceb938eca139ce122ac986d
4
- data.tar.gz: 9aa4b9661e8d2b2e9d645a1ec3158347d351a81b
3
+ metadata.gz: 020c03986052ff49549a37360b56b803d5b36cc0
4
+ data.tar.gz: 0e789a40a83f7cbc4ed39c72e2dd3fa05be64160
5
5
  SHA512:
6
- metadata.gz: 47de3ca150396c1163f04da730f3f2c403c4f3ff72dee8a1f4069f15dd0b40ca1ca49d5f2fc51d6a8e6b6f504087423d00c5cfac2ee217ca50386739958bb300
7
- data.tar.gz: f380c80b7bc5608d962e7aaa1d2af4a53687469c72b5b28a5179dd29a5d89b0a1d9daadb99c53e82cf05c580f08ac55c16752f558861235eba55bddd683005ff
6
+ metadata.gz: 09caa12ad44af13e3707315c87c0d822518d801bdb6eb8b3bf1aea00ca4135ce129d89b068c038176a4c7574b93d45a93af2c49e7aa934bcc92321917a84b563
7
+ data.tar.gz: 0aec83925d482a7a3861105f650e13cd3a5b86c58957288de9a753879d9576c5c838de49626a4115c64c6c0d45f53045005380dbc762b077f97a31785f3d14f9
@@ -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. A replacement for the rb_readline gem predicated
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
- require_relative 'raw_term/mapper'
3
+ require 'rbconfig'
4
4
 
5
5
  #* raw_term.rb - Platform determination for raw terminal access.
6
6
  module MiniReadline
7
7
 
8
- #The class used to manipulate console i/o on a low level.
9
- class RawTerm
10
-
11
- #Create a mapper.
12
- MAP = Mapper.new
13
-
14
- #Map the printable characters.
15
- (32..126).each do |code|
16
- char = code.chr
17
- MAP[char] = [:insert_text, char]
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
- #Get a mapped sequence.
21
- def get_mapped_keystroke
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 (RUBY_PLATFORM =~ /\bcygwin\b/i) || (RUBY_PLATFORM !~ /mswin|mingw/)
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
- require_relative 'other/map'
5
- require_relative 'other/set_posn'
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 = :other
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
- $stderr.write(BELL)
45
- $stderr.flush
48
+ STDERR.write(BELL)
49
+ STDERR.flush
46
50
  end
47
51
 
48
52
  #Get a uncooked character keystroke.
@@ -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
- require_relative 'windows/win_32_api'
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
- @_getch = Win32API.new("msvcrt", "_getch", [], 'I')
30
- @_kbhit = Win32API.new("msvcrt", "_kbhit", [], 'I')
31
- @_beep = Win32API.new("user32", "MessageBeep", ['L'])
32
- @_set_cursor_posn = Win32API.new("kernel32", "SetConsoleCursorPosition",
33
- ['L','L'], 'L')
34
- @_get_screen_info = Win32API.new("kernel32", "GetConsoleScreenBufferInfo",
35
- ['L','P'], 'L')
36
- @_get_handle = Win32API.new("kernel32", "GetStdHandle", ['L'], 'L')
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 = @_get_handle.call(STD_OUTPUT_HANDLE)
47
- put_string CARRIAGE_RETURN
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
- print("\n")
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 (@_kbhit.call == 0)
93
+ while (kbhit == 0)
63
94
  sleep(WAIT_SLEEP)
64
95
  end
65
96
 
66
- @_getch.call.chr
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
- @_get_screen_info.call(@_out_handle, raw_buffer)
12
+ get_screen_info(raw_buffer)
13
13
  y_posn = (raw_buffer[6,2].unpack('S'))[0]
14
14
 
15
- @_set_cursor_posn.call(@_out_handle, y_posn * 65536 + new_posn)
15
+ set_cursor_posn(y_posn * 65536 + new_posn)
16
16
  end
17
17
 
18
18
  end
@@ -13,6 +13,7 @@ module MiniReadline
13
13
  #Get the length without ANSI sequences.
14
14
  attr_reader :length
15
15
 
16
+ #Create a special prompt text.
16
17
  def initialize(text)
17
18
  @text = text
18
19
  @length = text.gsub(/\x1B\[(\d|;)*[@-~]/, "").length
@@ -1,4 +1,4 @@
1
1
  module MiniReadline
2
2
  #The current version of the mini_readline gem.
3
- VERSION = "0.6.8"
3
+ VERSION = "0.6.9"
4
4
  end
@@ -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", "README.md")
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 (RUBY_PLATFORM =~ /\bcygwin\b/i) || (RUBY_PLATFORM !~ /mswin|mingw/)
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.8
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-13 00:00:00.000000000 Z
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/mapper.rb
92
- - lib/mini_readline/raw_term/other.rb
93
- - lib/mini_readline/raw_term/other/map.rb
94
- - lib/mini_readline/raw_term/other/set_posn.rb
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