Browse Source

Added a few new options for Readline

Aleksi Talarmo 4 years ago
parent
commit
71a7878763
7 changed files with 30 additions and 5 deletions
  1. BIN
      audio/battle_music.ogg
  2. BIN
      audio/clang01.ogg
  3. 5
    3
      scss/custom.scss
  4. 15
    1
      ts/jash.ts
  5. 1
    0
      ts/main.ts
  6. 3
    0
      ts/std.ts
  7. 6
    1
      ts/testprogram.ts

BIN
audio/battle_music.ogg View File


BIN
audio/clang01.ogg View File


+ 5
- 3
scss/custom.scss View File

@@ -25,10 +25,12 @@ h1, p {
25 25
    /* bring your own prefixes */
26 26
    transform: translate(-50%, -50%);
27 27
 
28
-   background-color: #202020;
29
-   color: #cecece;
30
-
31 28
    font-size: 15px;
29
+
30
+   .js-terminal {
31
+      background-color: #202020;
32
+      color: #cecece;
33
+   }
32 34
 }
33 35
 
34 36
 .test {

+ 15
- 1
ts/jash.ts View File

@@ -92,6 +92,9 @@ namespace Jash {
92 92
          let key = keydown.key
93 93
          if (key.length == 1) {
94 94
             this.currentReadline += key;
95
+            if (this.currentReadlines[0].onChangeCallback !== undefined) {
96
+               this.currentReadlines[0].onChangeCallback(this.currentReadline);
97
+            }
95 98
             if (key == "/") {
96 99
                keydown.preventDefault();
97 100
             }
@@ -100,10 +103,16 @@ namespace Jash {
100 103
             switch (keydown.keyCode) {
101 104
                case (32): {
102 105
                   this.currentReadline += " ";
106
+                  if (this.currentReadlines[0].onChangeCallback !== undefined) {
107
+                     this.currentReadlines[0].onChangeCallback(this.currentReadline);
108
+                  }
103 109
                   break;
104 110
                }
105 111
                case (8): {
106 112
                   this.currentReadline = this.currentReadline.substr(0, this.currentReadline.length - 1);
113
+                  if (this.currentReadlines[0].onChangeCallback !== undefined) {
114
+                     this.currentReadlines[0].onChangeCallback(this.currentReadline);
115
+                  }
107 116
                   break;
108 117
                }
109 118
                case (13): {
@@ -118,6 +127,10 @@ namespace Jash {
118 127
                case (0): {
119 128
                   if (keydown.key == "Dead") {
120 129
                      this.currentReadline += "~";
130
+
131
+                     if (this.currentReadlines[0].onChangeCallback !== undefined) {
132
+                        this.currentReadlines[0].onChangeCallback(this.currentReadline);
133
+                     }
121 134
                   }
122 135
                }
123 136
             }
@@ -136,6 +149,7 @@ namespace Jash {
136 149
       * Inherited from Std.Input-interface. Not to be manually called.
137 150
       */
138 151
       readline(readline: Std.Readline) {
152
+         this.currentReadline = readline.default || "";
139 153
          this.currentReadlines.push(readline);
140 154
          this.refresh();
141 155
       }
@@ -191,7 +205,7 @@ namespace Jash {
191 205
          for (let i in this.messages) {
192 206
             messages.push(this.messages[i].slice());
193 207
          }
194
-         if (this.currentReadlines.length > 0) {
208
+         if (this.currentReadlines.length > 0 && !this.currentReadlines[0].hidden) {
195 209
             let readline = this.currentReadlines[0];
196 210
             let readlinePart = (readline.prefix || "") + this.currentReadline;
197 211
             let tempCursorPos = {x: this.cursor.x, y: this.cursor.y};

+ 1
- 0
ts/main.ts View File

@@ -13,5 +13,6 @@ function main() {
13 13
 
14 14
    globJash.setDefaultStyle("test");
15 15
 
16
+   //globJsterm.launchProgram(new TestProgram());
16 17
    globJsterm.launchProgram(globJsx = new JavaScriptX.JSX());
17 18
 }

+ 3
- 0
ts/std.ts View File

@@ -210,9 +210,12 @@ namespace Std {
210 210
    */
211 211
    export interface Readline {
212 212
       callback: (response: string) => void;
213
+      onChangeCallback?: (current: string) => void;
213 214
       style?: string;
214 215
       prefix?: string;
215 216
       printAfterDone?: boolean;
217
+      hidden?: boolean;
218
+      default?: string;
216 219
    }
217 220
 
218 221
    function translatePageToTerminal(termElem: JQuery, terminal: JSTerminal.Terminal, x: number, y: number) {

+ 6
- 1
ts/testprogram.ts View File

@@ -25,7 +25,12 @@ class TestProgram implements JSTerminal.Program {
25 25
             terminal.closeProgram(this);
26 26
          },
27 27
          printAfterDone: true,
28
-         style: "red"
28
+         style: "red",
29
+         hidden: false,
30
+         onChangeCallback: (curr: string) => {
31
+            console.log(curr);
32
+         },
33
+         default: "heh"
29 34
       });
30 35
    }
31 36