Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[建议]命令行工具 #436

Open
github0801230xyz opened this issue Jul 24, 2024 · 5 comments
Open

[建议]命令行工具 #436

github0801230xyz opened this issue Jul 24, 2024 · 5 comments

Comments

@github0801230xyz
Copy link

描述

见图
image

方案

呃。。。

其他

python能不能优化一下
这个eval的错误提示

@tjy-gitnub
Copy link
Owner

不是,你电脑里没有cmd和python吗(雾
如果你有什么好的方案,提交pr我们将乐意接受(。。。

@github0801230xyz
Copy link
Author

我电脑里确实有
不过你总得加个提示

屏幕截图 2024-08-29 133626
image


python的eval的bug提示改下行么(最好改成用另一台电脑运行相同代码的错误提示)

@tjy-gitnub
Copy link
Owner

什么eval???

@github0801230xyz
Copy link
Author

什么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;
           }
       }
   },

@github0801230xyz
Copy link
Author

#436 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants