yamatanooroti 0.0.5 → 0.0.9
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.
- checksums.yaml +4 -4
- data/lib/yamatanooroti/version.rb +1 -1
- data/lib/yamatanooroti/vterm.rb +21 -2
- data/lib/yamatanooroti/windows.rb +31 -16
- metadata +17 -4
- data/lib/yamatanooroti/vterm.rb.orig +0 -70
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a51e36e0f854db73b07bb49b5d1d5814daba6677de910fe7e3abc9b2099364f7
|
4
|
+
data.tar.gz: 00d11181f6e956a9fca14e84d4ec5b39896575bab9044b6092b6733c32805f8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd489a9b4f90e6736fb035176d1942d87a8057dc6578a516703a0da4f9110a497b07983d5028db8747afe754f59191dacbda937dd29e28acf52fce1937998e0b
|
7
|
+
data.tar.gz: cd56856af0b8fd4f6809cf838389a2a199013ccf4d0f19c886bb7ffc3c769bc1447a87e36abfc1c359bf346cf2e60f94898f2b034427921410a1913a8b9641f5
|
data/lib/yamatanooroti/vterm.rb
CHANGED
@@ -30,7 +30,18 @@ module Yamatanooroti::VTermTestCaseModule
|
|
30
30
|
|
31
31
|
def write(str)
|
32
32
|
sync
|
33
|
-
|
33
|
+
str_to_write = String.new(encoding: Encoding::ASCII_8BIT)
|
34
|
+
str.chars.each do |c|
|
35
|
+
byte = c.force_encoding(Encoding::ASCII_8BIT).ord
|
36
|
+
if c.bytesize == 1 and byte.allbits?(0x80) # with Meta key
|
37
|
+
c = (byte ^ 0x80).chr
|
38
|
+
str_to_write << "\e"
|
39
|
+
str_to_write << c
|
40
|
+
else
|
41
|
+
str_to_write << c
|
42
|
+
end
|
43
|
+
end
|
44
|
+
@pty_input.write(str_to_write)
|
34
45
|
sync
|
35
46
|
end
|
36
47
|
|
@@ -79,7 +90,15 @@ module Yamatanooroti::VTermTestCaseModule
|
|
79
90
|
@result << ''
|
80
91
|
cols.times do |c|
|
81
92
|
cell = @screen.cell_at(r, c)
|
82
|
-
|
93
|
+
if cell.char # The second cell of fullwidth char will be nil.
|
94
|
+
if cell.char.empty?
|
95
|
+
# There will be no char to the left of the rendered area if moves
|
96
|
+
# the cursor.
|
97
|
+
@result.last << ' '
|
98
|
+
else
|
99
|
+
@result.last << cell.char
|
100
|
+
end
|
101
|
+
end
|
83
102
|
end
|
84
103
|
@result.last.gsub!(/ *$/, '')
|
85
104
|
end
|
@@ -147,6 +147,7 @@ module Yamatanooroti::WindowsDefinition
|
|
147
147
|
TH32CS_SNAPPROCESS = 0x00000002
|
148
148
|
PROCESS_ALL_ACCESS = 0x001FFFFF
|
149
149
|
SW_HIDE = 0
|
150
|
+
LEFT_ALT_PRESSED = 0x0002
|
150
151
|
|
151
152
|
# HANDLE GetStdHandle(DWORD nStdHandle);
|
152
153
|
extern 'HANDLE GetStdHandle(DWORD);', :stdcall
|
@@ -169,6 +170,10 @@ module Yamatanooroti::WindowsDefinition
|
|
169
170
|
extern 'BOOL SetConsoleWindowInfo(HANDLE, BOOL, PSMALL_RECT);', :stdcall
|
170
171
|
# BOOL WriteConsoleInputW(HANDLE hConsoleInput, const INPUT_RECORD *lpBuffer, DWORD nLength, LPDWORD lpNumberOfEventsWritten);
|
171
172
|
extern 'BOOL WriteConsoleInputW(HANDLE, const INPUT_RECORD*, DWORD, LPDWORD);', :stdcall
|
173
|
+
# SHORT VkKeyScanW(WCHAR ch);
|
174
|
+
extern 'SHORT VkKeyScanW(WCHAR);', :stdcall
|
175
|
+
# UINT MapVirtualKeyW(UINT uCode, UINT uMapType);
|
176
|
+
extern 'UINT MapVirtualKeyW(UINT, UINT);', :stdcall
|
172
177
|
# BOOL ReadConsoleOutputW(HANDLE hConsoleOutput, PCHAR_INFO lpBuffer, COORD dwBufferSize, COORD dwBufferCoord, PSMALL_RECT lpReadRegion);
|
173
178
|
extern 'BOOL ReadConsoleOutputW(HANDLE, PCHAR_INFO, COORD, COORD, PSMALL_RECT);', :stdcall
|
174
179
|
# BOOL WINAPI SetCurrentConsoleFontEx(HANDLE hConsoleOutput, BOOL bMaximumWindow, PCONSOLE_FONT_INFOEX lpConsoleCurrentFontEx);
|
@@ -362,33 +367,43 @@ module Yamatanooroti::WindowsTestCaseModule
|
|
362
367
|
|
363
368
|
def write(str)
|
364
369
|
sleep @wait
|
365
|
-
str.tr!("\n", "\r")
|
370
|
+
str.force_encoding(Encoding::ASCII_8BIT).tr!("\n", "\r")
|
366
371
|
records = Fiddle::Pointer.malloc(DL::INPUT_RECORD_WITH_KEY_EVENT.size * str.size * 2, DL::FREE)
|
367
372
|
str.chars.each_with_index do |c, i|
|
373
|
+
byte = c.ord
|
374
|
+
if c.bytesize == 1 and byte.allbits?(0x80) # with Meta key
|
375
|
+
c = (byte ^ 0x80).chr
|
376
|
+
control_key_state = DL::LEFT_ALT_PRESSED
|
377
|
+
else
|
378
|
+
control_key_state = 0
|
379
|
+
end
|
368
380
|
record_index = i * 2
|
369
381
|
r = DL::INPUT_RECORD_WITH_KEY_EVENT.new(records + DL::INPUT_RECORD_WITH_KEY_EVENT.size * record_index)
|
370
|
-
r
|
371
|
-
r.bKeyDown = 1
|
372
|
-
r.wRepeatCount = 0
|
373
|
-
r.wVirtualKeyCode = 0
|
374
|
-
r.wVirtualScanCode = 0
|
375
|
-
r.UnicodeChar = c.unpack('U').first
|
376
|
-
r.dwControlKeyState = 0
|
382
|
+
set_input_record(r, c, true, control_key_state)
|
377
383
|
record_index = i * 2 + 1
|
378
384
|
r = DL::INPUT_RECORD_WITH_KEY_EVENT.new(records + DL::INPUT_RECORD_WITH_KEY_EVENT.size * record_index)
|
379
|
-
r
|
380
|
-
r.bKeyDown = 0
|
381
|
-
r.wRepeatCount = 0
|
382
|
-
r.wVirtualKeyCode = 0
|
383
|
-
r.wVirtualScanCode = 0
|
384
|
-
r.UnicodeChar = c.unpack('U').first
|
385
|
-
r.dwControlKeyState = 0
|
385
|
+
set_input_record(r, c, false, control_key_state)
|
386
386
|
end
|
387
387
|
written_size = Fiddle::Pointer.malloc(Fiddle::SIZEOF_DWORD, DL::FREE)
|
388
388
|
r = DL.WriteConsoleInputW(DL.GetStdHandle(DL::STD_INPUT_HANDLE), records, str.size * 2, written_size)
|
389
389
|
error_message(r, 'WriteConsoleInput')
|
390
390
|
end
|
391
391
|
|
392
|
+
private def set_input_record(r, c, key_down, control_key_state)
|
393
|
+
begin
|
394
|
+
code = c.unpack('U').first
|
395
|
+
rescue ArgumentError
|
396
|
+
code = c.bytes.first
|
397
|
+
end
|
398
|
+
r.EventType = DL::KEY_EVENT
|
399
|
+
r.bKeyDown = key_down ? 1 : 0
|
400
|
+
r.wRepeatCount = 1
|
401
|
+
r.wVirtualKeyCode = DL.VkKeyScanW(code)
|
402
|
+
r.wVirtualScanCode = DL.MapVirtualKeyW(code, 0)
|
403
|
+
r.UnicodeChar = code
|
404
|
+
r.dwControlKeyState = control_key_state
|
405
|
+
end
|
406
|
+
|
392
407
|
private def free_resources
|
393
408
|
h_snap = DL.CreateToolhelp32Snapshot(DL::TH32CS_SNAPPROCESS, 0)
|
394
409
|
pe = DL::PROCESSENTRY32W.malloc
|
@@ -478,7 +493,7 @@ module Yamatanooroti::WindowsTestCaseModule
|
|
478
493
|
end
|
479
494
|
end
|
480
495
|
|
481
|
-
def start_terminal(height, width, command, wait: 1)
|
496
|
+
def start_terminal(height, width, command, wait: 1, startup_message: nil)
|
482
497
|
@height = height
|
483
498
|
@width = width
|
484
499
|
@wait = wait
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yamatanooroti
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- aycabta
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-unit
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: reline
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: " Yamatanooroti is a multi-platform real(?) terminal test framework.\n"
|
56
70
|
email:
|
57
71
|
- aycabta@gmail.com
|
@@ -64,7 +78,6 @@ files:
|
|
64
78
|
- lib/yamatanooroti.rb
|
65
79
|
- lib/yamatanooroti/version.rb
|
66
80
|
- lib/yamatanooroti/vterm.rb
|
67
|
-
- lib/yamatanooroti/vterm.rb.orig
|
68
81
|
- lib/yamatanooroti/windows.rb
|
69
82
|
homepage: https://github.com/aycabta/yamatanooroti
|
70
83
|
licenses:
|
@@ -85,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
98
|
- !ruby/object:Gem::Version
|
86
99
|
version: '0'
|
87
100
|
requirements: []
|
88
|
-
rubygems_version: 3.
|
101
|
+
rubygems_version: 3.2.22
|
89
102
|
signing_key:
|
90
103
|
specification_version: 4
|
91
104
|
summary: Multi-platform real(?) terminal test framework
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'test-unit'
|
2
|
-
require 'vterm'
|
3
|
-
require 'pty'
|
4
|
-
|
5
|
-
module Yamatanooroti::VTermTestCaseModule
|
6
|
-
def start_terminal(height, width, command, wait: 0.1)
|
7
|
-
@wait = wait
|
8
|
-
|
9
|
-
@pty_output, @pty_input, @pid = PTY.spawn(*command)
|
10
|
-
|
11
|
-
@vterm = VTerm.new(height, width)
|
12
|
-
@vterm.set_utf8(true)
|
13
|
-
|
14
|
-
@screen = @vterm.screen
|
15
|
-
@screen.reset(true)
|
16
|
-
|
17
|
-
sync
|
18
|
-
end
|
19
|
-
|
20
|
-
def write(str)
|
21
|
-
sync
|
22
|
-
@pty_input.write(str)
|
23
|
-
sync
|
24
|
-
end
|
25
|
-
|
26
|
-
def close
|
27
|
-
sync
|
28
|
-
@pty_input.close
|
29
|
-
sync
|
30
|
-
end
|
31
|
-
|
32
|
-
private def sync
|
33
|
-
loop do
|
34
|
-
sleep @wait
|
35
|
-
chunk = @pty_output.read_nonblock(1024)
|
36
|
-
@vterm.write(chunk)
|
37
|
-
chunk = @vterm.read
|
38
|
-
@pty_input.write(chunk)
|
39
|
-
rescue Errno::EAGAIN, Errno::EWOULDBLOCK
|
40
|
-
break
|
41
|
-
rescue Errno::EIO # EOF
|
42
|
-
break
|
43
|
-
rescue IO::EAGAINWaitReadable # emtpy buffer
|
44
|
-
break
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def assert_screen(expected_lines)
|
49
|
-
actual_lines = []
|
50
|
-
rows, cols = @vterm.size
|
51
|
-
rows.times do |r|
|
52
|
-
actual_lines << ''
|
53
|
-
cols.times do |c|
|
54
|
-
cell = @screen.cell_at(r, c)
|
55
|
-
actual_lines.last << cell.char if cell.char
|
56
|
-
end
|
57
|
-
actual_lines.last.gsub!(/ *$/, '')
|
58
|
-
end
|
59
|
-
case expected_lines
|
60
|
-
when Array
|
61
|
-
assert_equal(expected_lines, actual_lines)
|
62
|
-
when String
|
63
|
-
assert_equal(expected_lines, actual_lines.join("\n").sub(/\n*\z/, "\n"))
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
class Yamatanooroti::VTermTestCase < Test::Unit::TestCase
|
69
|
-
include Yamatanooroti::VTermTestCaseModule
|
70
|
-
end
|