Browse Source

Added primal version of JEdi and made slight changex

Teascade 4 years ago
parent
commit
7f060dfb98
3 changed files with 68 additions and 3 deletions
  1. 1
    0
      ts/jsx.ts
  2. 65
    2
      ts/jsxcommands.ts
  3. 2
    1
      ts/main.ts

+ 1
- 0
ts/jsx.ts View File

@@ -32,6 +32,7 @@ namespace JavaScriptX {
32 32
          system.addFile(new BinaryFile("woman", new JSXCommands.Woman(this)));
33 33
          system.addFile(new BinaryFile("cat", new JSXCommands.Caternate(this)));
34 34
          system.addFile(new BinaryFile("touch", new JSXCommands.Touch(this)));
35
+         system.addFile(new BinaryFile("jedi", new JSXCommands.JEdi(this)));
35 36
 
36 37
          this.filesystem.rootFolder.addFile(new TextFile("textfile.txt", "Hello, world!"));
37 38
 

+ 65
- 2
ts/jsxcommands.ts View File

@@ -349,6 +349,69 @@ namespace JSXCommands {
349 349
          stdio.println(manual.getManual());
350 350
       }
351 351
    }
352
+   export class JEdi implements JSTerminal.Program, JavaScriptX.Manual {
353
+      jsx: JavaScriptX.JSX;
354
+      stdio: Std.IO;
355
+      terminal: JSTerminal.Terminal;
356
+      text: string[] = [""];
357
+      row = 0
358
+
359
+      constructor(jsx: JavaScriptX.JSX) {
360
+         this.jsx = jsx;
361
+      }
362
+
363
+      create(terminal: JSTerminal.Terminal, stdio: Std.IO, args?: string[]) {
364
+         this.stdio = stdio;
365
+         this.terminal = terminal;
366
+
367
+         this.doCommand();
368
+      }
369
+      enable() { }
370
+      disable() { }
371
+      onClose() { return true; }
372
+
373
+      getManual() {
374
+         return "(J)avascript (Edi)tor is a custom version of the UNIX editor 'ed'." +
375
+            "\nIt's quite simpler in the way that all of it's commands are whole words" +
376
+            "\n\nUsage: jedi [(optional) path]";
377
+      }
378
+
379
+      readManual(stdio: Std.IO, manual: JavaScriptX.Manual) {
380
+         stdio.println(manual.getManual());
381
+      }
382
+
383
+      doCommand() {
384
+         let readline = this.stdio.readline({
385
+            callback: c => this.exec(c),
386
+            prefix: "\n> ",
387
+            printAfterDone: true
388
+         })
389
+      }
390
+
391
+      exec(command: string) {
392
+         if (command == "exit" || command == "quit") {
393
+            this.terminal.closeProgram(this);
394
+            return;
395
+         } else if (command.split(" ")[0] == "append") {
396
+            let appended = command.split(" ").slice(1).join(" ");
397
+            debugger;
398
+            console.log(appended)
399
+            let rows = appended.split("\n");
400
+            console.log(rows)
401
+            for (let i = 0; i < rows.length; i++) {
402
+               if (this.text.length <= (this.row + i)) {
403
+                  this.text.push("");
404
+               }
405
+               this.text[this.row + i] += rows[i];
406
+            }
407
+            this.row += rows.length - 1;
408
+            this.stdio.println(`${this.text[this.row]}`);
409
+
410
+         }
411
+
412
+         this.doCommand();
413
+      }
414
+   }
352 415
 
353 416
    /**
354 417
    * Parses all given args from '--arg val' into format {arg: val}
@@ -379,7 +442,7 @@ namespace JSXCommands {
379 442
       return returned;
380 443
    }
381 444
 
382
-   function manualGuard(o: any): o is JavaScriptX.Manual {
383
-      return o.getManual != undefined
445
+   function manualGuard(arg: any): arg is JavaScriptX.Manual {
446
+      return arg.getManual !== undefined
384 447
    }
385 448
 }

+ 2
- 1
ts/main.ts View File

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