Skip to content

Commit

Permalink
Fix some input issues + upgrade to pico-mpy-com v1.0.4
Browse files Browse the repository at this point in the history
Signed-off-by: paulober <44974737+paulober@users.noreply.github.com>
  • Loading branch information
paulober committed Aug 30, 2024
1 parent 829f45a commit 7382a71
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
31 changes: 26 additions & 5 deletions src/activator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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) => {
Expand All @@ -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();
});
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -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));
Expand Down
3 changes: 3 additions & 0 deletions src/terminal.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down

0 comments on commit 7382a71

Please sign in to comment.