Skip to content

Commit

Permalink
Move the stop button to the input line.
Browse files Browse the repository at this point in the history
  • Loading branch information
rblank committed Feb 16, 2025
1 parent 0b423bb commit 75b92e2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
21 changes: 14 additions & 7 deletions docs/reference/exec.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Code execution

The {rst:dir}`exec` directive allows executing code directly in the browser.
The {rst:dir}`exec` directive allows executing code from the browser.

```{exec} sql
:name: sql-countries
Expand All @@ -28,10 +28,10 @@ insert into countries values

## Directive

````{rst:directive} .. exec:: language (html | python | sql)
This directive is a {rst:dir}`code-block` that allows executing the code
directly in the browser. It supports most of the options of
{rst:dir}`code-block`, and a few more described below.
````{rst:directive} .. exec:: runner (html | micropython | python | sql)
This directive is a {rst:dir}`code-block` that allows executing code from the
browser. It supports most of the options of {rst:dir}`code-block`, and a few
more described below.
{.rubric}
Options
Expand All @@ -52,7 +52,7 @@ Prepend the content of one or more files to the block's content.
```{rst:directive:option} output-style: property: value; [property: value; ...]
CSS styles to apply to the output generated by the code block, e.g.
`max-height: 10rem`. To which element the styles are applied is
language-specific.
runner-specific.
```
```{rst:directive:option} style: property: value; [property: value; ...]
CSS styles to apply to the code block and editor, e.g. `max-height: 20rem`.
Expand Down Expand Up @@ -160,13 +160,20 @@ content.
select * from people;
```

## Languages
## Runners

### HTML

HTML code execution displays a complete HTML document as an `<iframe>`, with
limited browsing functionality.

### MicroPython

This runner connects to an embedded system running
[MicroPython](https://micropython.org). The code is run from RAM and is
therefore transient. It can also be written to the file `main.py` in flash
memory, so that it is run at boot-time.

### Python

Python code execution is based on [Pyodide](https://pyodide.org/) and
Expand Down
19 changes: 10 additions & 9 deletions tdoc/common/static/tdoc/exec-micropython.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import {getSerials, onSerial, requestSerial} from './serial.js';
const form_feed = '\x0c';

const options = [{
// Raspberry Pi / MicroPython
match: {usbVendorId: 0x2e8a, usbProductId: 0x0005},
open: {baudRate: 1000000},
// // Raspberry Pi / MicroPython
// match: {usbVendorId: 0x2e8a, usbProductId: 0x0005},
// open: {baudRate: 1000000},
// }, {
// // ARM Ltd / ARM mbed (BBC micro:bit)
// match: {usbVendorId: 0x0d28, usbProductId: 0x0204},
// open: {baudRate: 115200},
}, {
// }, {
open: {baudRate: 115200},
}];

Expand All @@ -43,8 +43,8 @@ class MicroPythonExecutor extends Executor {
addControls(controls) {
if (this.when !== 'never') {
this.runCtrl = controls.appendChild(this.runControl());
this.stopCtrl = controls.appendChild(this.stopControl());
this.connectCtrl = controls.appendChild(this.connectControl());
this.input = this.inputControl(data => this.send(data + '\r\n'));
}
super.addControls(controls);
}
Expand Down Expand Up @@ -75,11 +75,11 @@ class MicroPythonExecutor extends Executor {
btn.click();
}
});
div.appendChild(this.stopControl());
return div;
}

onReady() {
this.input = this.inputControl(data => this.send(data + '\r\n'));
this.enableInput(false);
this.setSerial();
onSerial(this, {
Expand All @@ -91,9 +91,10 @@ class MicroPythonExecutor extends Executor {
}

enableInput(enable) {
this.stopCtrl.disabled = !enable;
this.input.querySelector('input').disabled = !enable;
this.input.querySelector('button').disabled = !enable;
if (!this.input) return;
for (const el of this.input.querySelectorAll('input, button')) {
el.disabled = !enable;
}
}

setSerial(serial) {
Expand Down

0 comments on commit 75b92e2

Please sign in to comment.