MCPcopy Index your code
hub / github.com/pyscript/pyscript / init

Function init

core/src/plugins/py-terminal/mpy.js:84–121  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

82 // common main thread initialization for both worker
83 // or main case, bootstrapping the terminal on its target
84 const init = () => {
85 let target = element;
86 const selector = target.getAttribute("target");
87 if (selector) {
88 target =
89 document.getElementById(selector) ||
90 document.querySelector(selector);
91 if (!target) throw new Error(`Unknown target ${selector}`);
92 } else {
93 target = document.createElement("py-terminal");
94 target.style.display = "block";
95 element.after(target);
96 }
97 const terminal = new Terminal({
98 theme: {
99 background: "#191A19",
100 foreground: "#F5F2E7",
101 },
102 ...terminalOptions,
103 });
104 const fitAddon = new FitAddon();
105 terminal.loadAddon(fitAddon);
106 terminal.loadAddon(new WebLinksAddon());
107 terminal.open(target);
108 fitAddon.fit();
109 terminal.focus();
110 defineProperties(element, {
111 terminal: { value: terminal },
112 process: {
113 value: async (code) => {
114 for (const line of code.split(/(?:\r\n|\r|\n)/)) {
115 await stream.write(`${line}\r`);
116 }
117 },
118 },
119 });
120 return terminal;
121 };
122
123 // branch logic for the worker
124 if (element.hasAttribute("worker")) {

Callers 1

mpy.jsFile · 0.70

Calls 5

fitMethod · 0.80
loadAddonMethod · 0.45
openMethod · 0.45
focusMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected