Refactor and fix getColor returning undefined

box-drawing
cpsdqs 7 years ago
parent 52bde8c266
commit a196f9a9de
Signed by untrusted user: cpsdqs
GPG Key ID: 3F59586BB7448DD1
  1. 11
      js/term/screen_parser.js
  2. 2
      js/term/screen_renderer.js

@ -1,6 +1,6 @@
const $ = require('../lib/chibi') const $ = require('../lib/chibi')
const { qs } = require('../utils') const { qs } = require('../utils')
const { themes, defThemes } = require('./themes') const { themes } = require('./themes')
// constants for decoding the update blob // constants for decoding the update blob
const SEQ_REPEAT = 2 const SEQ_REPEAT = 2
@ -160,7 +160,7 @@ module.exports = class ScreenParser {
case SEQ_REPEAT: case SEQ_REPEAT:
let count = strArray[i++].codePointAt(0) - 1 let count = strArray[i++].codePointAt(0) - 1
for (let j = 0; j < count; j++) { for (let j = 0; j < count; j++) {
setCellContent(cell) setCellContent()
if (++cell > screenLength) break if (++cell > screenLength) break
} }
break break
@ -189,7 +189,7 @@ module.exports = class ScreenParser {
default: default:
if (charCode < 32) character = '\ufffd' if (charCode < 32) character = '\ufffd'
lastChar = character lastChar = character
setCellContent(cell) setCellContent()
cell++ cell++
} }
} }
@ -223,7 +223,10 @@ module.exports = class ScreenParser {
/** /**
* Loads a message from the server, and optionally a theme. * Loads a message from the server, and optionally a theme.
* @param {string} str - the message * @param {string} str - the message
* @param {object} [opts] - options { [int] theme, [int] defaultFg, [int] defaultBg } * @param {object} [opts] - options
* @param {number} [opts.theme] - theme
* @param {number} [opts.defaultFg] - default foreground
* @param {number} [opts.defaultBg] - default background
*/ */
load (str, opts = null) { load (str, opts = null) {
const content = str.substr(1) const content = str.substr(1)

@ -89,7 +89,7 @@ module.exports = class ScreenRenderer {
*/ */
getColor (i) { getColor (i) {
// return palette color if it exists // return palette color if it exists
if (i < 16) return this.palette[i] if (i < 16 && i in this.palette) return this.palette[i]
// -1 for selection foreground, -2 for selection background // -1 for selection foreground, -2 for selection background
if (i === -1) return SELECTION_FG if (i === -1) return SELECTION_FG

Loading…
Cancel
Save