From 6c6f9765c5982347b36a38bce366dddadc497fe3 Mon Sep 17 00:00:00 2001 From: wlodekm Date: Sun, 10 Nov 2024 19:33:13 +0200 Subject: add home --- v2/screen.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'v2/screen.ts') 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 = new Map(); + elements: Map = 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) { -- cgit 1.4.1-2-gfad0