差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
javascript:jquery:terminal_emulator_plugin [2019/08/17 20:20] – ともやん | javascript:jquery:terminal_emulator_plugin [2019/09/05 01:09] (現在) – ともやん | ||
---|---|---|---|
行 1: | 行 1: | ||
- | <ifauth !@loggedinusers>< | ||
- | <script async src="// | ||
- | < | ||
- | | ||
- | google_ad_client: | ||
- | enable_page_level_ads: | ||
- | }); | ||
- | </ | ||
< | < | ||
- | <script src="https:// | + | <script src="/ |
- | <link href="https:// | + | <link href="/ |
< | < | ||
jQuery(function($, | jQuery(function($, | ||
行 15: | 行 7: | ||
term.terminal(function(command, | term.terminal(function(command, | ||
if (command == ' | if (command == ' | ||
- | term.echo(' | + | term.echo(' |
- | } | + | |
- | else if (command == 'load python' | + | |
- | if (typeof(pyodide) != ' | + | |
- | return; | + | |
- | + | ||
- | self.startTime = new Date(); | + | |
- | self.languagePluginUrl = '/ | + | |
- | $.ajax({ | + | |
- | url: self.languagePluginUrl + ' | + | |
- | async: false, | + | |
- | dataType: " | + | |
- | }); | + | |
- | $('< | + | |
- | rel: ' | + | |
- | }).appendTo(' | + | |
- | languagePluginLoader.then(() => { | + | |
- | term.echo(' | + | |
- | function pushCode(line) { | + | |
- | handleResult(c.push(line)) | + | |
- | } | + | |
- | self.endTime = new Date(); | + | |
- | var ms = self.endTime.getTime() | + | |
- | term.terminal( | + | |
- | pushCode, | + | |
- | { | + | |
- | greetings: " | + | |
- | " | + | |
- | prompt: " | + | |
- | } | + | |
- | ); | + | |
- | pyodide.runPython(` | + | |
- | import io, code, sys | + | |
- | from js import term, pyodide | + | |
- | + | ||
- | class Console(code.InteractiveConsole): | + | |
- | def runcode(self, | + | |
- | sys.stdout = io.StringIO() | + | |
- | sys.stderr = io.StringIO() | + | |
- | term.runPython(" | + | |
- | _c = Console(locals=globals()) | + | |
- | `) | + | |
- | + | ||
- | var c = pyodide.pyimport('_c') | + | |
- | + | ||
- | function handleResult(result) { | + | |
- | if (result) { | + | |
- | term.set_prompt(' | + | |
- | } else { | + | |
- | term.set_prompt(' | + | |
- | var stderr = pyodide.runPython(" | + | |
- | if (stderr) { | + | |
- | term.echo(`[[; | + | |
- | } else { | + | |
- | var stdout = pyodide.runPython(" | + | |
- | if (stdout) { | + | |
- | term.echo(stdout.trim()) | + | |
- | } | + | |
- | } | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | term.runPython = function(code) { | + | |
- | pyodide.runPythonAsync(code).then( | + | |
- | term.handlePythonResult, | + | |
- | ) | + | |
- | } | + | |
- | + | ||
- | term.handlePythonResult = function(result) { | + | |
- | if (result === undefined) { | + | |
- | return | + | |
- | } else if (result[' | + | |
- | term.echo(result[' | + | |
- | } else { | + | |
- | term.echo(result.toString()) | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | term.handlePythonError = function(result) { | + | |
- | term.error(result.toString()) | + | |
- | } | + | |
- | }); | + | |
} | } | ||
else if (command !== '' | else if (command !== '' | ||
行 114: | 行 25: | ||
navigator.userAgent, | navigator.userAgent, | ||
name: ' | name: ' | ||
- | height: | + | height: |
prompt: 'js > ' | prompt: 'js > ' | ||
}); | }); | ||
+ | | ||
function dir(object) { | function dir(object) { | ||
var result = ''; | var result = ''; |