1
0

index.html 7.9 KB

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