Explorar o código

update web

Update main.yml

Update main.yml
blueloveTH %!s(int64=3) %!d(string=hai) anos
pai
achega
7c26af33b5
Modificáronse 7 ficheiros con 281 adicións e 4 borrados
  1. 17 1
      .github/workflows/main.yml
  2. 3 3
      build_wasm.sh
  3. 13 0
      web/index.html
  4. 56 0
      web/index.js
  5. 192 0
      web/xterm/xterm.css
  6. 0 0
      web/xterm/xterm.js
  7. 0 0
      web/xterm/xterm.js.map

+ 17 - 1
.github/workflows/main.yml

@@ -17,4 +17,20 @@ jobs:
         name: pocketpy
         name: pocketpy
         path: |
         path: |
           D:\a\pocketpy\pocketpy\pocketpy.exe
           D:\a\pocketpy\pocketpy\pocketpy.exe
-          D:\a\pocketpy\pocketpy\libpocketpy.dll
+          D:\a\pocketpy\pocketpy\libpocketpy.dll
+  build_web:
+    runs-on: ubuntu-latest
+    steps:
+    - uses: actions/checkout@v2
+    - uses: mymindstorm/setup-emsdk@v11
+      with:
+        emsdk-version: 3.1.25
+    - name: Compiling
+      run: |
+        bash build_wasm.sh
+    - uses: crazy-max/ghaction-github-pages@v3
+      with:
+        target_branch: gh-pages
+        build_dir: web
+      env:
+        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

+ 3 - 3
build_wasm.sh

@@ -1,3 +1,3 @@
-rm -rf build/wasm/
-mkdir -p build/wasm/
-emcc src/main.cpp -fexceptions -sEXIT_RUNTIME -sEXPORTED_FUNCTIONS=_repl_input,_repl_start -sEXPORTED_RUNTIME_METHODS=ccall -o build/wasm/pocketpy.js
+rm -rf web/lib/
+mkdir -p web/lib/
+emcc src/main.cpp -fexceptions -sEXIT_RUNTIME -O2 -sEXPORTED_FUNCTIONS=_repl_input,_repl_start -sEXPORTED_RUNTIME_METHODS=ccall -o web/lib/pocketpy.js

+ 13 - 0
web/index.html

@@ -0,0 +1,13 @@
+<!doctype html>
+  <html>
+    <head>
+      <link rel="stylesheet" href="xterm/xterm.css" />
+      <script src="xterm/xterm.js"></script>
+      <script src="index.js" ></script>
+    </head>
+    <body>
+      <div id="terminal"></div>
+      <script>term_init();</script>
+      <script src="./lib/pocketpy.js"></script>
+    </body>
+  </html>

+ 56 - 0
web/index.js

@@ -0,0 +1,56 @@
+const term = new Terminal();
+
+var command = "";
+var need_more_lines = false;
+var stopped = false;
+
+var Module = {
+    'print': function(text) { 
+      term.write(text + "\r\n");
+    },
+    'printErr': function(text) {
+      term.write(text + "\r\n");
+    },
+    'onRuntimeInitialized': function(text) { 
+      Module.ccall('repl_start', null, [], []);
+      term.write(need_more_lines ? "... " : ">>> ");
+    },
+    'onAbort': function(text) { 
+      stopped = true;
+      term.write("Aborted\r\n");
+    },
+  };
+
+function term_init() {
+    term.open(document.getElementById('terminal'));
+    term.onData(e => {
+      if (stopped) return;
+      switch (e) {
+        case '\r': // Enter
+          term.write("\r\n");
+          if(command == 'exit()'){
+            stopped = true;
+            term.write("Bye!\r\n");
+            break;
+          }
+          need_more_lines = Module.ccall('repl_input', Boolean, ['string'], [command]);
+          command = '';
+          term.write(need_more_lines ? "... " : ">>> ");
+          break;
+        case '\u007F': // Backspace (DEL)
+          // Do not delete the prompt
+          if (term._core.buffer.x > 4) {    // '>>> ' or '... '
+            term.write('\b \b');
+            if (command.length > 0) {
+              command = command.substr(0, command.length - 1);
+            }
+          }
+          break;
+        default: // Print all other characters for demo
+          if (e >= String.fromCharCode(0x20) && e <= String.fromCharCode(0x7E) || e >= '\u00a0') {
+            command += e;
+            term.write(e);
+          }
+      }
+    });
+}

+ 192 - 0
web/xterm/xterm.css

