yamatanooroti 0.0.6 → 0.0.7

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
  SHA256:
3
- metadata.gz: 7ec6554c150a5c256de88a3feda8e9a3b073bfdfc1af5925e82b78ec29563c83
4
- data.tar.gz: 54df3900576ae774f4c86642c98ae22854e8917927cbb570666b38ac22b8ba16
3
+ metadata.gz: b0fd9df2f9f10fe273c68653443f62f80a66b2c18e2f7fad4ad3a39bf2b41ff5
4
+ data.tar.gz: e349135272b3c4321e8e7a54d03fe8e22c5a3e237d1b6c134743f44d94ccb628
5
5
  SHA512:
6
- metadata.gz: e5765147b02b72bb30969075614e335d8019b6dd8c6ae5535d5170e5c18533dd6275fa065f413a9e1a2d5d126e6679010670d0a72d9c3e3216376386938e1886
7
- data.tar.gz: 1b403888aa4428770f105a2e415997a6460e0cfb25335ba50a29e34add5cee35611ce138298e4e2e5276a4d16e8ea4fd7bc18f205aca15edc835d9e7f1773e02
6
+ metadata.gz: 6d5612862c2a2286463a81af6b1cce97c95fc6fe8f231c8e1cd78a03c5ea4d5a582f51d5bb80f13f80c7fa3717db242c35e13f4d23fb4e846d7a38484336d860
7
+ data.tar.gz: e891f544e3433528a6ca47a49538fd4a571cbe8f9eca874091df1cec177ff9ba2199718ffa0cd6fc291d82d6ae0c8f2195ed99adbb24cf4206e3ea9b61e86ee8
@@ -1,3 +1,3 @@
1
1
  class Yamatanooroti
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
@@ -30,7 +30,18 @@ module Yamatanooroti::VTermTestCaseModule
30
30
 
31
31
  def write(str)
32
32
  sync
33
- @pty_input.write(str)
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
 
@@ -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.EventType = DL::KEY_EVENT
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.EventType = DL::KEY_EVENT
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
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.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - aycabta
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-14 00:00:00.000000000 Z
11
+ date: 2021-04-19 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.0.3
101
+ rubygems_version: 3.2.3
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