index.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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{display:block;overflow-x:auto;padding:.5em;background:#282a36}
  38. .hljs-keyword,.hljs-selector-tag,.hljs-literal,.hljs-section,.hljs-link{color:#73cbde}
  39. .hljs,.hljs-subst{color:#f8f8f2}
  40. .hljs-string,.hljs-title,.hljs-name,.hljs-type,.hljs-attribute,.hljs-symbol,
  41. .hljs-bullet,.hljs-addition,.hljs-variable,.hljs-template-tag,.hljs-template-variable{color:#f1fa8c}
  42. .hljs-comment,.hljs-quote,.hljs-deletion,.hljs-meta{color:#6272a4}
  43. .hljs-keyword,.hljs-selector-tag,.hljs-literal,.hljs-title,.hljs-section,.hljs-doctag,
  44. .hljs-type,.hljs-name,.hljs-strong{font-weight:bold}.hljs-emphasis{font-style:italic}
  45. :root {
  46. --window-width: 80%;
  47. }
  48. body {
  49. background-color: #778abb;
  50. font-family: Lato, sans-serif;
  51. font-weight: 300;
  52. font-size: 15px;
  53. margin: 0;
  54. }
  55. *,
  56. *:before,
  57. *:after {
  58. box-sizing: border-box;
  59. }
  60. *:focus {
  61. outline: none;
  62. }
  63. a,
  64. a:visited,
  65. a:active {
  66. color: black;
  67. }
  68. main {
  69. min-height: 100vh;
  70. display: flex;
  71. align-items: center;
  72. flex-direction: column;
  73. }
  74. .title {
  75. color: #fff;
  76. text-align: center;
  77. font-weight: 300;
  78. font-size: 34px;
  79. margin-top: 20px;
  80. }
  81. .window {
  82. width: var(--window-width);
  83. border-radius: 6px;
  84. box-shadow: 0 8px 12px rgba(0, 0, 0, 0.1);
  85. overflow: hidden;
  86. margin-bottom: 20px;
  87. }
  88. .window .window-header {
  89. height: 25px;
  90. background: Gainsboro;
  91. position: relative;
  92. }
  93. .window .window-header .action-buttons {
  94. position: absolute;
  95. top: 50%;
  96. left: 10px;
  97. margin-top: -5px;
  98. width: 10px;
  99. height: 10px;
  100. background: Crimson;
  101. border-radius: 50%;
  102. box-shadow: 15px 0 0 Orange, 30px 0 0 LimeGreen;
  103. }
  104. #code-editor {
  105. border-bottom-left-radius: 6px;
  106. border-bottom-right-radius: 6px;
  107. box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12),
  108. 0 3px 1px -2px rgba(0, 0, 0, 0.2);
  109. font-family: "PT Mono", monospace;
  110. font-size: 14px;
  111. font-weight: 400;
  112. min-height: 300px;
  113. letter-spacing: normal;
  114. line-height: 20px;
  115. padding: 10px;
  116. resize: none !important;
  117. tab-size: 4;
  118. }
  119. #run-button {
  120. padding-left: 10px;
  121. padding-right: 10px;
  122. font-weight: bold;
  123. cursor: pointer;
  124. }
  125. #code-editor.hljs {
  126. padding: 10px;
  127. }
  128. #output-wrapper {
  129. font-family: "PT Mono", monospace;
  130. width: var(--window-width);
  131. min-height: 50px;
  132. background-color: #282a36;
  133. border-radius: 6px;
  134. padding: 10px;
  135. color: white;
  136. margin:0 !important;
  137. }
  138. #code-output span.error-line {
  139. color: #ec5424;
  140. }
  141. .controls {
  142. font-size: 14px;
  143. position: absolute;
  144. top: 50%;
  145. right: 10px;
  146. margin-top: -10px;
  147. display: flex;
  148. }
  149. .controls > div:first-child > a {
  150. display: inline-block;
  151. width: 40px;
  152. }
  153. .features {
  154. width: 547px;
  155. font-size: 16px;
  156. margin-bottom: 30px;
  157. }
  158. </style>
  159. <title>Try Online</title>
  160. </head>
  161. <body id="tryonline-body">
  162. <main>
  163. <br>
  164. <div class="window">
  165. <div class="window-header">
  166. <div class="action-buttons"></div>
  167. <div class="controls">
  168. <div id="run-button">Run</div>
  169. </div>
  170. </div>
  171. <div class="window-body">
  172. <div id="code-editor" class="language-python" data-gramm="false"># A recursive fibonacci function.
  173. def fib(n):
  174. if n &lt; 2:
  175. return n
  176. return fib(n-1) + fib(n-2)
  177. # Prints all fibonacci from 0 to 10 exclusive.
  178. for i in range(10):
  179. print(f"fib({i}) = {fib(i)}")
  180. </div>
  181. </div>
  182. </div>
  183. <pre id="output-wrapper"><div id="code-output">...</div></pre>
  184. <br>
  185. </main>
  186. <script>
  187. let code_editor = document.querySelector('#code-editor');
  188. let code_output = document.querySelector('#code-output');
  189. let run_button = document.querySelector('#run-button');
  190. let highlight = withLineNumbers(function(editor) {
  191. editor.textContent = editor.textContent;
  192. hljs.highlightElement(editor);
  193. });
  194. highlight(code_editor);
  195. CodeJar(code_editor, highlight); //, { indentOn: /[(\[{:]$/});
  196. var Module = {
  197. onRuntimeInitialized: function() {
  198. Module.ccall('py_initialize', null, [], []);
  199. },
  200. print: function(text) {
  201. console.log(text);
  202. code_output.innerText += text + '\n';
  203. },
  204. onabort: function(what) {
  205. code_output.innerText += 'Aborted: ' + what + '\n';
  206. Module.ccall('py_finalize', null, [], []);
  207. }
  208. };
  209. window.onload = function() {
  210. var script = document.createElement('script');
  211. script.src = 'lib/pocketpy.js';
  212. document.head.appendChild(script);
  213. run_button.onclick = function() {
  214. code_output.innerText = '';
  215. const source = code_editor.textContent;
  216. var ok = Module.ccall(
  217. 'py_exec', 'boolean', ['string', 'string', 'number', 'number'],
  218. [source, 'main.py', 0, 0]
  219. );
  220. if (!ok) {
  221. Module.ccall('py_printexc', null, [], []);
  222. Module.ccall('py_clearexc', null, ['number'], [0]);
  223. }
  224. }
  225. }
  226. </script>
  227. </body>
  228. </html>