mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
[next] Testing XTerm (#1696)
This commit is contained in:
committed by
GitHub
parent
3aef5a99dc
commit
d8e1cb8b0f
37
pyscript.core/test/terminal.html
Normal file
37
pyscript.core/test/terminal.html
Normal file
@@ -0,0 +1,37 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>PyScript Next - Terminal</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/xterm@latest/css/xterm.min.css">
|
||||
<script type="module">
|
||||
import { Readline } from "https://cdn.jsdelivr.net/npm/xterm-readline@latest/+esm";
|
||||
const rl = new Readline;
|
||||
rl.setCheckHandler(text => !text.trimEnd().endsWith("&&"));
|
||||
|
||||
import { Terminal } from "https://cdn.jsdelivr.net/npm/xterm@latest/+esm";
|
||||
const term = new Terminal({
|
||||
theme: {
|
||||
background: "#191A19",
|
||||
foreground: "#F5F2E7",
|
||||
},
|
||||
cursorBlink: true,
|
||||
cursorStyle: "block",
|
||||
});
|
||||
term.loadAddon(rl);
|
||||
term.open(terminal);
|
||||
term.focus();
|
||||
|
||||
import { PyWorker } from "../dist/core.js";
|
||||
const { sync } = new PyWorker("terminal.py");
|
||||
Object.assign(sync, {
|
||||
readline: prompt => rl.read(prompt),
|
||||
write: line => term.write(line),
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="terminal"></div>
|
||||
</body>
|
||||
</html>
|
||||
22
pyscript.core/test/terminal.py
Normal file
22
pyscript.core/test/terminal.py
Normal file
@@ -0,0 +1,22 @@
|
||||
###### magic monkey patching ######
|
||||
import sys
|
||||
import builtins
|
||||
import js
|
||||
from pyscript import sync
|
||||
from pyodide.code import eval_code
|
||||
|
||||
sys.stdout = sync
|
||||
builtins.input = sync.readline
|
||||
|
||||
globals = {"js": js}
|
||||
|
||||
####### main code ######
|
||||
while True:
|
||||
code = input(f"> ")
|
||||
if len(code):
|
||||
try:
|
||||
result = eval_code(f"{code}", globals=globals)
|
||||
if result is not None:
|
||||
print(result)
|
||||
except:
|
||||
print(f"Unable to evaluate: {code}")
|
||||
Reference in New Issue
Block a user