From b5f05b69e33ea07cdf35e6f88cd786ec56ca7591 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Tue, 26 Apr 2022 12:28:15 -0600 Subject: [PATCH] Remove MCI cache and xxhash dependency The MCI cache is no longer needed as we no longer rely on DSR/CPR --- core/art.js | 99 ++++++++++++++++------------------------------------ package.json | 1 - 2 files changed, 30 insertions(+), 70 deletions(-) diff --git a/core/art.js b/core/art.js index 46a0ce8d..5e77a915 100644 --- a/core/art.js +++ b/core/art.js @@ -15,7 +15,6 @@ const paths = require('path'); const assert = require('assert'); const iconv = require('iconv-lite'); const _ = require('lodash'); -const xxhash = require('xxhash'); exports.getArt = getArt; exports.getArtFromPath = getArtFromPath; @@ -250,8 +249,7 @@ function display(client, art, options, cb) { return cb(Errors.Invalid('No art supplied!')); } - options.mciReplaceChar = options.mciReplaceChar || ' '; - options.disableMciCache = options.disableMciCache || false; + options.mciReplaceChar = options.mciReplaceChar || ' '; // :TODO: this is going to be broken into two approaches controlled via options: // 1) Standard - use internal tracking of locations for MCI -- no CPR's/etc. @@ -272,82 +270,45 @@ function display(client, art, options, cb) { startRow : options.startRow, }); - let parseComplete = false; - let mciMap; - const mciCprQueue = []; - let artHash; - let mciMapFromCache; + const mciMap = {}; + let generatedId = 100; - function completed() { + ansiParser.on('mci', mciInfo => { + // :TODO: ensure generatedId's do not conflict with any existing |id| + const id = _.isNumber(mciInfo.id) ? mciInfo.id : generatedId; + const mapKey = `${mciInfo.mci}${id}`; + const mapEntry = mciMap[mapKey]; - if(!options.disableMciCache && !mciMapFromCache) { - // cache our MCI findings... - client.mciCache[artHash] = mciMap; - client.log.trace( { artHash : artHash.toString(16), mciMap : mciMap }, 'Added MCI map to cache'); + if(mapEntry) { + mapEntry.focusSGR = mciInfo.SGR; + mapEntry.focusArgs = mciInfo.args; + } else { + mciMap[mapKey] = { + position : mciInfo.position, + args : mciInfo.args, + SGR : mciInfo.SGR, + code : mciInfo.mci, + id : id, + }; + + if(!mciInfo.id) { + ++generatedId; + } } - ansiParser.removeAllListeners(); // :TODO: Necessary??? + }); + + ansiParser.on('literal', literal => client.term.write(literal, false) ); + ansiParser.on('control', control => client.term.rawWrite(control) ); + + ansiParser.on('complete', () => { + ansiParser.removeAllListeners(); const extraInfo = { height : ansiParser.row - 1, }; return cb(null, mciMap, extraInfo); - } - - if(!options.disableMciCache) { - artHash = xxhash.hash(Buffer.from(art), 0xCAFEBABE); - - // see if we have a mciMap cached for this art - if(client.mciCache) { - mciMap = client.mciCache[artHash]; - } - } - - if(mciMap) { - mciMapFromCache = true; - client.log.trace( { artHash : artHash.toString(16), mciMap : mciMap }, 'Loaded MCI map from cache'); - } else { - // no cached MCI info - mciMap = {}; - - let generatedId = 100; - - ansiParser.on('mci', mciInfo => { - // :TODO: ensure generatedId's do not conflict with any existing |id| - const id = _.isNumber(mciInfo.id) ? mciInfo.id : generatedId; - const mapKey = `${mciInfo.mci}${id}`; - const mapEntry = mciMap[mapKey]; - - if(mapEntry) { - mapEntry.focusSGR = mciInfo.SGR; - mapEntry.focusArgs = mciInfo.args; - } else { - mciMap[mapKey] = { - position : mciInfo.position, - args : mciInfo.args, - SGR : mciInfo.SGR, - code : mciInfo.mci, - id : id, - }; - - if(!mciInfo.id) { - ++generatedId; - } - } - - }); - } - - ansiParser.on('literal', literal => client.term.write(literal, false) ); - ansiParser.on('control', control => client.term.rawWrite(control) ); - - ansiParser.on('complete', () => { - parseComplete = true; - - if(0 === mciCprQueue.length) { - return completed(); - } }); let initSeq = ''; diff --git a/package.json b/package.json index 94e674b0..a1617dea 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,6 @@ "uuid": "8.3.2", "uuid-parse": "1.1.0", "ws": "7.4.3", - "xxhash": "^0.3.0", "yazl": "^2.5.1" }, "devDependencies": {