mirror of
https://github.com/copy/v86.git
synced 2025-12-31 04:23:15 +00:00
refactored V86.wait_until_vga_screen_contains()
- reduced clutter and made control flow more comprehensible - moved initial delay of 100ms to expect(), needed for keyboard buffer "cooldown" in between commands
This commit is contained in:
parent
47fb4e1dd2
commit
92ba111d92
2 changed files with 29 additions and 45 deletions
|
|
@ -1397,36 +1397,53 @@ V86.prototype.wait_until_vga_screen_contains = async function(expected, options)
|
|||
const timeout_msec = options?.timeout_msec || 0;
|
||||
const changed_rows = new Set();
|
||||
const screen_put_char = args => changed_rows.add(args[0]);
|
||||
const contains_expected = expected.test ? expected.test : line => line.startsWith(expected);
|
||||
const contains_expected = (screen_line, pattern) => pattern.test ? pattern.test(screen_line) : screen_line.startsWith(pattern);
|
||||
const screen_lines = [];
|
||||
|
||||
this.add_listener("screen-put-char", screen_put_char);
|
||||
|
||||
const screen_lines = [];
|
||||
for(const screen_line of this.screen_adapter.get_text_screen())
|
||||
{
|
||||
if(match_multi)
|
||||
{
|
||||
screen_lines.push(screen_line.trimRight());
|
||||
}
|
||||
else if(contains_expected(screen_line))
|
||||
else if(contains_expected(screen_line, expected))
|
||||
{
|
||||
this.remove_listener("screen-put-char", screen_put_char);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
let succeeded;
|
||||
let succeeded = false;
|
||||
const end = timeout_msec ? performance.now() + timeout_msec : 0;
|
||||
loop: while(true)
|
||||
loop: while(!end || performance.now() < end)
|
||||
{
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
|
||||
if(end && performance.now() >= end)
|
||||
if(match_multi)
|
||||
{
|
||||
succeeded = false;
|
||||
break;
|
||||
let screen_height = screen_lines.length;
|
||||
while(screen_height > 0 && screen_lines[screen_height - 1] === "")
|
||||
{
|
||||
screen_height--;
|
||||
}
|
||||
const screen_offset = screen_height - expected.length;
|
||||
if(screen_offset >= 0)
|
||||
{
|
||||
let matches = true;
|
||||
for(let i = 0; i < expected.length && matches; i++)
|
||||
{
|
||||
matches = contains_expected(screen_lines[screen_offset + i], expected[i]);
|
||||
}
|
||||
if(matches)
|
||||
{
|
||||
succeeded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
|
||||
for(const row of changed_rows)
|
||||
{
|
||||
const screen_line = this.screen_adapter.get_text_row(row);
|
||||
|
|
@ -1434,47 +1451,13 @@ V86.prototype.wait_until_vga_screen_contains = async function(expected, options)
|
|||
{
|
||||
screen_lines[row] = screen_line.trimRight();
|
||||
}
|
||||
else if(contains_expected(screen_line))
|
||||
else if(contains_expected(screen_line, expected))
|
||||
{
|
||||
succeeded = true;
|
||||
break loop;
|
||||
}
|
||||
}
|
||||
changed_rows.clear();
|
||||
|
||||
if(!match_multi)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
let screen_height = screen_lines.length;
|
||||
while(screen_height > 0 && screen_lines[screen_height - 1] === "")
|
||||
{
|
||||
screen_height--;
|
||||
}
|
||||
const screen_offset = screen_height - expected.length;
|
||||
if(screen_offset < 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
let matches = true;
|
||||
for(let i = 0; i < expected.length && matches; i++)
|
||||
{
|
||||
if(expected[i].test)
|
||||
{
|
||||
matches = expected[i].test(screen_lines[screen_offset + i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
matches = screen_lines[screen_offset + i].startsWith(expected[i]);
|
||||
}
|
||||
}
|
||||
if(matches)
|
||||
{
|
||||
succeeded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.remove_listener("screen-put-char", screen_put_char);
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ async function expect(emulator, command, expected, timeout_msec)
|
|||
await pause(10);
|
||||
}
|
||||
expected = [new RegExp(regexp_escape(command.trimRight()) + "$"), ...expected];
|
||||
await pause(100);
|
||||
}
|
||||
if(!await emulator.wait_until_vga_screen_contains(expected, {timeout_msec: timeout_msec}))
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue