This commit is contained in:
blueloveTH 2024-08-11 23:59:48 +08:00
parent 26c76960e9
commit 9d0d4d1841

View File

@ -1,4 +1,3 @@
<!-- <!--
Note: Note:
@ -30,6 +29,7 @@ DEALINGS IN THE SOFTWARE.
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
@ -41,136 +41,201 @@ DEALINGS IN THE SOFTWARE.
<link rel="stylesheet" href="static/highlight.js/github-dark-dimmed.min.css"> <link rel="stylesheet" href="static/highlight.js/github-dark-dimmed.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style> <style>
@import url("https://fonts.googleapis.com/css2?family=Lato:wght@300&family=PT+Mono&display=swap"); @import url("https://fonts.googleapis.com/css2?family=Lato:wght@300&family=PT+Mono&display=swap");
.hljs{display:block;overflow-x:auto;padding:.5em;background:#282a36} .hljs {
.hljs-keyword,.hljs-selector-tag,.hljs-literal,.hljs-section,.hljs-link{color:#73cbde} display: block;
.hljs,.hljs-subst{color:#f8f8f2} overflow-x: auto;
.hljs-string,.hljs-title,.hljs-name,.hljs-type,.hljs-attribute,.hljs-symbol, padding: .5em;
.hljs-bullet,.hljs-addition,.hljs-variable,.hljs-template-tag,.hljs-template-variable{color:#f1fa8c} background: #282a36
.hljs-comment,.hljs-quote,.hljs-deletion,.hljs-meta{color:#6272a4} }
.hljs-keyword,.hljs-selector-tag,.hljs-literal,.hljs-title,.hljs-section,.hljs-doctag,
.hljs-type,.hljs-name,.hljs-strong{font-weight:bold}.hljs-emphasis{font-style:italic}
:root { .hljs-keyword,
--window-width: 80%; .hljs-selector-tag,
} .hljs-literal,
.hljs-section,
.hljs-link {
color: #73cbde
}
body { .hljs,
background-color: #778abb; .hljs-subst {
font-family: Lato, sans-serif; color: #f8f8f2
font-weight: 300; }
font-size: 15px;
margin: 0; .hljs-string,
} .hljs-title,
*, .hljs-name,
*:before, .hljs-type,
*:after { .hljs-attribute,
box-sizing: border-box; .hljs-symbol,
} .hljs-bullet,
*:focus { .hljs-addition,
outline: none; .hljs-variable,
} .hljs-template-tag,
a, .hljs-template-variable {
a:visited, color: #f1fa8c
a:active { }
color: black;
} .hljs-comment,
main { .hljs-quote,
min-height: 100vh; .hljs-deletion,
display: flex; .hljs-meta {
align-items: center; color: #6272a4
flex-direction: column; }
}
.title { .hljs-keyword,
color: #fff; .hljs-selector-tag,
text-align: center; .hljs-literal,
font-weight: 300; .hljs-title,
font-size: 34px; .hljs-section,
margin-top: 20px; .hljs-doctag,
} .hljs-type,
.window { .hljs-name,
width: var(--window-width); .hljs-strong {
border-radius: 6px; font-weight: bold
box-shadow: 0 8px 12px rgba(0, 0, 0, 0.1); }
overflow: hidden;
margin-bottom: 20px; .hljs-emphasis {
} font-style: italic
.window .window-header { }
height: 25px;
background: Gainsboro; :root {
position: relative; --window-width: 80%;
} }
.window .window-header .action-buttons {
position: absolute; body {
top: 50%; background-color: #778abb;
left: 10px; font-family: Lato, sans-serif;
margin-top: -5px; font-weight: 300;
width: 10px; font-size: 15px;
height: 10px; margin: 0;
background: Crimson; }
border-radius: 50%;
box-shadow: 15px 0 0 Orange, 30px 0 0 LimeGreen; *,
} *:before,
#code-editor { *:after {
border-bottom-left-radius: 6px; box-sizing: border-box;
border-bottom-right-radius: 6px; }
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12),
0 3px 1px -2px rgba(0, 0, 0, 0.2); *:focus {
font-family: "PT Mono", monospace; outline: none;
font-size: 14px; }
font-weight: 400;
min-height: 300px; a,
letter-spacing: normal; a:visited,
line-height: 20px; a:active {
padding: 10px; color: black;
resize: none !important; }
tab-size: 4;
} main {
#run-button { min-height: 100vh;
padding-left: 10px; display: flex;
padding-right: 10px; align-items: center;
font-weight: bold; flex-direction: column;
cursor: pointer; }
}
#code-editor.hljs { .title {
padding: 10px; color: #fff;
} text-align: center;
#output-wrapper { font-weight: 300;
font-family: "PT Mono", monospace; font-size: 34px;
width: var(--window-width); margin-top: 20px;
min-height: 50px; }
background-color: #282a36;
border-radius: 6px; .window {
padding: 10px; width: var(--window-width);
color: white; border-radius: 6px;
margin:0 !important; box-shadow: 0 8px 12px rgba(0, 0, 0, 0.1);
} overflow: hidden;
#code-output span.error-line { margin-bottom: 20px;
color: #ec5424; }
}
.controls { .window .window-header {
font-size: 14px; height: 25px;
position: absolute; background: Gainsboro;
top: 50%; position: relative;
right: 10px; }
margin-top: -10px;
display: flex; .window .window-header .action-buttons {
} position: absolute;
.controls > div:first-child > a { top: 50%;
display: inline-block; left: 10px;
width: 40px; margin-top: -5px;
} width: 10px;
.features { height: 10px;
width: 547px; background: Crimson;
font-size: 16px; border-radius: 50%;
margin-bottom: 30px; box-shadow: 15px 0 0 Orange, 30px 0 0 LimeGreen;
} }
</style>
#code-editor {
border-bottom-left-radius: 6px;
border-bottom-right-radius: 6px;
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12),
0 3px 1px -2px rgba(0, 0, 0, 0.2);
font-family: "PT Mono", monospace;
font-size: 14px;
font-weight: 400;
min-height: 300px;
letter-spacing: normal;
line-height: 20px;
padding: 10px;
resize: none !important;
tab-size: 4;
}
#run-button {
padding-left: 10px;
padding-right: 10px;
font-weight: bold;
cursor: pointer;
}
#code-editor.hljs {
padding: 10px;
}
#output-wrapper {
font-family: "PT Mono", monospace;
width: var(--window-width);
min-height: 50px;
background-color: #282a36;
border-radius: 6px;
padding: 10px;
color: white;
margin: 0 !important;
}
#code-output span.error-line {
color: #ec5424;
}
.controls {
font-size: 14px;
position: absolute;
top: 50%;
right: 10px;
margin-top: -10px;
display: flex;
}
.controls>div:first-child>a {
display: inline-block;
width: 40px;
}
.features {
width: 547px;
font-size: 16px;
margin-bottom: 30px;
}
</style>
<title>Try Online</title> <title>Try Online</title>
</head> </head>
<body id="tryonline-body"> <body id="tryonline-body">
<main> <main>
@ -183,74 +248,62 @@ margin-bottom: 30px;
</div> </div>
</div> </div>
<div class="window-body"> <div class="window-body">
<div id="code-editor" class="language-python" data-gramm="false"># A recursive fibonacci function. <div id="code-editor" class="language-python" data-gramm="false"></div>
def fib(n):
if n &lt; 2:
return n
return fib(n-1) + fib(n-2)
# Prints all fibonacci from 0 to 10 exclusive.
for i in range(10):
print(f"fib({i}) = {fib(i)}")
</div>
</div> </div>
</div> </div>
<pre id="output-wrapper"><div id="code-output">...</div></pre> <pre id="output-wrapper"><div id="code-output">...</div></pre>
<br> <br>
</main> </main>
<script>
var Module = {
onRuntimeInitialized: function () {
Module.ccall('py_initialize', null, [], []);
},
print: function (text) {
console.log(text);
code_output.innerText += text + '\n';
},
onabort: function (what) {
code_output.innerText += 'Aborted: ' + what + '\n';
Module.ccall('py_finalize', null, [], []);
}
};
</script>
<script src="lib/pocketpy.js"></script>
<script>
let code_editor = document.querySelector('#code-editor');
let code_output = document.querySelector('#code-output');
let run_button = document.querySelector('#run-button');
<script> let highlight = withLineNumbers(function (editor) {
editor.textContent = editor.textContent;
hljs.highlightElement(editor);
});
let code_editor = document.querySelector('#code-editor'); highlight(code_editor);
let code_output = document.querySelector('#code-output');
let run_button = document.querySelector('#run-button');
let highlight = withLineNumbers(function(editor) { CodeJar(code_editor, highlight); //, { indentOn: /[(\[{:]$/});
editor.textContent = editor.textContent;
hljs.highlightElement(editor);
});
highlight(code_editor); code_editor.textContent = '# A recursive fibonacci function.\ndef fib(n):\n if n < 2:\n return n\n return fib(n-1) + fib(n-2)\n\n# Prints all fibonacci from 0 to 10 exclusive.\nfor i in range(10):\n print(f"fib({i}) = {fib(i)}")\n';
CodeJar(code_editor, highlight); //, { indentOn: /[(\[{:]$/}); window.onload = function () {
run_button.onclick = function () {
code_output.innerText = '';
var Module = { const source = code_editor.textContent;
onRuntimeInitialized: function() { var ok = Module.ccall(
Module.ccall('py_initialize', null, [], []); 'py_exec', 'boolean', ['string', 'string', 'number', 'number'],
}, [source, 'main.py', 0, 0]
print: function(text) { );
console.log(text); if (!ok) {
code_output.innerText += text + '\n'; Module.ccall('py_printexc', null, [], []);
}, Module.ccall('py_clearexc', null, ['number'], [0]);
onabort: function(what) { }
code_output.innerText += 'Aborted: ' + what + '\n'; }
Module.ccall('py_finalize', null, [], []);
}
};
window.onload = function() {
var script = document.createElement('script');
script.src = 'lib/pocketpy.js';
document.head.appendChild(script);
run_button.onclick = function() {
code_output.innerText = '';
const source = code_editor.textContent;
var ok = Module.ccall(
'py_exec', 'boolean', ['string', 'string', 'number', 'number'],
[source, 'main.py', 0, 0]
);
if (!ok) {
Module.ccall('py_printexc', null, [], []);
Module.ccall('py_clearexc', null, ['number'], [0]);
} }
}
}
</script> </script>
</body> </body>
</html> </html>