Path: blob/main/desktop/electron/src/python-terminal.ts
1067 views
import "xterm/css/xterm.css";1import { Terminal } from "xterm";2import setTheme from "./xterm-theme";3import { WebLinksAddon } from "xterm-addon-web-links";45export default async function terminal(element: HTMLDivElement) {6const term = new Terminal({ convertEol: true });7term.options.allowProposedApi = true;8term.loadAddon(new WebLinksAddon());9term.open(element);10(element.children[0] as any).style.padding = "15px";11term.resize(80, 40);12term.write(13"This is a demo of https://www.npmjs.com/package/python-wasm\nIt includes numpy, sympy and pandas. "14);15term.write(16"Try 'import pandas' below.\nControl+c to interrupt and time.sleep to pause are also supported.\n\n"17);18setTheme(term, "solarized-light");1920// Start the terminal:21window.electronAPI.pythonTerminal();2223// process output from the terminal24window.electronAPI.onPythonStdout((data) => {25term.write(data);26});27window.electronAPI.onPythonStderr((data) => {28term.write(data);29});3031term.onData((data) => {32window.electronAPI.pythonStdin(data);33});34/*35const python = await pythonWasm();36// @ts-ignore37element.children[0].style.padding = "15px";38term.resize(80, 40);39term.write(40"This is a demo of https://www.npmjs.com/package/python-wasm\nIt includes numpy and sympy. "41);42term.write(43"Try 'import numpy' and 'import sympy' below.\nControl+c to interrupt and time.sleep to pause are also supported.\n\n"44);45setTheme(term, "solarized-light");46term.onData((data) => {47python.kernel.writeToStdin(data);48});49python.kernel.on("stdout", (data) => {50term.write(data);51});52python.kernel.on("stderr", (data) => {53term.write(data);54});55await python.terminal();56python.kernel.terminate();57*/58}596061