| 1 |
<!-- |
| 2 |
|
| 3 |
Note: |
| 4 |
This site was created by modifying code pen https://codepen.io/antonmedv/pen/PoPoGwg |
| 5 |
written by 'Anton Medvedev' the license can be found bellow. |
| 6 |
|
| 7 |
LICENSE |
| 8 |
------- |
| 9 |
Copyright (c) 2022 by Anton Medvedev (https://codepen.io/antonmedv/pen/PoPoGwg) |
| 10 |
|
| 11 |
Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 12 |
this software and associated documentation files (the "Software"), to deal in |
| 13 |
the Software without restriction, including without limitation the rights to |
| 14 |
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 15 |
of the Software, and to permit persons to whom the Software is furnished to do |
| 16 |
so, subject to the following conditions: |
| 17 |
|
| 18 |
The above copyright notice and this permission notice shall be included in |
| 19 |
all copies or substantial portions of the Software. |
| 20 |
|
| 21 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 26 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 27 |
DEALINGS IN THE SOFTWARE. |
| 28 |
--> |
| 29 |
|
| 30 |
<!DOCTYPE html> |
| 31 |
<html lang="en"> |
| 32 |
|
| 33 |
<head> |
| 34 |
<meta charset="UTF-8"> |
| 35 |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| 36 |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 37 |
|
| 38 |
<script src="static/codejar/codejar.js"></script> |
| 39 |
<script src="static/codejar/linenumbers.js"></script> |
| 40 |
<script src="static/highlight.js/highlight.min.js"></script> |
| 41 |
<link rel="stylesheet" href="static/highlight.js/github-dark-dimmed.min.css"> |
| 42 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> |
| 43 |
|
| 44 |
<style> |
| 45 |
@import url("https://fonts.googleapis.com/css2?family=Lato:wght@300&family=PT+Mono&display=swap"); |
| 46 |
|
| 47 |
.hljs { |
| 48 |
display: block; |
| 49 |
overflow-x: auto; |
| 50 |
padding: .5em; |
| 51 |
background: #282a36 |
| 52 |
} |
| 53 |
|
| 54 |
.hljs-keyword, |
| 55 |
.hljs-selector-tag, |
| 56 |
.hljs-literal, |
| 57 |
.hljs-section, |
| 58 |
.hljs-link { |
| 59 |
color: #73cbde |
| 60 |
} |
| 61 |
|
| 62 |
.hljs, |
| 63 |
.hljs-subst { |
| 64 |
color: #f8f8f2 |
| 65 |
} |
| 66 |
|
| 67 |
.hljs-string, |
| 68 |
.hljs-title, |
| 69 |
.hljs-name, |
| 70 |
.hljs-type, |
| 71 |
.hljs-attribute, |
| 72 |
.hljs-symbol, |
| 73 |
.hljs-bullet, |
| 74 |
.hljs-addition, |
| 75 |
.hljs-variable, |
| 76 |
.hljs-template-tag, |
| 77 |
.hljs-template-variable { |
| 78 |
color: #f1fa8c |
| 79 |
} |
| 80 |
|
| 81 |
.hljs-comment, |
| 82 |
.hljs-quote, |
| 83 |
.hljs-deletion, |
| 84 |
.hljs-meta { |
| 85 |
color: #6272a4 |
| 86 |
} |
| 87 |
|
| 88 |
.hljs-keyword, |
| 89 |
.hljs-selector-tag, |
| 90 |
.hljs-literal, |
| 91 |
.hljs-title, |
| 92 |
.hljs-section, |
| 93 |
.hljs-doctag, |
| 94 |
.hljs-type, |
| 95 |
.hljs-name, |
| 96 |
.hljs-strong { |
| 97 |
font-weight: bold |
| 98 |
} |
| 99 |
|
| 100 |
.hljs-emphasis { |
| 101 |
font-style: italic |
| 102 |
} |
| 103 |
|
| 104 |
:root { |
| 105 |
--window-width: 80%; |
| 106 |
} |
| 107 |
|
| 108 |
body { |
| 109 |
background-color: #778abb; |
| 110 |
font-family: Lato, sans-serif; |
| 111 |
font-weight: 300; |
| 112 |
font-size: 15px; |
| 113 |
margin: 0; |
| 114 |
} |
| 115 |
|
| 116 |
*, |
| 117 |
*:before, |
| 118 |
*:after { |
| 119 |
box-sizing: border-box; |
| 120 |
} |
| 121 |
|
| 122 |
*:focus { |
| 123 |
outline: none; |
| 124 |
} |
| 125 |
|
| 126 |
a, |
| 127 |
a:visited, |
| 128 |
a:active { |
| 129 |
color: black; |
| 130 |
} |
| 131 |
|
| 132 |
main { |
| 133 |
min-height: 100vh; |
| 134 |
display: flex; |
| 135 |
align-items: center; |
| 136 |
flex-direction: column; |
| 137 |
} |
| 138 |
|
| 139 |
.title { |
| 140 |
color: #fff; |
| 141 |
text-align: center; |
| 142 |
font-weight: 300; |
| 143 |
font-size: 34px; |
| 144 |
margin-top: 20px; |
| 145 |
} |
| 146 |
|
| 147 |
.window { |
| 148 |
width: var(--window-width); |
| 149 |
border-radius: 6px; |
| 150 |
box-shadow: 0 8px 12px rgba(0, 0, 0, 0.1); |
| 151 |
overflow: hidden; |
| 152 |
margin-bottom: 20px; |
| 153 |
} |
| 154 |
|
| 155 |
.window .window-header { |
| 156 |
height: 25px; |
| 157 |
background: Gainsboro; |
| 158 |
position: relative; |
| 159 |
} |
| 160 |
|
| 161 |
.window .window-header .action-buttons { |
| 162 |
position: absolute; |
| 163 |
top: 50%; |
| 164 |
left: 10px; |
| 165 |
margin-top: -5px; |
| 166 |
width: 10px; |
| 167 |
height: 10px; |
| 168 |
background: Crimson; |
| 169 |
border-radius: 50%; |
| 170 |
box-shadow: 15px 0 0 Orange, 30px 0 0 LimeGreen; |
| 171 |
} |
| 172 |
|
| 173 |
#code-editor { |
| 174 |
border-bottom-left-radius: 6px; |
| 175 |
border-bottom-right-radius: 6px; |
| 176 |
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12), |
| 177 |
0 3px 1px -2px rgba(0, 0, 0, 0.2); |
| 178 |
font-family: "PT Mono", monospace; |
| 179 |
font-size: 14px; |
| 180 |
font-weight: 400; |
| 181 |
min-height: 300px; |
| 182 |
letter-spacing: normal; |
| 183 |
line-height: 20px; |
| 184 |
padding: 10px; |
| 185 |
resize: none !important; |
| 186 |
tab-size: 4; |
| 187 |
} |
| 188 |
|
| 189 |
#run-button { |
| 190 |
padding-left: 20px; |
| 191 |
padding-right: 20px; |
| 192 |
padding-bottom: 1px; |
| 193 |
font-weight: bold; |
| 194 |
cursor: pointer; |
| 195 |
background-color: #007bff; |
| 196 |
color: #ffffff; |
| 197 |
border: none; |
| 198 |
border-radius: 4px; |
| 199 |
outline: none; |
| 200 |
user-select: none; |
| 201 |
} |
| 202 |
#run-button:hover, |
| 203 |
#run-button:focus { |
| 204 |
background-color: #0056b3; |
| 205 |
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); |
| 206 |
} |
| 207 |
#run-button:active { |
| 208 |
background-color: #004085; |
| 209 |
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1); |
| 210 |
transform: translateY(1px); |
| 211 |
} |
| 212 |
|
| 213 |
#code-editor.hljs { |
| 214 |
padding: 10px; |
| 215 |
} |
| 216 |
|
| 217 |
#output-wrapper { |
| 218 |
font-family: "PT Mono", monospace; |
| 219 |
width: var(--window-width); |
| 220 |
min-height: 50px; |
| 221 |
background-color: #282a36; |
| 222 |
border-radius: 6px; |
| 223 |
padding: 10px; |
| 224 |
color: white; |
| 225 |
margin: 0 !important; |
| 226 |
} |
| 227 |
|
| 228 |
#code-output span.error-line { |
| 229 |
color: #ec5424; |
| 230 |
} |
| 231 |
|
| 232 |
.controls { |
| 233 |
font-size: 14px; |
| 234 |
position: absolute; |
| 235 |
top: 50%; |
| 236 |
right: 10px; |
| 237 |
margin-top: -10px; |
| 238 |
display: flex; |
| 239 |
} |
| 240 |
|
| 241 |
.controls>div:first-child>a { |
| 242 |
display: inline-block; |
| 243 |
width: 40px; |
| 244 |
} |
| 245 |
|
| 246 |
.features { |
| 247 |
width: 547px; |
| 248 |
font-size: 16px; |
| 249 |
margin-bottom: 30px; |
| 250 |
} |
| 251 |
</style> |
| 252 |
|
| 253 |
<title>Try Online</title> |
| 254 |
</head> |
| 255 |
|
| 256 |
<body id="tryonline-body"> |
| 257 |
|
| 258 |
<main> |
| 259 |
<br> |
| 260 |
<div class="window"> |
| 261 |
<div class="window-header"> |
| 262 |
<div class="action-buttons"></div> |
| 263 |
<div class="controls"> |
| 264 |
<div id="run-button">Run</div> |
| 265 |
</div> |
| 266 |
</div> |
| 267 |
<div class="window-body"> |
| 268 |
<div id="code-editor" class="language-python" data-gramm="false"></div> |
| 269 |
</div> |
| 270 |
</div> |
| 271 |
<pre id="output-wrapper"><div id="code-output">...</div></pre> |
| 272 |
<br> |
| 273 |
</main> |
| 274 |
|
| 275 |
<script> |
| 276 |
var Module = { |
| 277 |
onRuntimeInitialized: function () { |
| 278 |
Module.ccall('py_initialize', null, [], []); |
| 279 |
console.log("py_initialize() called"); |
| 280 |
}, |
| 281 |
print: function (text) { |
| 282 |
code_output.innerText += text + '\n'; |
| 283 |
}, |
| 284 |
onabort: function (what) { |
| 285 |
code_output.innerText += 'Aborted: ' + what + '\n'; |
| 286 |
Module.ccall('py_finalize', null, [], []); |
| 287 |
console.log("py_finalize() called"); |
| 288 |
} |
| 289 |
}; |
| 290 |
</script> |
| 291 |
<script src="lib/pocketpy.js"></script> |
| 292 |
<script> |
| 293 |
let code_editor = document.querySelector('#code-editor'); |
| 294 |
let code_output = document.querySelector('#code-output'); |
| 295 |
let run_button = document.querySelector('#run-button'); |
| 296 |
|
| 297 |
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'; |
| 298 |
|
| 299 |
let highlight = withLineNumbers(function (editor) { |
| 300 |
editor.textContent = editor.textContent; |
| 301 |
hljs.highlightElement(editor); |
| 302 |
}); |
| 303 |
|
| 304 |
highlight(code_editor); |
| 305 |
CodeJar(code_editor, highlight); //, { indentOn: /[(\[{:]$/}); |
| 306 |
|
| 307 |
window.onload = function () { |
| 308 |
run_button.onclick = function () { |
| 309 |
code_output.innerText = ''; |
| 310 |
const source = code_editor.textContent; |
| 311 |
var ok = Module.ccall( |
| 312 |
'py_exec', 'boolean', ['string', 'string', 'number', 'number'], |
| 313 |
[source, 'main.py', 0, 0] |
| 314 |
); |
| 315 |
console.log("py_exec() called"); |
| 316 |
if (!ok) { |
| 317 |
Module.ccall('py_printexc', null, [], []); |
| 318 |
Module.ccall('py_clearexc', null, ['number'], [0]); |
| 319 |
} |
| 320 |
} |
| 321 |
} |
| 322 |
|
| 323 |
</script> |
| 324 |
|
| 325 |
</body> |
| 326 |
|
| 327 |
</html> |