From 8053f12b63e272cc9119a30f9ddc480b5ea75641 Mon Sep 17 00:00:00 2001 From: Florrie Date: Sun, 15 Sep 2019 17:17:31 -0300 Subject: Only render when stuff on-screen actually changes! This means we can basically guarantee 0% CPU usage when nothing on the screen is changing! There may still be some kinks to work out, but I've tested most features and fixed any apparent bugs (including an unrelated bug in the suspend feature which made it crash when resuming the process). --- client.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'client.js') diff --git a/client.js b/client.js index a899c2d..c591a00 100644 --- a/client.js +++ b/client.js @@ -16,7 +16,7 @@ const { } } = require('./tui-lib') -const setupClient = async ({backend, writable, interfacer, appConfig, frameRate = 50}) => { +const setupClient = async ({backend, writable, interfacer, appConfig}) => { const cleanTerminal = () => { writable.write(ansi.cleanCursor()) writable.write(ansi.disableAlternateScreen()) @@ -29,14 +29,15 @@ const setupClient = async ({backend, writable, interfacer, appConfig, frameRate dirtyTerminal() - const root = new Root(interfacer) + const flushable = new Flushable(writable, true) + const root = new Root(interfacer, flushable) + root.on('rendered', () => flushable.flush()) const size = await interfacer.getScreenSize() root.w = size.width root.h = size.height root.fixAllLayout() - const flushable = new Flushable(writable, true) flushable.resizeScreen(size) flushable.write(ansi.clearScreen()) flushable.flush() @@ -78,12 +79,7 @@ const setupClient = async ({backend, writable, interfacer, appConfig, frameRate appElement.queueListingElement.buildItems() appElement.playbackInfoElement.updateTrack(backend.playingTrack) - const renderInterval = setInterval(() => { - root.renderTo(flushable) - flushable.flush() - }, frameRate) - - return {appElement, cleanTerminal, flushable, renderInterval} + return {appElement, cleanTerminal, dirtyTerminal, flushable, root} } module.exports = setupClient -- cgit 1.3.0-6-gf8a5