mirror of https://github.com/pyodide/pyodide.git
Fix terminal Ctrl+C handling (#1790)
This commit is contained in:
parent
bb2f594372
commit
cacfdde929
|
@ -11,6 +11,15 @@ substitutions:
|
|||
|
||||
# Change Log
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Console
|
||||
|
||||
- {{Fix}} Ctrl+C handling in console now works correctly with multiline input.
|
||||
New behavior more closely approximates the behavior of the native Python
|
||||
console.
|
||||
{pr}`1790`
|
||||
|
||||
## Version 0.18.0
|
||||
|
||||
_August 3rd, 2021_
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
<style>
|
||||
.terminal {
|
||||
--size: 1.5;
|
||||
--color: rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
@ -30,20 +31,23 @@
|
|||
pyodide.runPython(
|
||||
`
|
||||
import sys
|
||||
import js
|
||||
from pyodide import to_js
|
||||
from pyodide.console import PyodideConsole, repr_shorten, BANNER
|
||||
import __main__
|
||||
BANNER = "Welcome to the Pyodide terminal emulator 🐍\\n" + BANNER
|
||||
js.pyconsole = PyodideConsole(__main__.__dict__)
|
||||
pyconsole = PyodideConsole(__main__.__dict__)
|
||||
async def await_fut(fut):
|
||||
return to_js([await fut], depth=1)
|
||||
def clear_console():
|
||||
pyconsole.buffer = []
|
||||
`,
|
||||
namespace
|
||||
);
|
||||
let repr_shorten = namespace.get("repr_shorten");
|
||||
let banner = namespace.get("BANNER");
|
||||
let await_fut = namespace.get("await_fut");
|
||||
let pyconsole = namespace.get("pyconsole");
|
||||
let clear_console = namespace.get("clear_console");
|
||||
namespace.destroy();
|
||||
|
||||
let ps1 = ">>> ",
|
||||
|
@ -116,6 +120,15 @@
|
|||
completion: function (command, callback) {
|
||||
callback(pyconsole.complete(command).toJs()[0]);
|
||||
},
|
||||
keymap: {
|
||||
"CTRL+C": async function (event, original) {
|
||||
clear_console();
|
||||
term.echo_command();
|
||||
term.echo("KeyboardInterrupt");
|
||||
term.set_command("");
|
||||
term.set_prompt(ps1);
|
||||
},
|
||||
},
|
||||
});
|
||||
window.term = term;
|
||||
pyconsole.stdout_callback = (s) => term.echo(s, { newline: false });
|
||||
|
|
Loading…
Reference in New Issue