差分
このページの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>< | ||
- | <script async src="// | ||
- | < | ||
- | | ||
- | google_ad_client: | ||
- | enable_page_level_ads: | ||
- | }); | ||
- | </ | ||
< | < | ||
- | <script src="https:// | + | <script src="/ |
- | <link href="https:// | + | <link href="/ |
< | < | ||
jQuery(function($, | jQuery(function($, | ||
term = $('# | term = $('# | ||
- | term.terminal(function(command) { | + | term.terminal(function(command, term) { |
- | if (command !== '' | + | |
+ | 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() - self.startTime.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(' | ||
+ | |||
+ | 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 !== '' | ||
try { | try { | ||
var result = window.eval(command); | var result = window.eval(command); | ||
行 27: | 行 103: | ||
} | } | ||
}, { | }, { | ||
- | greetings: ' | + | greetings: ' |
+ | navigator.userAgent, | ||
name: ' | name: ' | ||
height: 200, | height: 200, | ||
- | prompt: ' | + | prompt: 'js > ' |
}); | }); | ||
function dir(object) { | function dir(object) { | ||
行 65: | 行 142: | ||
Copyright (c) 2011-2019 Jakub T. Jankiewicz < | Copyright (c) 2011-2019 Jakub T. Jankiewicz < | ||
+ | js > help | ||
+ | load python - Python Interpreter | ||
js > | js > | ||
</ | </ | ||
</ | </ | ||
- |