tjy-gitnub / win12

Windows 12 网页版,在线体验 点击下面的链接在线体验
https://tjy-gitnub.github.io/win12/desktop.html
Eclipse Public License 2.0
6.64k stars 817 forks source link

python eval error #489

Open github0801230xyz opened 1 month ago

github0801230xyz commented 1 month ago
          > 什么eval???
 catch (err) {
                        var newD = document.createElement('div');
                        newD.innerText = `${err.message}`;
                        elt.appendChild(newD);
                    }

desktop.js line 675-679 v5.2.3 err.message 好像报eval的错误

@tjy-gitnub

more


$('#win-python').html(`
<pre>
Python 3.10.2  [MSC v.1912 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
</pre>
<pre class="text-cmd"></pre>
<pre style="display: flex;"><span class='prompt'>>>> </span><input type="text" onkeyup="if (event.keyCode == 13) { apps.python.run(); }"></pre>`);
},
run: () => {
if (apps.python.pyodide) {
const input = document.querySelector('#win-python>pre>input');
const _code = input.value;
const elt = document.querySelector('#win-python>pre.text-cmd');
const lastChar = _code[_code.length - 1];
var newD = document.createElement('div');
newD.innerText = `${apps.python.prompt}${_code}`;
elt.appendChild(newD);
if (lastChar != ':' && lastChar != '\\' && ((!apps.python.indent || _code == ''))) {
apps.python.prompt = '>>> ';
apps.python.codeCache += _code;
apps.python.indent = false;
const code = apps.python.codeCache;
apps.python.codeCache = '';
apps.python.pyodide.runPython('sys.stdout = io.StringIO()');
try {
const result = String(apps.python.pyodide.runPython(code));
if (apps.python.pyodide.runPython('sys.stdout.getvalue()')) {
var newD = document.createElement('div');
newD.innerText = `${apps.python.pyodide.runPython('sys.stdout.getvalue()')}`;
elt.appendChild(newD);
}
if (result && result != 'undefined') {
var newD = document.createElement('div');
if (result == 'false') {
newD.innerText = 'False';
}
else if (result == 'true') {
newD.innerText = 'True';
}
else {
newD.innerText = result;
}
elt.appendChild(newD);
}
}
catch (err) {
var newD = document.createElement('div');
newD.innerText = `${err.message}`;
elt.appendChild(newD);
}
}
else {
apps.python.prompt = '... ';
if (lastChar == ':') {
apps.python.indent = true;
}
apps.python.codeCache += _code + '\n';
}
input.value = "";
            // 自动聚焦
            input.blur();
            input.focus();

            document.querySelector('#win-python .prompt').innerText = apps.python.prompt;
        }
    }
},


_Originally posted by @github0801230xyz in https://github.com/tjy-gitnub/win12/issues/436#issuecomment-2396760940_
github0801230xyz commented 1 month ago

image image

NB-Group commented 1 month ago

你可以尝试提交 PR ,我们乐意接受,我会帮你合并。 这样也可以计入你的贡献里。