@@ -0,0 +1,192 @@
+/**
+ * Copyright (c) 2014 The xterm.js authors. All rights reserved.
+ * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
+ * https://github.com/chjj/term.js
+ * @license MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Originally forked from (with the author's permission):
+ *   Fabrice Bellard's javascript vt100 for jslinux:
+ *   http://bellard.org/jslinux/
+ *   Copyright (c) 2011 Fabrice Bellard
+ *   The original design remains. The terminal itself
+ *   has been extended to include xterm CSI codes, among
+ *   other features.
+ */
+
+/**
+ *  Default styles for xterm.js
+ */
+
+.xterm {
+    cursor: text;
+    position: relative;
+    user-select: none;
+    -ms-user-select: none;
+    -webkit-user-select: none;
+}
+
+.xterm.focus,
+.xterm:focus {
+    outline: none;
+}
+
+.xterm .xterm-helpers {
+    position: absolute;
+    top: 0;
+    /**
+     * The z-index of the helpers must be higher than the canvases in order for
+     * IMEs to appear on top.
+     */
+    z-index: 5;
+}
+
+.xterm .xterm-helper-textarea {
+    padding: 0;
+    border: 0;
+    margin: 0;
+    /* Move textarea out of the screen to the far left, so that the cursor is not visible */
+    position: absolute;
+    opacity: 0;
+    left: -9999em;
+    top: 0;
+    width: 0;
+    height: 0;
+    z-index: -5;
+    /** Prevent wrapping so the IME appears against the textarea at the correct position */
+    white-space: nowrap;
+    overflow: hidden;
+    resize: none;
+}
+
+.xterm .composition-view {
+    /* TODO: Composition position got messed up somewhere */
+    background: #000;
+    color: #FFF;
+    display: none;
+    position: absolute;
+    white-space: nowrap;
+    z-index: 1;
+}
+
+.xterm .composition-view.active {
+    display: block;
+}
+
+.xterm .xterm-viewport {
+    /* On OS X this is required in order for the scroll bar to appear fully opaque */
+    background-color: #000;
+    overflow-y: scroll;
+    cursor: default;
+    position: absolute;
+    right: 0;
+    left: 0;
+    top: 0;
+    bottom: 0;
+}
+
+.xterm .xterm-screen {
+    position: relative;
+}
+
+.xterm .xterm-screen canvas {
+    position: absolute;
+    left: 0;
+    top: 0;
+}
+
+.xterm .xterm-scroll-area {
+    visibility: hidden;
+}
+
+.xterm-char-measure-element {
+    display: inline-block;
+    visibility: hidden;
+    position: absolute;
+    top: 0;
+    left: -9999em;
+    line-height: normal;
+}
+
+.xterm.enable-mouse-events {
+    /* When mouse events are enabled (eg. tmux), revert to the standard pointer cursor */
+    cursor: default;
+}
+
+.xterm.xterm-cursor-pointer,
+.xterm .xterm-cursor-pointer {
+    cursor: pointer;
+}
+
+.xterm.column-select.focus {
+    /* Column selection mode */
+    cursor: crosshair;
+}
+
+.xterm .xterm-accessibility,
+.xterm .xterm-message {
+    position: absolute;
+    left: 0;
+    top: 0;
+    bottom: 0;
+    right: 0;
+    z-index: 10;
+    color: transparent;
+}
+
+.xterm .live-region {
+    position: absolute;
+    left: -9999px;
+    width: 1px;
+    height: 1px;
+    overflow: hidden;
+}
+
+.xterm-dim {
+    opacity: 0.5;
+}
+
+.xterm-underline-1 { text-decoration: underline; }
+.xterm-underline-2 { text-decoration: double underline; }
+.xterm-underline-3 { text-decoration: wavy underline; }
+.xterm-underline-4 { text-decoration: dotted underline; }
+.xterm-underline-5 { text-decoration: dashed underline; }
+
+.xterm-strikethrough {
+    text-decoration: line-through;
+}
+
+.xterm-screen .xterm-decoration-container .xterm-decoration {
+	z-index: 6;
+	position: absolute;
+}
+
+.xterm-decoration-overview-ruler {
+    z-index: 7;
+    position: absolute;
+    top: 0;
+    right: 0;
+    pointer-events: none;
+}
+
+.xterm-decoration-top {
+    z-index: 2;
+    position: relative;
+}

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
web/xterm/xterm.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
web/xterm/xterm.js.map


Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio