Remove most references to screen in parser

pull/1/head
cpsdqs 7 years ago
parent 180ab41299
commit 90a1676084
Signed by untrusted user: cpsdqs
GPG Key ID: 3F59586BB7448DD1
  1. 31
      js/term/screen.js
  2. 74
      js/term/screen_parser.js

@ -688,6 +688,10 @@ module.exports = class TermScreen extends EventEmitter {
this.emit('button-labels', update.labels) this.emit('button-labels', update.labels)
break break
case 'backdrop':
this.backgroundImage = update.image
break
case 'bell': case 'bell':
this.beep() this.beep()
break break
@ -697,7 +701,32 @@ module.exports = class TermScreen extends EventEmitter {
break break
case 'content': case 'content':
update.tempDoNotCommitUpstream() const { frameX, frameY, frameWidth, frameHeight, cells } = update
if (this._debug && this.window.debug) {
this._debug.pushFrame([frameX, frameY, frameWidth, frameHeight])
}
for (let cell = 0; cell < cells.length; cell++) {
let data = cells[cell]
let cellXInFrame = cell % frameWidth
let cellYInFrame = Math.floor(cell / frameWidth)
let index = (frameY + cellYInFrame) * this.window.width + frameX + cellXInFrame
this.screen[index] = data[0]
this.screenFG[index] = data[1]
this.screenBG[index] = data[2]
this.screenAttrs[index] = data[3]
}
this.renderer.scheduleDraw('load', 16)
this.conn.emit('load')
this.emit('load')
break
case 'full-load-complete':
this.emit('TEMP:hide-load-failed-msg')
break break
default: default:

@ -63,20 +63,10 @@ module.exports = class ScreenParser {
} }
}) })
// true if TermScreen#load was called at least once // true if full content was loaded
this.contentLoaded = false this.contentLoaded = false
} }
/**
* Hide the warning message about failed data load
*/
hideLoadFailedMsg () {
if (!this.contentLoaded) {
this.screen.emit('TEMP:hide-load-failed-msg')
this.contentLoaded = true
}
}
parseUpdate (str) { parseUpdate (str) {
// console.log(`update ${str}`) // console.log(`update ${str}`)
// current index // current index
@ -142,11 +132,6 @@ module.exports = class ScreenParser {
else if (cursorStyle === 1) cursorStyle = 'line' else if (cursorStyle === 1) cursorStyle = 'line'
else cursorStyle = 'bar' else cursorStyle = 'bar'
if (this.screen.cursor.blinking !== cursorBlinking) {
this.screen.cursor.blinking = cursorBlinking
this.screen.renderer.resetCursorBlink()
}
const showButtons = !!(attributes & OPT_SHOW_BUTTONS) const showButtons = !!(attributes & OPT_SHOW_BUTTONS)
const showConfigLinks = !!(attributes & OPT_SHOW_CONFIG_LINKS) const showConfigLinks = !!(attributes & OPT_SHOW_CONFIG_LINKS)
@ -232,19 +217,11 @@ module.exports = class ScreenParser {
}) })
} else if (topic === TOPIC_CONTENT) { } else if (topic === TOPIC_CONTENT) {
// set screen content // set screen content
let _ci = ci
let tempDoNotCommitUpstream = () => {
let ci = _ci
const frameY = du(strArray[ci++]) const frameY = du(strArray[ci++])
const frameX = du(strArray[ci++]) const frameX = du(strArray[ci++])
const frameHeight = du(strArray[ci++]) const frameHeight = du(strArray[ci++])
const frameWidth = du(strArray[ci++]) const frameWidth = du(strArray[ci++])
if (this.screen._debug && this.screen.window.debug) {
this.screen._debug.pushFrame([frameX, frameY, frameWidth, frameHeight])
}
// content // content
let fg = 7 let fg = 7
let bg = 0 let bg = 0
@ -256,45 +233,44 @@ module.exports = class ScreenParser {
const MASK_LINE_ATTR = ATTR_UNDERLINE | ATTR_OVERLINE | ATTR_STRIKE const MASK_LINE_ATTR = ATTR_UNDERLINE | ATTR_OVERLINE | ATTR_STRIKE
const MASK_BLINK = ATTR_BLINK const MASK_BLINK = ATTR_BLINK
const cells = []
let pushCell = () => { let pushCell = () => {
// Remove blink attribute if it wouldn't have any effect
let myAttrs = attrs
let hasFG = attrs & ATTR_FG let hasFG = attrs & ATTR_FG
let hasBG = attrs & ATTR_BG let hasBG = attrs & ATTR_BG
let cellFG = fg let cellFG = fg
let cellBG = bg let cellBG = bg
let cellAttrs = attrs
// use 0,0 if no fg/bg. this is to match back-end implementation // 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 // and allow leaving out fg/bg setting for cells with none
if (!hasFG) cellFG = 0 if (!hasFG) cellFG = 0
if (!hasBG) cellBG = 0 if (!hasBG) cellBG = 0
if ((myAttrs & MASK_BLINK) !== 0 && // Remove blink attribute if it wouldn't have any effect
((lastChar === ' ' && ((myAttrs & MASK_LINE_ATTR) === 0)) || // no line styles if ((cellAttrs & MASK_BLINK) &&
((lastChar === ' ' && ((cellAttrs & MASK_LINE_ATTR) === 0)) || // no line styles
(fg === bg && hasFG && hasBG) // invisible text (fg === bg && hasFG && hasBG) // invisible text
) )
) { ) {
myAttrs ^= MASK_BLINK cellAttrs ^= MASK_BLINK
} }
// TODO: reimplement
/*
// update blinking cells counter if blink state changed // update blinking cells counter if blink state changed
if ((this.screen.screenAttrs[cell] & MASK_BLINK) !== (myAttrs & MASK_BLINK)) { if ((this.screen.screenAttrs[cell] & MASK_BLINK) !== (cellAttrs & MASK_BLINK)) {
if (myAttrs & MASK_BLINK) this.screen.blinkingCellCount++ if (cellAttrs & MASK_BLINK) this.screen.blinkingCellCount++
else this.screen.blinkingCellCount-- else this.screen.blinkingCellCount--
} }
*/
let cellXInFrame = cell % frameWidth
let cellYInFrame = Math.floor(cell / frameWidth)
let index = (frameY + cellYInFrame) * this.screen.window.width + frameX + cellXInFrame
// 8 dark system colors turn bright when bold // 8 dark system colors turn bright when bold
if ((myAttrs & ATTR_BOLD) && !(myAttrs & ATTR_FAINT) && hasFG && cellFG < 8) { if ((cellAttrs & ATTR_BOLD) && !(cellAttrs & ATTR_FAINT) && hasFG && cellFG < 8) {
cellFG += 8 cellFG += 8
} }
this.screen.screen[index] = lastChar cells.push([lastChar, cellFG, cellBG, cellAttrs])
this.screen.screenFG[index] = cellFG
this.screen.screenBG[index] = cellBG
this.screen.screenAttrs[index] = myAttrs
} }
while (ci < strArray.length && cell < frameLength) { while (ci < strArray.length && cell < frameLength) {
@ -358,19 +334,23 @@ module.exports = class ScreenParser {
} }
} }
if (this.screen.window.debug) console.log(`Blinky cells: ${this.screen.blinkingCellCount}`) // TODO (see above)
// if (this.screen.window.debug) console.log(`Blinky cells: ${this.screen.blinkingCellCount}`)
this.screen.renderer.scheduleDraw('load', 16)
this.screen.conn.emit('load')
}
updates.push({ updates.push({
topic: 'content', topic: 'content',
tempDoNotCommitUpstream frameX,
frameY,
frameWidth,
frameHeight,
cells
}) })
} }
if ((topics & 0x3B) !== 0) this.hideLoadFailedMsg() if (topics & 0x3B && !this.contentLoaded) {
updates.push({ topic: 'full-load-complete' })
this.contentLoaded = true
}
} }
return updates return updates

Loading…
Cancel
Save