« get me outta code hell

Make tui-app work with draw dependencies - tui-lib - Pure Node.js library for making visual command-line programs (ala vim, ncdu)
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2019-10-17 10:04:50 -0300
committerFlorrie <towerofnix@gmail.com>2019-10-17 10:04:50 -0300
commitfd2acc348797982e0c4ec7702eac1fa47c690648 (patch)
tree98b3a2dcf884a0afb4e0c8b4b7ea96bb9720a8e6
parentea5b57242b7734b2d7c70cce48658d4e3331102f (diff)
Make tui-app work with draw dependencies
...instead of using the old loop system.
-rw-r--r--package-lock.json2
-rw-r--r--util/tui-app.js21
2 files changed, 8 insertions, 15 deletions
diff --git a/package-lock.json b/package-lock.json
index aa06ee1..33f839f 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
 {
   "name": "tui-lib",
-  "version": "0.0.0",
+  "version": "0.0.3",
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {
diff --git a/util/tui-app.js b/util/tui-app.js
index 0b845ea..a695e57 100644
--- a/util/tui-app.js
+++ b/util/tui-app.js
@@ -20,6 +20,7 @@ module.exports = async function tuiApp(callback) {
     root.w = size.width;
     root.h = size.height;
     flushable.resizeScreen(size);
+    root.on('rendered', () => flushable.flush());
 
     interfacer.on('resize', newSize => {
         root.w = newSize.width;
@@ -48,26 +49,18 @@ module.exports = async function tuiApp(callback) {
         process.kill(process.pid, 'SIGTSTP');
     };
 
-    const startRenderLoop = function () {
+    process.on('SIGCONT', () => {
+        flushable.clearLastFrame();
+        process.stdin.setRawMode(false);
+        process.stdin.setRawMode(true);
         dirtyTerminal();
+    });
 
-        process.on('SIGCONT', () => {
-            flushable.clearLastFrame();
-            process.stdin.setRawMode(false);
-            process.stdin.setRawMode(true);
-            dirtyTerminal();
-        });
-
-        setInterval(() => {
-            root.renderTo(flushable);
-            flushable.flush();
-        });
-    };
+    dirtyTerminal();
 
     try {
         return await callback({
             root,
-            startRenderLoop,
             suspendProgram,
             quitProgram
         });