Skip to content

Commit e848055

Browse files
committed
feat: --interactive flag
Redirects stdin into the simulated serial port Related: espressif/pytest-embedded#233
1 parent ea38315 commit e848055

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/APIClient.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { WebSocket } from 'ws';
2+
import { Writable } from 'stream';
23
import type {
34
APICommand,
45
APIError,
@@ -156,6 +157,19 @@ export class APIClient {
156157
});
157158
}
158159

160+
serialMonitorWritable() {
161+
return new Writable({
162+
write: (chunk, encoding, callback) => {
163+
if (typeof chunk === 'string') {
164+
chunk = Buffer.from(chunk, encoding);
165+
}
166+
this.serialMonitorWrite(chunk).then(() => {
167+
callback(null);
168+
}, callback);
169+
},
170+
});
171+
}
172+
159173
async framebufferRead(partId: string) {
160174
return await this.sendCommand<{ png: string }>('framebuffer:read', {
161175
id: partId,

src/help.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export function cliHelp() {
1212
{green --expect-text} <string> Expect the given text in the output
1313
{green --fail-text} <string> Fail if the given text is found in the output
1414
{green --elf} <path> ELF file to simulate (default: read from wokwi.toml)
15+
{green --interactive} Redirect stdin to the simulated serial port
1516
{green --scenario} <path> Run the given scenario (yaml) file, path is relative to project root
1617
{green --serial-log-file} <path> Save the serial monitor output to the given file
1718
{green --screenshot-part} <string> Take a screenshot of the given part id (from diagram.json)

src/main.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ async function main() {
2929
'--elf': String,
3030
'--expect-text': String,
3131
'--fail-text': String,
32+
'--interactive': Boolean,
3233
'--serial-log-file': String,
3334
'--scenario': String,
3435
'--screenshot-part': String,
@@ -46,6 +47,7 @@ async function main() {
4647
const elf = args['--elf'];
4748
const expectText = args['--expect-text'];
4849
const failText = args['--fail-text'];
50+
const interactive = args['--interactive'];
4951
const serialLogFile = args['--serial-log-file'];
5052
const scenarioFile = args['--scenario'];
5153
const timeout = args['--timeout'] ?? 30000;
@@ -255,6 +257,10 @@ async function main() {
255257
pause: timeToNextEvent >= 0,
256258
});
257259

260+
if (interactive) {
261+
process.stdin.pipe(client.serialMonitorWritable());
262+
}
263+
258264
if (timeToNextEvent > 0) {
259265
await client.simResume(timeToNextEvent);
260266
}

0 commit comments

Comments
 (0)