javascript:jquery:terminal_emulator_plugin

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
次のリビジョン両方とも次のリビジョン
javascript:jquery:terminal_emulator_plugin [2019/08/17 17:37] ともやんjavascript:jquery:terminal_emulator_plugin [2019/08/20 15:12] ともやん
行 1: 行 1:
-<ifauth !@loggedinusers><html> 
-<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> 
-<script> 
-     (adsbygoogle = window.adsbygoogle || []).push({ 
-          google_ad_client: "ca-pub-0791334967460971", 
-          enable_page_level_ads: true 
-     }); 
-</script></html></ifauth> 
 <html> <html>
-  <script src="https://www.tomoyan.net/_media/javascript/jquery/jquery.terminal-2.7.1.min.js"></script> +  <script src="/_media/javascript/jquery/jquery.terminal-2.7.1.min.js"></script> 
-  <link href="https://www.tomoyan.net/_media/javascript/jquery/jquery.terminal-2.7.1.css" rel="stylesheet"/>+  <link href="/_media/javascript/jquery/jquery.terminal-2.7.1.css" rel="stylesheet"/>
   <script>   <script>
     jQuery(function($, undefined) {     jQuery(function($, undefined) {
       term = $('#term_demo');       term = $('#term_demo');
-      term.terminal(function(command) { +      term.terminal(function(command, term) { 
-        if (command !== '') {+        if (command == 'help') { 
 +          term.echo('load python - Python Interpreter'); 
 +        } 
 +        else if (command == 'load python') { 
 +          if (typeof(pyodide) != 'undefined'
 +            return; 
 + 
 +          self.startTime = new Date(); 
 +          self.languagePluginUrl = '/_media/python/pyodide/'; 
 +          $.ajax({ 
 +            url: self.languagePluginUrl + 'pyodide_dev.js', 
 +            async: false, 
 +            dataType: "script" 
 +          }); 
 +          $('<link/>',
 +            rel: 'stylesheet', type: 'text/css', href: self.languagePluginUrl + 'renderedhtml.css' 
 +          }).appendTo('head'); 
 +          languagePluginLoader.then(() => { 
 +            term.echo('languagePluginLoader.then()'); 
 +            function pushCode(line) { 
 +              handleResult(c.push(line)) 
 +            } 
 +            self.endTime = new Date(); 
 +            var ms = self.endTime.getTime() - self.startTime.getTime(); 
 +            term.terminal( 
 +              pushCode, 
 +              { 
 +                greetings: "Interpreter Loading time: " + ms + "ms\r\n" +  
 +                           "Welcome to the Pyodide terminal emulator 🐍", 
 +                prompt: "[[;red;]>>> ]" 
 +              } 
 +            ); 
 +            pyodide.runPython(` 
 +              import io, code, sys 
 +              from js import term, pyodide 
 + 
 +              class Console(code.InteractiveConsole): 
 +                def runcode(self, code): 
 +                  sys.stdout = io.StringIO() 
 +                  sys.stderr = io.StringIO() 
 +                  term.runPython("\\n".join(self.buffer)) 
 +              _c = Console(locals=globals()) 
 +            `) 
 + 
 +            var c = pyodide.pyimport('_c'
 + 
 +            function handleResult(result) { 
 +              if (result) { 
 +                term.set_prompt('[[;gray;]... ]') 
 +              } else { 
 +                term.set_prompt('[[;red;]>>> ]') 
 +                var stderr = pyodide.runPython("sys.stderr.getvalue()").trim() 
 +                if (stderr) { 
 +                  term.echo(`[[;red;]${stderr}]`) 
 +                } else { 
 +                  var stdout = pyodide.runPython("sys.stdout.getvalue()"
 +                  if (stdout) { 
 +                    term.echo(stdout.trim()) 
 +                  } 
 +                } 
 +              } 
 +            } 
 + 
 +            term.runPython = function(code) { 
 +              pyodide.runPythonAsync(code).then( 
 +                term.handlePythonResult, term.handlePythonError 
 +              ) 
 +            } 
 + 
 +            term.handlePythonResult = function(result) { 
 +              if (result === undefined) { 
 +                return 
 +              } else if (result['_repr_html_'] !== undefined) { 
 +                term.echo(result['_repr_html_'], {raw: true}) 
 +              } else { 
 +                term.echo(result.toString()) 
 +              } 
 +            } 
 + 
 +            term.handlePythonError = function(result) { 
 +              term.error(result.toString()) 
 +            } 
 +          }); 
 +        } 
 +        else if (command !== '') {
           try {           try {
             var result = window.eval(command);             var result = window.eval(command);
行 27: 行 103:
         }         }
       }, {       }, {
-        greetings: 'JavaScript Interpreter Version ' + $.terminal.version,+        greetings: 'JavaScript Interpreter Version ' + $.terminal.version + '\r\n'
 +        navigator.userAgent,
         name: 'js_demo',         name: 'js_demo',
         height: 200,         height: 200,
-        prompt: 'js> '+        prompt: 'js > '
       });       });
       function dir(object) {       function dir(object) {
行 65: 行 142:
 Copyright (c) 2011-2019 Jakub T. Jankiewicz <https://jcubic.pl/me> Copyright (c) 2011-2019 Jakub T. Jankiewicz <https://jcubic.pl/me>
  
 +js > help
 +load python - Python Interpreter
 js > js >
 </code> </code>
 </WRAP> </WRAP>
- 
  • javascript/jquery/terminal_emulator_plugin.txt
  • 最終更新: 2019/09/05 01:09
  • by ともやん