Fix demo having black spots and refactor a bit

* Note: black spots are caused by inexplicable palette switch; might need investigation
box-drawing
cpsdqs 7 years ago
parent 91c17e0fc3
commit e9aa3bfba6
Signed by untrusted user: cpsdqs
GPG Key ID: 3F59586BB7448DD1
  1. 1
      js/term/demo.js
  2. 17
      js/term/screen_renderer.js

@ -281,7 +281,6 @@ class ScrollingTerminal {
else if (setForeground) serialized += '\x05' + encode2B(foreground) else if (setForeground) serialized += '\x05' + encode2B(foreground)
else if (setBackground) serialized += '\x06' + encode2B(background) else if (setBackground) serialized += '\x06' + encode2B(background)
if (setAttributes) serialized += '\x04' + encode2B(attributes) if (setAttributes) serialized += '\x04' + encode2B(attributes)
lastStyle = style lastStyle = style
} }
serialized += cell[0] serialized += cell[0]

@ -53,6 +53,7 @@ module.exports = class ScreenRenderer {
set palette (palette) { set palette (palette) {
if (this._palette !== palette) { if (this._palette !== palette) {
this._palette = palette this._palette = palette
this.resetDrawn()
this.scheduleDraw('palette') this.scheduleDraw('palette')
} }
} }
@ -96,8 +97,8 @@ module.exports = class ScreenRenderer {
return `rgb(${red}, ${green}, ${blue})` return `rgb(${red}, ${green}, ${blue})`
} }
// default to transparent // return error color
return 'rgba(0, 0, 0, 0)' return (Date.now() / 1000) % 2 === 0 ? '#f0f' : '#0f0'
} }
/** /**
@ -413,9 +414,9 @@ module.exports = class ScreenRenderer {
let inSelection = this.screen.isInSelection(x, y) let inSelection = this.screen.isInSelection(x, y)
let text = this.screen.screen[cell] let text = this.screen.screen[cell]
let fg = this.screen.screenFG[cell] let fg = this.screen.screenFG[cell] | 0
let bg = this.screen.screenBG[cell] let bg = this.screen.screenBG[cell] | 0
let attrs = this.screen.screenAttrs[cell] let attrs = this.screen.screenAttrs[cell] | 0
if (attrs & (1 << 4) && !this.blinkStyleOn) { if (attrs & (1 << 4) && !this.blinkStyleOn) {
// blinking is enabled and blink style is off // blinking is enabled and blink style is off
@ -438,7 +439,7 @@ module.exports = class ScreenRenderer {
let font = attrs & FONT_MASK let font = attrs & FONT_MASK
if (!fontGroups.has(font)) fontGroups.set(font, []) if (!fontGroups.has(font)) fontGroups.set(font, [])
fontGroups.get(font).push([cell, x, y, text, fg, bg, attrs, isCursor, inSelection]) fontGroups.get(font).push({ cell, x, y, text, fg, bg, attrs, isCursor, inSelection })
updateMap.set(cell, didUpdate) updateMap.set(cell, didUpdate)
} }
@ -507,7 +508,7 @@ module.exports = class ScreenRenderer {
// pass 1: backgrounds // pass 1: backgrounds
for (let font of fontGroups.keys()) { for (let font of fontGroups.keys()) {
for (let data of fontGroups.get(font)) { for (let data of fontGroups.get(font)) {
let [cell, x, y, text, , bg] = data let { cell, x, y, text, bg } = data
if (redrawMap.get(cell)) { if (redrawMap.get(cell)) {
this.drawBackground({ x, y, cellWidth, cellHeight, bg }) this.drawBackground({ x, y, cellWidth, cellHeight, bg })
@ -536,7 +537,7 @@ module.exports = class ScreenRenderer {
ctx.font = this.screen.getFont(modifiers) ctx.font = this.screen.getFont(modifiers)
for (let data of fontGroups.get(font)) { for (let data of fontGroups.get(font)) {
let [cell, x, y, text, fg, bg, attrs, isCursor, inSelection] = data let { cell, x, y, text, fg, bg, attrs, isCursor, inSelection } = data
if (redrawMap.get(cell)) { if (redrawMap.get(cell)) {
this.drawCharacter({ this.drawCharacter({

Loading…
Cancel
Save