diff options
author | wlodekm <[email protected]> | 2024-11-10 19:33:13 +0200 |
---|---|---|
committer | wlodekm <[email protected]> | 2024-11-10 19:33:13 +0200 |
commit | 6c6f9765c5982347b36a38bce366dddadc497fe3 (patch) | |
tree | 888f22cb99c6dbae08cd31e0351adecef4c0f7ba /v2/screen.ts | |
parent | 22a2150eef88430f9d9d5491a002e23e7813ac0c (diff) |
add home
Diffstat (limited to 'v2/screen.ts')
-rw-r--r-- | v2/screen.ts | 16 |
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) { |