|
|
@ -19,6 +19,7 @@ const SEQ_SET_BG = 6 |
|
|
|
const SEQ_SET_ATTR_0 = 7 |
|
|
|
const SEQ_SET_ATTR_0 = 7 |
|
|
|
|
|
|
|
|
|
|
|
function du (str) { |
|
|
|
function du (str) { |
|
|
|
|
|
|
|
if (!str) return NaN |
|
|
|
let num = str.codePointAt(0) |
|
|
|
let num = str.codePointAt(0) |
|
|
|
if (num > 0xDFFF) num -= 0x800 |
|
|
|
if (num > 0xDFFF) num -= 0x800 |
|
|
|
return num - 1 |
|
|
|
return num - 1 |
|
|
@ -52,7 +53,15 @@ const OPT_REVERSE_VIDEO = (1 << 14) |
|
|
|
|
|
|
|
|
|
|
|
module.exports = class ScreenParser { |
|
|
|
module.exports = class ScreenParser { |
|
|
|
constructor (screen) { |
|
|
|
constructor (screen) { |
|
|
|
this.screen = screen |
|
|
|
// this.screen = screen
|
|
|
|
|
|
|
|
let didWarn = false |
|
|
|
|
|
|
|
Object.defineProperty(this, 'screen', { |
|
|
|
|
|
|
|
get () { |
|
|
|
|
|
|
|
if (!didWarn) console.warn('Deprecated get ScreenParser#screen') |
|
|
|
|
|
|
|
didWarn = true |
|
|
|
|
|
|
|
return screen |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
// true if TermScreen#load was called at least once
|
|
|
|
// true if TermScreen#load was called at least once
|
|
|
|
this.contentLoaded = false |
|
|
|
this.contentLoaded = false |
|
|
@ -68,14 +77,13 @@ module.exports = class ScreenParser { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
loadUpdate (str) { |
|
|
|
parseUpdate (str) { |
|
|
|
// console.log(`update ${str}`)
|
|
|
|
// console.log(`update ${str}`)
|
|
|
|
// current index
|
|
|
|
// current index
|
|
|
|
let ci = 0 |
|
|
|
let ci = 0 |
|
|
|
let strArray = Array.from ? Array.from(str) : str.split('') |
|
|
|
let strArray = Array.from ? Array.from(str) : str.split('') |
|
|
|
|
|
|
|
|
|
|
|
let text |
|
|
|
let text |
|
|
|
let resized = false |
|
|
|
|
|
|
|
const topics = du(strArray[ci++]) |
|
|
|
const topics = du(strArray[ci++]) |
|
|
|
// this.screen.cursor.hanging = !!(attributes & (1 << 1))
|
|
|
|
// this.screen.cursor.hanging = !!(attributes & (1 << 1))
|
|
|
|
|
|
|
|
|
|
|
@ -93,35 +101,30 @@ module.exports = class ScreenParser { |
|
|
|
return text |
|
|
|
return text |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const updates = [] |
|
|
|
|
|
|
|
|
|
|
|
while (ci < strArray.length) { |
|
|
|
while (ci < strArray.length) { |
|
|
|
const topic = strArray[ci++] |
|
|
|
const topic = strArray[ci++] |
|
|
|
|
|
|
|
|
|
|
|
if (topic === TOPIC_SCREEN_OPTS) { |
|
|
|
if (topic === TOPIC_SCREEN_OPTS) { |
|
|
|
const newHeight = du(strArray[ci++]) |
|
|
|
const height = du(strArray[ci++]) |
|
|
|
const newWidth = du(strArray[ci++]) |
|
|
|
const width = du(strArray[ci++]) |
|
|
|
const theme = du(strArray[ci++]) |
|
|
|
const theme = du(strArray[ci++]) |
|
|
|
const defFg = (du(strArray[ci++]) & 0xFFFF) | ((du(strArray[ci++]) & 0xFFFF) << 16) |
|
|
|
const defFG = (du(strArray[ci++]) & 0xFFFF) | ((du(strArray[ci++]) & 0xFFFF) << 16) |
|
|
|
const defBg = (du(strArray[ci++]) & 0xFFFF) | ((du(strArray[ci++]) & 0xFFFF) << 16) |
|
|
|
const defBG = (du(strArray[ci++]) & 0xFFFF) | ((du(strArray[ci++]) & 0xFFFF) << 16) |
|
|
|
const attributes = du(strArray[ci++]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// theming
|
|
|
|
|
|
|
|
this.screen.renderer.loadTheme(theme) |
|
|
|
|
|
|
|
this.screen.renderer.setDefaultColors(defFg, defBg) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// apply size
|
|
|
|
|
|
|
|
resized = (this.screen.window.height !== newHeight) || (this.screen.window.width !== newWidth) |
|
|
|
|
|
|
|
this.screen.window.height = newHeight |
|
|
|
|
|
|
|
this.screen.window.width = newWidth |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// process attributes
|
|
|
|
// process attributes
|
|
|
|
this.screen.cursor.visible = !!(attributes & OPT_CURSOR_VISIBLE) |
|
|
|
const attributes = du(strArray[ci++]) |
|
|
|
|
|
|
|
|
|
|
|
this.screen.input.setAlts( |
|
|
|
const cursorVisible = !!(attributes & OPT_CURSOR_VISIBLE) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// HACK: input alts are formatted as arguments for Input#setAlts
|
|
|
|
|
|
|
|
const inputAlts = [ |
|
|
|
!!(attributes & OPT_CURSORS_ALT_MODE), |
|
|
|
!!(attributes & OPT_CURSORS_ALT_MODE), |
|
|
|
!!(attributes & OPT_NUMPAD_ALT_MODE), |
|
|
|
!!(attributes & OPT_NUMPAD_ALT_MODE), |
|
|
|
!!(attributes & OPT_FN_ALT_MODE), |
|
|
|
!!(attributes & OPT_FN_ALT_MODE), |
|
|
|
!!(attributes & OPT_CRLF_MODE) |
|
|
|
!!(attributes & OPT_CRLF_MODE) |
|
|
|
) |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
const trackMouseClicks = !!(attributes & OPT_CLICK_TRACKING) |
|
|
|
const trackMouseClicks = !!(attributes & OPT_CLICK_TRACKING) |
|
|
|
const trackMouseMovement = !!(attributes & OPT_MOVE_TRACKING) |
|
|
|
const trackMouseMovement = !!(attributes & OPT_MOVE_TRACKING) |
|
|
@ -133,60 +136,58 @@ module.exports = class ScreenParser { |
|
|
|
// if it's not zero, decrement such that the two most significant bits
|
|
|
|
// if it's not zero, decrement such that the two most significant bits
|
|
|
|
// are the type and the least significant bit is the blink state
|
|
|
|
// are the type and the least significant bit is the blink state
|
|
|
|
if (cursorShape > 0) cursorShape-- |
|
|
|
if (cursorShape > 0) cursorShape-- |
|
|
|
const cursorStyle = cursorShape >> 1 |
|
|
|
let cursorStyle = cursorShape >> 1 |
|
|
|
const cursorBlinking = !(cursorShape & 1) |
|
|
|
const cursorBlinking = !(cursorShape & 1) |
|
|
|
if (cursorStyle === 0) this.screen.cursor.style = 'block' |
|
|
|
if (cursorStyle === 0) cursorStyle = 'block' |
|
|
|
else if (cursorStyle === 1) this.screen.cursor.style = 'line' |
|
|
|
else if (cursorStyle === 1) cursorStyle = 'line' |
|
|
|
else if (cursorStyle === 2) this.screen.cursor.style = 'bar' |
|
|
|
else cursorStyle = 'bar' |
|
|
|
|
|
|
|
|
|
|
|
if (this.screen.cursor.blinking !== cursorBlinking) { |
|
|
|
if (this.screen.cursor.blinking !== cursorBlinking) { |
|
|
|
this.screen.cursor.blinking = cursorBlinking |
|
|
|
this.screen.cursor.blinking = cursorBlinking |
|
|
|
this.screen.renderer.resetCursorBlink() |
|
|
|
this.screen.renderer.resetCursorBlink() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.screen.input.setMouseMode(trackMouseClicks, trackMouseMovement) |
|
|
|
|
|
|
|
this.screen.selection.setSelectable(!trackMouseClicks && !trackMouseMovement) |
|
|
|
|
|
|
|
this.screen.mouseMode = { |
|
|
|
|
|
|
|
clicks: trackMouseClicks, |
|
|
|
|
|
|
|
movement: trackMouseMovement |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
this.screen.emit('TEMP:show-config-links', showConfigLinks) |
|
|
|
const bracketedPaste = !!(attributes & OPT_BRACKETED_PASTE) |
|
|
|
this.screen.emit('TEMP:show-buttons', showButtons) |
|
|
|
const reverseVideo = !!(attributes & OPT_REVERSE_VIDEO) |
|
|
|
|
|
|
|
|
|
|
|
this.screen.bracketedPaste = !!(attributes & OPT_BRACKETED_PASTE) |
|
|
|
const debugEnabled = !!(attributes & OPT_DEBUGBAR) |
|
|
|
this.screen.reverseVideo = !!(attributes & OPT_REVERSE_VIDEO) |
|
|
|
|
|
|
|
|
|
|
|
updates.push({ |
|
|
|
const debugbar = !!(attributes & OPT_DEBUGBAR) |
|
|
|
topic: 'screen-opts', |
|
|
|
|
|
|
|
width, |
|
|
|
this.screen.window.debug &= 0b01 | (+debugbar < 1) |
|
|
|
height, |
|
|
|
|
|
|
|
theme, |
|
|
|
|
|
|
|
defFG, |
|
|
|
|
|
|
|
defBG, |
|
|
|
|
|
|
|
cursorVisible, |
|
|
|
|
|
|
|
cursorBlinking, |
|
|
|
|
|
|
|
cursorStyle, |
|
|
|
|
|
|
|
inputAlts, |
|
|
|
|
|
|
|
trackMouseClicks, |
|
|
|
|
|
|
|
trackMouseMovement, |
|
|
|
|
|
|
|
showButtons, |
|
|
|
|
|
|
|
showConfigLinks, |
|
|
|
|
|
|
|
bracketedPaste, |
|
|
|
|
|
|
|
reverseVideo, |
|
|
|
|
|
|
|
debugEnabled |
|
|
|
|
|
|
|
}) |
|
|
|
} else if (topic === TOPIC_CURSOR) { |
|
|
|
} else if (topic === TOPIC_CURSOR) { |
|
|
|
|
|
|
|
|
|
|
|
// cursor position
|
|
|
|
// cursor position
|
|
|
|
const cursorY = du(strArray[ci++]) |
|
|
|
const y = du(strArray[ci++]) |
|
|
|
const cursorX = du(strArray[ci++]) |
|
|
|
const x = du(strArray[ci++]) |
|
|
|
const hanging = du(strArray[ci++]) |
|
|
|
const hanging = !!du(strArray[ci++]) |
|
|
|
|
|
|
|
|
|
|
|
const cursorMoved = ( |
|
|
|
updates.push({ |
|
|
|
hanging !== this.screen.cursor.hanging || |
|
|
|
topic: 'cursor', |
|
|
|
cursorX !== this.screen.cursor.x || |
|
|
|
x, |
|
|
|
cursorY !== this.screen.cursor.y) |
|
|
|
y, |
|
|
|
|
|
|
|
hanging |
|
|
|
this.screen.cursor.x = cursorX |
|
|
|
}) |
|
|
|
this.screen.cursor.y = cursorY |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.screen.cursor.hanging = !!hanging |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cursorMoved) { |
|
|
|
|
|
|
|
this.screen.renderer.resetCursorBlink() |
|
|
|
|
|
|
|
this.screen.emit('cursor-moved') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.screen.renderer.scheduleDraw('cursor-moved') |
|
|
|
|
|
|
|
} else if (topic === TOPIC_TITLE) { |
|
|
|
} else if (topic === TOPIC_TITLE) { |
|
|
|
this.screen.emit('TEMP:update-title', collectOneTerminatedString()) |
|
|
|
updates.push({ topic: 'title', title: collectOneTerminatedString() }) |
|
|
|
} else if (topic === TOPIC_BUTTONS) { |
|
|
|
} else if (topic === TOPIC_BUTTONS) { |
|
|
|
const count = du(strArray[ci++]) |
|
|
|
const count = du(strArray[ci++]) |
|
|
|
|
|
|
|
|
|
|
@ -196,16 +197,14 @@ module.exports = class ScreenParser { |
|
|
|
labels.push(text) |
|
|
|
labels.push(text) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.screen.emit('button-labels', labels) |
|
|
|
updates.push({ |
|
|
|
|
|
|
|
topic: 'button-labels', |
|
|
|
|
|
|
|
labels |
|
|
|
|
|
|
|
}) |
|
|
|
} else if (topic === TOPIC_BACKDROP) { |
|
|
|
} else if (topic === TOPIC_BACKDROP) { |
|
|
|
|
|
|
|
updates.push({ topic: 'backdrop', image: collectOneTerminatedString() }) |
|
|
|
text = collectOneTerminatedString() |
|
|
|
|
|
|
|
this.screen.backgroundImage = text |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (topic === TOPIC_BELL) { |
|
|
|
} else if (topic === TOPIC_BELL) { |
|
|
|
|
|
|
|
updates.push({ topic: 'bell' }) |
|
|
|
this.screen.beep() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (topic === TOPIC_INTERNAL) { |
|
|
|
} else if (topic === TOPIC_INTERNAL) { |
|
|
|
// debug info
|
|
|
|
// debug info
|
|
|
|
|
|
|
|
|
|
|
@ -219,7 +218,8 @@ module.exports = class ScreenParser { |
|
|
|
const freeHeap = du(strArray[ci++]) |
|
|
|
const freeHeap = du(strArray[ci++]) |
|
|
|
const clientCount = du(strArray[ci++]) |
|
|
|
const clientCount = du(strArray[ci++]) |
|
|
|
|
|
|
|
|
|
|
|
this.screen.emit('internal', { |
|
|
|
updates.push({ |
|
|
|
|
|
|
|
topic: 'internal', |
|
|
|
flags, |
|
|
|
flags, |
|
|
|
cursorAttrs, |
|
|
|
cursorAttrs, |
|
|
|
regionStart, |
|
|
|
regionStart, |
|
|
@ -232,7 +232,10 @@ 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++]) |
|
|
@ -249,16 +252,6 @@ module.exports = class ScreenParser { |
|
|
|
let cell = 0 // cell index
|
|
|
|
let cell = 0 // cell index
|
|
|
|
let lastChar = ' ' |
|
|
|
let lastChar = ' ' |
|
|
|
let frameLength = frameWidth * frameHeight |
|
|
|
let frameLength = frameWidth * frameHeight |
|
|
|
let screenLength = this.screen.window.width * this.screen.window.height |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (resized) { |
|
|
|
|
|
|
|
this.screen.updateSize() |
|
|
|
|
|
|
|
this.screen.blinkingCellCount = 0 |
|
|
|
|
|
|
|
this.screen.screen = new Array(screenLength).fill(' ') |
|
|
|
|
|
|
|
this.screen.screenFG = new Array(screenLength).fill(' ') |
|
|
|
|
|
|
|
this.screen.screenBG = new Array(screenLength).fill(' ') |
|
|
|
|
|
|
|
this.screen.screenAttrs = new Array(screenLength).fill(0) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
@ -369,26 +362,34 @@ module.exports = class ScreenParser { |
|
|
|
|
|
|
|
|
|
|
|
this.screen.renderer.scheduleDraw('load', 16) |
|
|
|
this.screen.renderer.scheduleDraw('load', 16) |
|
|
|
this.screen.conn.emit('load') |
|
|
|
this.screen.conn.emit('load') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updates.push({ |
|
|
|
|
|
|
|
topic: 'content', |
|
|
|
|
|
|
|
tempDoNotCommitUpstream |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ((topics & 0x3B) !== 0) this.hideLoadFailedMsg() |
|
|
|
if ((topics & 0x3B) !== 0) this.hideLoadFailedMsg() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return updates |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Loads a message from the server, and optionally a theme. |
|
|
|
* Parses a message from the server |
|
|
|
* @param {string} str - the message |
|
|
|
* @param {string} message - the message |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
load (str) { |
|
|
|
parse (message) { |
|
|
|
const content = str.substr(1) |
|
|
|
const content = message.substr(1) |
|
|
|
|
|
|
|
const updates = [] |
|
|
|
|
|
|
|
|
|
|
|
// This is a good place for debugging the message
|
|
|
|
// This is a good place for debugging the message
|
|
|
|
// console.log(str)
|
|
|
|
// console.log(message)
|
|
|
|
|
|
|
|
|
|
|
|
switch (str[0]) { |
|
|
|
switch (message[0]) { |
|
|
|
case 'U': |
|
|
|
case 'U': |
|
|
|
this.loadUpdate(content) |
|
|
|
updates.push(...this.parseUpdate(content)) |
|
|
|
break |
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
case 'G': |
|
|
|
case 'G': |
|
|
@ -396,7 +397,9 @@ module.exports = class ScreenParser { |
|
|
|
break |
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
default: |
|
|
|
console.warn(`Bad data message type; ignoring.\n${JSON.stringify(str)}`) |
|
|
|
console.warn(`Bad data message type; ignoring.\n${JSON.stringify(message)}`) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return updates |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|