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,
.hljs-selector-tag,
.hljs-literal,
.hljs-section,
.hljs-link {
color: #73cbde
}
.hljs,
.hljs-subst {
color: #f8f8f2
}
.hljs-string,
.hljs-title,
.hljs-name,
.hljs-type,
.hljs-attribute,
.hljs-symbol,
.hljs-bullet,
.hljs-addition,
.hljs-variable,
.hljs-template-tag,
.hljs-template-variable {
color: #f1fa8c
}
.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 {
--window-width: 80%; --window-width: 80%;
} }
body { body {
background-color: #778abb; background-color: #778abb;
font-family: Lato, sans-serif; font-family: Lato, sans-serif;
font-weight: 300; font-weight: 300;
font-size: 15px; font-size: 15px;
margin: 0; margin: 0;
} }
*,
*:before, *,
*:after { *:before,
box-sizing: border-box; *:after {
} box-sizing: border-box;
*:focus { }
*:focus {
outline: none; outline: none;
} }
a,
a:visited, a,
a:active { a:visited,
color: black; a:active {
} color: black;
main { }
min-height: 100vh;
display: flex; main {
align-items: center; min-height: 100vh;
flex-direction: column; display: flex;
} align-items: center;
.title { flex-direction: column;
color: #fff; }
text-align: center;
font-weight: 300; .title {
font-size: 34px; color: #fff;
margin-top: 20px; text-align: center;
} font-weight: 300;
.window { font-size: 34px;
width: var(--window-width); margin-top: 20px;
border-radius: 6px; }
box-shadow: 0 8px 12px rgba(0, 0, 0, 0.1);
overflow: hidden; .window {
margin-bottom: 20px; width: var(--window-width);
} border-radius: 6px;
.window .window-header { box-shadow: 0 8px 12px rgba(0, 0, 0, 0.1);
height: 25px; overflow: hidden;
background: Gainsboro; margin-bottom: 20px;
position: relative; }
}
.window .window-header .action-buttons { .window .window-header {
position: absolute; height: 25px;
top: 50%; background: Gainsboro;
left: 10px; position: relative;
margin-top: -5px; }
width: 10px;
height: 10px; .window .window-header .action-buttons {
background: Crimson; position: absolute;
border-radius: 50%; top: 50%;
box-shadow: 15px 0 0 Orange, 30px 0 0 LimeGreen; left: 10px;
} margin-top: -5px;
#code-editor { width: 10px;
border-bottom-left-radius: 6px; height: 10px;
border-bottom-right-radius: 6px; background: Crimson;
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12), border-radius: 50%;
box-shadow: 15px 0 0 Orange, 30px 0 0 LimeGreen;
}
#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); 0 3px 1px -2px rgba(0, 0, 0, 0.2);
font-family: "PT Mono", monospace; font-family: "PT Mono", monospace;
font-size: 14px; font-size: 14px;
font-weight: 400; font-weight: 400;
min-height: 300px; min-height: 300px;
letter-spacing: normal; letter-spacing: normal;
line-height: 20px; line-height: 20px;
padding: 10px; padding: 10px;
resize: none !important; resize: none !important;
tab-size: 4; tab-size: 4;
} }
#run-button {
#run-button {
padding-left: 10px; padding-left: 10px;
padding-right: 10px; padding-right: 10px;
font-weight: bold; font-weight: bold;
cursor: pointer; cursor: pointer;
} }
#code-editor.hljs {
padding: 10px; #code-editor.hljs {
} padding: 10px;
#output-wrapper { }
font-family: "PT Mono", monospace;
width: var(--window-width); #output-wrapper {
min-height: 50px; font-family: "PT Mono", monospace;
background-color: #282a36; width: var(--window-width);
border-radius: 6px; min-height: 50px;
padding: 10px; background-color: #282a36;
color: white; border-radius: 6px;
margin:0 !important; padding: 10px;
} color: white;
#code-output span.error-line { margin: 0 !important;
color: #ec5424; }
}
.controls { #code-output span.error-line {
font-size: 14px; color: #ec5424;
position: absolute; }
top: 50%;
right: 10px; .controls {
margin-top: -10px; font-size: 14px;
display: flex; position: absolute;
} top: 50%;
.controls > div:first-child > a { right: 10px;
display: inline-block; margin-top: -10px;
width: 40px; display: flex;
} }
.features {
width: 547px; .controls>div:first-child>a {
font-size: 16px; display: inline-block;
margin-bottom: 30px; width: 40px;
} }
</style>
.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,60 +248,47 @@ 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>
<script> var Module = {
onRuntimeInitialized: function () {
let code_editor = document.querySelector('#code-editor');
let code_output = document.querySelector('#code-output');
let run_button = document.querySelector('#run-button');
let highlight = withLineNumbers(function(editor) {
editor.textContent = editor.textContent;
hljs.highlightElement(editor);
});
highlight(code_editor);
CodeJar(code_editor, highlight); //, { indentOn: /[(\[{:]$/});
var Module = {
onRuntimeInitialized: function() {
Module.ccall('py_initialize', null, [], []); Module.ccall('py_initialize', null, [], []);
}, },
print: function(text) { print: function (text) {
console.log(text); console.log(text);
code_output.innerText += text + '\n'; code_output.innerText += text + '\n';
}, },
onabort: function(what) { onabort: function (what) {
code_output.innerText += 'Aborted: ' + what + '\n'; code_output.innerText += 'Aborted: ' + what + '\n';
Module.ccall('py_finalize', null, [], []); 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');
window.onload = function() { let highlight = withLineNumbers(function (editor) {
var script = document.createElement('script'); editor.textContent = editor.textContent;
script.src = 'lib/pocketpy.js'; hljs.highlightElement(editor);
document.head.appendChild(script); });
run_button.onclick = function() { highlight(code_editor);
CodeJar(code_editor, highlight); //, { indentOn: /[(\[{:]$/});
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';
window.onload = function () {
run_button.onclick = function () {
code_output.innerText = ''; code_output.innerText = '';
const source = code_editor.textContent; const source = code_editor.textContent;
var ok = Module.ccall( var ok = Module.ccall(
@ -248,9 +300,10 @@ window.onload = function() {
Module.ccall('py_clearexc', null, ['number'], [0]); Module.ccall('py_clearexc', null, ['number'], [0]);
} }
} }
} }
</script> </script>
</body> </body>
</html> </html>