reline 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ module Reline
2
+ VERSION = '0.0.0'
3
+ end
@@ -0,0 +1,132 @@
1
+ module Reline
2
+ VK_LMENU = 0xA4
3
+ STD_OUTPUT_HANDLE = -11
4
+ @@getwch = Win32API.new('msvcrt', '_getwch', [], 'I')
5
+ @@kbhit = Win32API.new('msvcrt', '_kbhit', [], 'I')
6
+ @@GetKeyState = Win32API.new('user32', 'GetKeyState', ['L'], 'L')
7
+ @@GetConsoleScreenBufferInfo = Win32API.new('kernel32', 'GetConsoleScreenBufferInfo', ['L', 'P'], 'L')
8
+ @@SetConsoleCursorPosition = Win32API.new('kernel32', 'SetConsoleCursorPosition', ['L', 'L'], 'L')
9
+ @@GetStdHandle = Win32API.new('kernel32', 'GetStdHandle', ['L'], 'L')
10
+ @@FillConsoleOutputCharacter = Win32API.new('kernel32', 'FillConsoleOutputCharacter', ['L', 'L', 'L', 'L', 'P'], 'L')
11
+ @@ScrollConsoleScreenBuffer = Win32API.new('kernel32', 'ScrollConsoleScreenBuffer', ['L', 'P', 'P', 'L', 'P'], 'L')
12
+ @@hConsoleHandle = @@GetStdHandle.call(STD_OUTPUT_HANDLE)
13
+ @@buf = []
14
+
15
+ def getwch
16
+ while @@kbhit.call == 0
17
+ sleep(0.001)
18
+ end
19
+ result = []
20
+ until @@kbhit.call == 0
21
+ ret = @@getwch.call
22
+ begin
23
+ result.concat(ret.chr(Encoding::UTF_8).encode(Encoding.default_external).bytes)
24
+ rescue Encoding::UndefinedConversionError
25
+ result << ret
26
+ result << @@getwch.call if ret == 224
27
+ end
28
+ end
29
+ result
30
+ end
31
+
32
+ def getc
33
+ unless @@buf.empty?
34
+ return @@buf.shift
35
+ end
36
+ input = getwch
37
+ alt = (@@GetKeyState.call(VK_LMENU) & 0x80) != 0
38
+ if input.size > 1
39
+ @@buf.concat(input)
40
+ else # single byte
41
+ case input[0]
42
+ when 0x00
43
+ getwch
44
+ alt = false
45
+ input = getwch
46
+ @@buf.concat(input)
47
+ when 0xE0
48
+ @@buf.concat(input)
49
+ input = getwch
50
+ @@buf.concat(input)
51
+ when 0x03
52
+ @@buf.concat(input)
53
+ else
54
+ @@buf.concat(input)
55
+ end
56
+ end
57
+ if alt
58
+ "\e".ord
59
+ else
60
+ @@buf.shift
61
+ end
62
+ end
63
+
64
+ def self.get_screen_size
65
+ csbi = 0.chr * 24
66
+ @@GetConsoleScreenBufferInfo.call(@@hConsoleHandle, csbi)
67
+ csbi[0, 4].unpack('SS')
68
+ end
69
+
70
+ def self.cursor_pos
71
+ csbi = 0.chr * 24
72
+ @@GetConsoleScreenBufferInfo.call(@@hConsoleHandle, csbi)
73
+ x = csbi[4, 2].unpack('s*').first
74
+ y = csbi[6, 4].unpack('s*').first
75
+ CursorPos.new(x, y)
76
+ end
77
+
78
+ def self.move_cursor_column(val)
79
+ @@SetConsoleCursorPosition.call(@@hConsoleHandle, cursor_pos.y * 65536 + val)
80
+ end
81
+
82
+ def self.move_cursor_up(val)
83
+ if val > 0
84
+ @@SetConsoleCursorPosition.call(@@hConsoleHandle, (cursor_pos.y - val) * 65536 + cursor_pos.x)
85
+ elsif val < 0
86
+ move_cursor_down(-val)
87
+ end
88
+ end
89
+
90
+ def self.move_cursor_down(val)
91
+ if val > 0
92
+ @@SetConsoleCursorPosition.call(@@hConsoleHandle, (cursor_pos.y + val) * 65536 + cursor_pos.x)
93
+ elsif val < 0
94
+ move_cursor_up(-val)
95
+ end
96
+ end
97
+
98
+ def self.erase_after_cursor
99
+ csbi = 0.chr * 24
100
+ @@GetConsoleScreenBufferInfo.call(@@hConsoleHandle, csbi)
101
+ cursor = csbi[4, 4].unpack('L').first
102
+ written = 0.chr * 4
103
+ @@FillConsoleOutputCharacter.call(@@hConsoleHandle, 0x20, get_screen_size.first - cursor_pos.x, cursor, written)
104
+ end
105
+
106
+ def self.scroll_down(val)
107
+ return if val.zero?
108
+ scroll_rectangle = [0, val, get_screen_size.last, get_screen_size.first].pack('s4')
109
+ destination_origin = 0 # y * 65536 + x
110
+ fill = [' '.ord, 0].pack('SS')
111
+ @@ScrollConsoleScreenBuffer.call(@@hConsoleHandle, scroll_rectangle, nil, destination_origin, fill)
112
+ end
113
+
114
+ def self.clear_screen
115
+ # TODO: Use FillConsoleOutputCharacter and FillConsoleOutputAttribute
116
+ print "\e[2J"
117
+ print "\e[1;1H"
118
+ end
119
+
120
+ def self.set_screen_size(rows, columns)
121
+ raise NotImplementedError
122
+ end
123
+
124
+ def prep
125
+ # do nothing
126
+ nil
127
+ end
128
+
129
+ def deprep(otio)
130
+ # do nothing
131
+ end
132
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reline
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - aycabta
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-04-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Alternative GNU Readline or Editline implementation by pure Ruby.
56
+ email:
57
+ - aycabta@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - BSDL
63
+ - COPYING
64
+ - README.md
65
+ - lib/reline.rb
66
+ - lib/reline/ansi.rb
67
+ - lib/reline/config.rb
68
+ - lib/reline/key_actor.rb
69
+ - lib/reline/key_actor/base.rb
70
+ - lib/reline/key_actor/emacs.rb
71
+ - lib/reline/key_actor/vi_command.rb
72
+ - lib/reline/key_actor/vi_insert.rb
73
+ - lib/reline/key_stroke.rb
74
+ - lib/reline/kill_ring.rb
75
+ - lib/reline/line_editor.rb
76
+ - lib/reline/unicode.rb
77
+ - lib/reline/unicode/east_asian_width.rb
78
+ - lib/reline/version.rb
79
+ - lib/reline/windows.rb
80
+ homepage: https://github.com/ruby/reline
81
+ licenses:
82
+ - Ruby License
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubygems_version: 3.0.3
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Alternative GNU Readline or Editline implementation by pure Ruby.
103
+ test_files: []