Skip to content

Commit

Permalink
Send an interrupt signal on Ctrl+C in the line input.
Browse files Browse the repository at this point in the history
  • Loading branch information
rblank committed Mar 1, 2025
1 parent 5d38d45 commit 3ab28e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion tdoc/common/static/tdoc/exec-micropython.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,16 @@ class MicroPythonExecutor extends Executor {
input.value = '';
onSend(value);
});
div.appendChild(this.stopControl());
const stop = div.appendChild(this.stopControl());
stop.setAttribute('title', `${stop.getAttribute('title')} (Ctrl+C)`);
const input = div.querySelector('input');
input.addEventListener('keydown', e => {
if (e.ctrlKey && e.key === 'c' && !e.altKey && !e.metaKey
&& input.selectionStart === input.selectionEnd) {
e.preventDefault();
stop.click();
}
});
return div;
}

Expand Down
4 changes: 2 additions & 2 deletions tdoc/common/static/tdoc/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ class SectionedOutput {
const btn = div.appendChild(element(`\
<button class="tdoc-send" title="Send input (Enter)">Send</button>`));
btn.addEventListener('click', () => onSend(input));
input.addEventListener('keydown', (e) => {
input.addEventListener('keydown', e => {
if (e.key === 'Enter' && !e.altKey && !e.ctrlKey && !e.metaKey) {
e.preventDefault();
btn.click();
Expand All @@ -376,7 +376,7 @@ class SectionedOutput {
const btn = div.appendChild(element(`\
<button class="tdoc-send" title="Send input (Shift+Enter)">Send</button>`));
btn.addEventListener('click', () => onSend(input));
input.addEventListener('keydown', (e) => {
input.addEventListener('keydown', e => {
if (e.key === 'Enter' && e.shiftKey && !e.altKey &&
!e.ctrlKey && !e.metaKey) {
e.preventDefault();
Expand Down

0 comments on commit 3ab28e7

Please sign in to comment.