From 7382a71a61c243f641cdf43d784080b3a75670cc Mon Sep 17 00:00:00 2001 From: paulober <44974737+paulober@users.noreply.github.com> Date: Fri, 30 Aug 2024 18:14:13 +0100 Subject: [PATCH] Fix some input issues + upgrade to pico-mpy-com v1.0.4 Signed-off-by: paulober <44974737+paulober@users.noreply.github.com> --- README.md | 2 +- package-lock.json | 8 ++++---- package.json | 2 +- src/activator.mts | 31 ++++++++++++++++++++++++++----- src/terminal.mts | 3 +++ 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 801f1bd..5283c42 100755 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ On most Linux installations the device file of the Pico serial port is owned by ## Getting started -- First of all open a folder and run `> MicroPico > Configure Project` command via `Ctrl+Shift+P` (or the equivalent on your platform) VS Code command palette. This will import stubs for autocompletion and the settings into your project folder. For the auto-completion to work, the extension prompts you (after project configuration) to install recommended extensions mentioned in [\#Requirements](#requirements). +- First of all open a folder and run `> MicroPico > Configure Project` command via `Ctrl+Shift+P` (or the equivalent on your platform) VS Code command palette. This will import stubs for autocompletion and the settings into your project folder. For the autocompletion to work, the extension prompts you (after project configuration) to install recommended extensions mentioned in [\#Requirements](#requirements). - Have the onboard LED flashing in under 5 minutes: diff --git a/package-lock.json b/package-lock.json index ea4b739..ef150f3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,7 @@ "linux" ], "dependencies": { - "@paulober/pico-mpy-com": "^1.0.1", + "@paulober/pico-mpy-com": "^1.0.4", "@vscode/python-extension": "^1.0.5", "axios": "^1.7.5", "fs-extra": "^11.2.0", @@ -331,9 +331,9 @@ } }, "node_modules/@paulober/pico-mpy-com": { - "version": "1.0.1", - "resolved": "https://npm.pkg.github.com/download/@paulober/pico-mpy-com/1.0.1/80242a15979202a6c543bf56779a1d0be781d635", - "integrity": "sha512-K7dMxuCOksVxdOtBnI1ZALp/pqnKs3t/YctViHZQOmC7hjfFwvb+kPxYqdHREUN5SjO8zw2pgwhazhKMgLWFkQ==", + "version": "1.0.4", + "resolved": "https://npm.pkg.github.com/download/@paulober/pico-mpy-com/1.0.4/ae3a6637e8542c8e1a73e380681324ec089cfa2f", + "integrity": "sha512-FfXmcOIiM0+OzTk8agdiXT15eYMUnzT9sC/raB3DKKvQEQwC/VWIRgvi4NTAI0gdpOJIFCRHE2/A2rMOHlHieA==", "cpu": [ "x64", "arm64" diff --git a/package.json b/package.json index c6b5218..27d4fa3 100644 --- a/package.json +++ b/package.json @@ -611,7 +611,7 @@ "typescript-eslint": "^8.3.0" }, "dependencies": { - "@paulober/pico-mpy-com": "^1.0.1", + "@paulober/pico-mpy-com": "^1.0.4", "@vscode/python-extension": "^1.0.5", "axios": "^1.7.5", "fs-extra": "^11.2.0", diff --git a/src/activator.mts b/src/activator.mts index baa3847..1cd78c9 100644 --- a/src/activator.mts +++ b/src/activator.mts @@ -141,7 +141,10 @@ export default class Activator { let commandExecuting = false; this.terminal.onDidSubmit(async (cmd: string) => { if (commandExecuting) { - PicoMpyCom.getInstance().emit(PicoSerialEvents.relayInput, cmd); + PicoMpyCom.getInstance().emit( + PicoSerialEvents.relayInput, + Buffer.from(cmd.trim(), "utf-8") + ); return; } @@ -155,6 +158,7 @@ export default class Activator { // TODO: maybe this.ui?.userOperationStarted(); // this will make waiting for prompt falsethis.terminal.freeze(); commandExecuting = true; + this.ui?.userOperationStarted(); const result = await PicoMpyCom.getInstance().runFriendlyCommand( cmd, (open: boolean) => { @@ -172,7 +176,12 @@ export default class Activator { // write red text into terminal this.terminal?.write("\x1b[31mException occured\x1b[0m\r\n"); this.terminal?.write("\r\n"); + // important if for example a command requests input and the user + // stops it with the universal stop command but had already entered + // some input which hasn't been submitted yet + this.terminal?.clean(true); } + this.ui?.userOperationStopped(); commandExecuting = false; this.terminal?.prompt(); }); @@ -210,7 +219,7 @@ export default class Activator { .find(term => term.creationOptions.name === TERMINAL_NAME) ?.dispose(); } catch { - console.warn("Failed to dispose old terminals on reactivation."); + this.logger.warn("Failed to dispose old terminals on reactivation."); } const terminalOptions = { @@ -241,6 +250,19 @@ export default class Activator { vscode.window.onDidOpenTerminal(async newTerminal => { if (newTerminal.creationOptions.name === TERMINAL_NAME) { if (this.terminal?.getIsOpen()) { + // fix if all terminals are closed + // but close() has not been called + // for example if the vscode window was reloaded + // in some combination of reopening and restoring + // this situation can occur + if ( + vscode.window.terminals.filter( + t => t.creationOptions.name === TERMINAL_NAME + ).length < 2 + ) { + return; + } + void vscode.window.showWarningMessage( "Only one instance of MicroPico vREPL is recommended. " + "Closing new instance." @@ -1132,9 +1154,8 @@ export default class Activator { return; } - // double ctrl+c to stop any running program - // TODO: to be implemented - //await PicoMpyCom.getInstance().st; + // interrupt most running programs + PicoMpyCom.getInstance().interruptExecution(); // wait for the program to stop await new Promise(resolve => setTimeout(resolve, 100)); diff --git a/src/terminal.mts b/src/terminal.mts index 4e1d50b..5fd0d4e 100644 --- a/src/terminal.mts +++ b/src/terminal.mts @@ -282,6 +282,9 @@ export class Terminal implements Pseudoterminal { } private handleTab(): void { + if (this.buffer === "") { + return; + } // move cursor into next line this.writeEmitter.fire("\r\n");