From 3f76094c554c23ee3519f41458a04d348f4f75a3 Mon Sep 17 00:00:00 2001 From: Florrie Date: Sun, 15 Sep 2019 16:55:53 -0300 Subject: (!!) Only render when draw-dependency props change This is a very large change and probably breaks most applications not built to work with it. (Obviously, I'm not really being that responsible with this sort of thing.) I've tested with mtui and it works fine, but some elements may need tweaks before being 100% adjusted to the new scheduled-render system we're using with this commit. Also, any elements which have custom draw behavior will likely need updating so that they appropriately schedule renders. --- util/ansi.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'util/ansi.js') diff --git a/util/ansi.js b/util/ansi.js index c786db5..ac511ed 100644 --- a/util/ansi.js +++ b/util/ansi.js @@ -182,7 +182,8 @@ const ansi = { interpret(text, scrRows, scrCols, { oldChars = null, oldLastChar = null, - oldCursorRow = 0, oldCursorCol = 0, oldShowCursor = true + oldScrRows = null, oldScrCols = null, + oldCursorRow = 1, oldCursorCol = 1, oldShowCursor = true } = {}) { // Interprets the given ansi code, more or less. @@ -193,9 +194,17 @@ const ansi = { const chars = new Array(scrRows * scrCols).fill(blank) - let showCursor = true - let cursorRow = 1 - let cursorCol = 1 + if (oldChars) { + for (let row = 0; row < scrRows && row < oldScrRows; row++) { + for (let col = 0; col < scrCols && col < oldScrCols; col++) { + chars[row * scrCols + col] = oldChars[row * oldScrCols + col] + } + } + } + + let showCursor = oldShowCursor + let cursorRow = oldCursorRow + let cursorCol = oldCursorCol let attributes = [] for (let charI = 0; charI < text.length; charI++) { @@ -475,10 +484,12 @@ const ansi = { return { oldChars: newChars.slice(), + oldLastChar: Object.assign({}, lastChar), + oldScrRows: scrRows, + oldScrCols: scrCols, oldCursorRow: cursorRow, oldCursorCol: cursorCol, oldShowCursor: showCursor, - oldLastChar: Object.assign({}, lastChar), screen: result.join('') } } -- cgit 1.3.0-6-gf8a5