This repository has been archived by the owner on Jan 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
minimal_console.html
95 lines (93 loc) · 3.85 KB
/
minimal_console.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<html>
<head>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
<meta charset="utf-8">
<title>PyPy.js - minimal console</title>
<style>
button {
display:none;
}
pre, textarea {
width: 90%;
height: 35%;
margin: 1em;
padding: 1em;
}
pre {
border: 5px solid #ddd;
}
</style>
</head>
<body>
<h1>PyPy.js minimal console</h1>
<p>
This is only a minimal console!<br />
Only single string input works and only a few special keys are supported.<br />
A full featured console, that used <strong>jq-console</strong> is here: <a href="http://pypyjs.org">pypyjs.org</a>
</p>
<a href="https://github.com/jedie/pypyjs-examples"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/e7bbb0521b397edbd5fe43e7f760759336b5e05f/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677265656e5f3030373230302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_green_007200.png"></a>
<noscript><h3>Please enable JavaScript for using PyPy.js</h3></noscript>
<pre id="output"></pre>
<p>
PyPy.js is an experiment in building a fast and compliant python environment for the web.
<br/>
It uses the <a href="http://pypy.org/">PyPy</a> python interpreter, compiled for the web via
<a href="http://emscripten.org">emscripten</a>, with a custom JIT backend that emits <a href="http://asmjs.org">asm.js</a>
code at runtime.
</p>
</div>
<script src="pypyjs-release/lib/Promise.min.js" type="text/javascript" charset="utf-8" onerror="JavaScript:alert('Error loading file ['+this.src+'] !');"></script>
<script src="pypyjs-release/lib/FunctionPromise.js" type="text/javascript" charset="utf-8" onerror="JavaScript:alert('Error loading file ['+this.src+'] !');"></script>
<script src="pypyjs-release/lib/pypyjs.js" type="text/javascript" charset="utf-8" onerror="JavaScript:alert('Error loading file ['+this.src+'] !');"></script>
<script src="https://code.jquery.com/jquery-1.12.4.min.js" onerror="JavaScript:alert('Error loading file ['+this.src+'] !');"></script>
<script type="text/javascript" charset="utf-8">
try {
jQuery(document);
} catch (e) {
alert("Error, jQuery JS not loaded!\n Original error was:" + e);
}
function console_exec(code) {
console.log("exec: '" + code + "'");
pypyjs.exec(code).then(function() {
console.log("OK");
pypyjs.stdout("\n>>> ");
}, function (err) {
// err is an instance of PyPyJS.Error
console.log("ERROR: "+err.name+": "+err.message+"!)");
pypyjs.stderr(err.trace); // the human-readable traceback, as a string
});
}
$(document).ready(function() {
out = $("#output");
pypyjs.stdout = pypyjs.stderr = function(data) {
out.append(data);
}
pypyjs.stdout.reset = pypyjs.stderr.reset = function(data) {
out.empty();
}
pypyjs.stdout("loading PyPy.js...");
var pseudo_status = setInterval(function(){ pypyjs.stdout("."); }, 500);
pypyjs.ready().then(function() {
clearInterval(pseudo_status);
pypyjs.stdout.reset();
pypyjs.stdout('Welcome to PyPy.js!\n');
console_exec("import sys;print sys.version");
window.inputs="";
$(document).keypress(function( event ) {
console.log("keypress code: " + event.keyCode);
if (event.keyCode==27) {
window.inputs="";
pypyjs.stdout.reset();
} else if (event.keyCode==13) {
console_exec(window.inputs+"\n");
window.inputs="";
} else {
window.inputs += event.key;
pypyjs.stdout(event.key);
}
});
});
});
</script>
</body>
</html>