diff options
author | Florrie <towerofnix@gmail.com> | 2019-09-15 16:55:53 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2019-09-15 17:09:31 -0300 |
commit | 3f76094c554c23ee3519f41458a04d348f4f75a3 (patch) | |
tree | 5b87c588651b52aec6136e651e73d9f1d747c638 /util | |
parent | 878e55e7c2a203d89fb1dad83ba6d6d8751b521a (diff) |
(!!) 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.
Diffstat (limited to 'util')
-rw-r--r-- | util/ansi.js | 21 |
1 files changed, 16 insertions, 5 deletions
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('') } } |