summary refs log tree commit diff
path: root/v2/screen.ts
diff options
context:
space:
mode:
Diffstat (limited to 'v2/screen.ts')
-rw-r--r--v2/screen.ts16
1 files changed, 12 insertions, 4 deletions
diff --git a/v2/screen.ts b/v2/screen.ts
index 2d90dde..4da6482 100644
--- a/v2/screen.ts
+++ b/v2/screen.ts
@@ -1,4 +1,4 @@
-import type { Element } from "./elements.ts"
+import type { Element, Input, Text, Button } from "./elements.ts"
 import readline from 'node:readline';
 
 readline.emitKeypressEvents(process.stdin);
@@ -14,7 +14,7 @@ function onexit() {
 }
 
 export class Screen {
-    elements: Map<string, Element> = new Map<string, Element>();
+    elements: Map<string, Element|Input|Text|Button> = new Map();
     name: string;
     focusedElementId: string = '';
     logs = logs
@@ -23,6 +23,12 @@ export class Screen {
         this.name = name;
     }
 
+    call(function_name:string, ...args:any) {
+        for (const element of this.elements) {
+            element[1][function_name](...args)
+        }
+    }
+
     handleKeypress(chunk: any, key: any, screen: Screen) {
         const focusableIDs = Object.keys(screen.getFocusable());
         const focusedIndex = focusableIDs.indexOf(screen.focusedElementId);
@@ -52,13 +58,15 @@ export class Screen {
         return (chunk: any, key: any) => this.handleKeypress(chunk,key, screen);
     }
 
+    keypressHandler = this.getKeypressHandler(this)
+
     ready() {
-        process.stdin.on('keypress', this.getKeypressHandler(this));
+        process.stdin.on('keypress', this.keypressHandler);
         this.render()
     }
 
     off() {
-        process.stdin.off('keypress', this.getKeypressHandler(this))
+        process.stdin.off('keypress', this.keypressHandler)
     }
 
     addElement(name: string, element: Element) {