From 7c912035289c0d43283625a738a39d341ac383b7 Mon Sep 17 00:00:00 2001 From: cpsdqs Date: Sat, 30 Sep 2017 22:16:01 +0200 Subject: [PATCH] Fix parser derp, show internal info if available --- js/term/buttons.js | 1 - js/term/debug_screen.js | 16 ++++++++++++++++ js/term/screen_parser.js | 38 ++++++++++++++++++++++++-------------- 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/js/term/buttons.js b/js/term/buttons.js index ceb5e69..929464d 100644 --- a/js/term/buttons.js +++ b/js/term/buttons.js @@ -34,7 +34,6 @@ module.exports = function initButtons (input) { // sync with DOM let update = function updateButtons () { - console.log(labels) if (labels.length > buttons.length) { for (let i = buttons.length; i < labels.length; i++) { pushButton() diff --git a/js/term/debug_screen.js b/js/term/debug_screen.js index 0f486c6..b4c58a1 100644 --- a/js/term/debug_screen.js +++ b/js/term/debug_screen.js @@ -247,14 +247,30 @@ module.exports = function attachDebugScreen (screen) { return `((${y},${x})=${cell}:${hexcode}:F${cellFG}:B${cellBG}:A${cellAttrs.toString(2)})` } + let internalInfo = {} + updateToolbar = () => { if (!toolbarAttached) return let text = `C((${screen.cursor.y},${screen.cursor.x}),hang:${screen.cursor.hanging},vis:${screen.cursor.visible})` if (mouseHoverCell) { text += ' m' + getCellData(mouseHoverCell[1] * screen.window.width + mouseHoverCell[0]) } + if ('flags' in internalInfo) { + // we got ourselves some internal data + text += ' ' + text += ` flags:${internalInfo.flags}` + text += ` curAttrs:${internalInfo.cursorAttrs}` + text += ` Region:${internalInfo.regionStart}->${internalInfo.regionEnd}` + text += ` Charset:${internalInfo.charsetGx} (0:${internalInfo.charsetG0},1:${internalInfo.charsetG1})` + text += ` Heap:${internalInfo.freeHeap}` + text += ` Clients:${internalInfo.clientCount}` + } dataDisplay.textContent = text } screen.on('draw', updateToolbar) + screen.on('internal', data => { + internalInfo = data + updateToolbar() + }) } diff --git a/js/term/screen_parser.js b/js/term/screen_parser.js index 16400a6..8e20ab3 100644 --- a/js/term/screen_parser.js +++ b/js/term/screen_parser.js @@ -212,8 +212,8 @@ module.exports = class ScreenParser { this.screen.beep() } else if (topic === TOPIC_INTERNAL) { - // debug info + const flags = du(strArray[ci++]) const cursorAttrs = du(strArray[ci++]) const regionStart = du(strArray[ci++]) @@ -222,15 +222,25 @@ module.exports = class ScreenParser { const charsetG0 = strArray[ci++] const charsetG1 = strArray[ci++] const freeHeap = du(strArray[ci++]) - const numClients = du(strArray[ci++]) - // TODO do something with those - + const clientCount = du(strArray[ci++]) + + this.emit('internal', { + flags, + cursorAttrs, + regionStart, + regionEnd, + charsetGx, + charsetG0, + charsetG1, + freeHeap, + clientCount + }) } else if (topic === TOPIC_CONTENT) { // set screen content const frameY = du(strArray[ci++]) const frameX = du(strArray[ci++]) - const frameHeight = du(strArray[ci++]) // FIXME unused, useless data! + const frameHeight = du(strArray[ci++]) const frameWidth = du(strArray[ci++]) // content @@ -239,7 +249,7 @@ module.exports = class ScreenParser { let attrs = 0 let cell = 0 // cell index let lastChar = ' ' - let screenLength = this.screen.window.width * this.screen.window.height + let screenLength = frameWidth * frameHeight if (resized) { this.screen.updateSize() @@ -258,11 +268,13 @@ module.exports = class ScreenParser { let myAttrs = attrs let hasFG = attrs & ATTR_FG let hasBG = attrs & ATTR_BG + let cellFG = fg + let cellBG = bg // use 0,0 if no fg/bg. this is to match back-end implementation // and allow leaving out fg/bg setting for cells with none - if (!hasFG) fg = 0 - if (!hasBG) bg = 0 + if (!hasFG) cellFG = 0 + if (!hasBG) cellBG = 0 if ((myAttrs & MASK_BLINK) !== 0 && ((lastChar === ' ' && ((myAttrs & MASK_LINE_ATTR) === 0)) || // no line styles @@ -281,16 +293,14 @@ module.exports = class ScreenParser { let cellYInFrame = Math.floor(cell / frameWidth) let index = (frameY + cellYInFrame) * this.screen.window.width + frameX + cellXInFrame - let cellFg = fg - // 8 dark system colors turn bright when bold - if ((myAttrs & ATTR_BOLD) && !(myAttrs & ATTR_FAINT) && hasFG && fg < 8) { - cellFg += 8 + if ((myAttrs & ATTR_BOLD) && !(myAttrs & ATTR_FAINT) && hasFG && cellFG < 8) { + cellFG += 8 } this.screen.screen[index] = lastChar - this.screen.screenFG[index] = cellFg - this.screen.screenBG[index] = bg + this.screen.screenFG[index] = cellFG + this.screen.screenBG[index] = cellBG this.screen.screenAttrs[index] = myAttrs }