|
|
@ -2,6 +2,8 @@ const EventEmitter = require('events') |
|
|
|
const { parse2B } = require('../utils') |
|
|
|
const { parse2B } = require('../utils') |
|
|
|
const { themes } = require('./themes') |
|
|
|
const { themes } = require('./themes') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const encodeAsCodePoint = i => String.fromCodePoint(i + (i >= 0xD800 ? 0x801 : 1)) |
|
|
|
|
|
|
|
|
|
|
|
class ANSIParser { |
|
|
|
class ANSIParser { |
|
|
|
constructor (handler) { |
|
|
|
constructor (handler) { |
|
|
|
this.reset() |
|
|
|
this.reset() |
|
|
@ -113,7 +115,6 @@ class ANSIParser { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
const TERM_DEFAULT_STYLE = [0, 0, 0] |
|
|
|
const TERM_DEFAULT_STYLE = [0, 0, 0] |
|
|
|
const TERM_MIN_DRAW_DELAY = 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let getRainbowColor = t => { |
|
|
|
let getRainbowColor = t => { |
|
|
|
let r = Math.floor(Math.sin(t) * 2.5 + 2.5) |
|
|
|
let r = Math.floor(Math.sin(t) * 2.5 + 2.5) |
|
|
@ -270,45 +271,45 @@ class ScrollingTerminal { |
|
|
|
} |
|
|
|
} |
|
|
|
getScreenOpts () { |
|
|
|
getScreenOpts () { |
|
|
|
let data = 'O' |
|
|
|
let data = 'O' |
|
|
|
data += String.fromCodePoint(26) |
|
|
|
data += encodeAsCodePoint(25) |
|
|
|
data += String.fromCodePoint(81) |
|
|
|
data += encodeAsCodePoint(80) |
|
|
|
data += String.fromCodePoint(this.theme + 1) |
|
|
|
data += encodeAsCodePoint(this.theme) |
|
|
|
data += String.fromCodePoint(8) |
|
|
|
data += encodeAsCodePoint(7) |
|
|
|
data += String.fromCodePoint(1) |
|
|
|
data += encodeAsCodePoint(0) |
|
|
|
data += String.fromCodePoint(1) |
|
|
|
data += encodeAsCodePoint(0) |
|
|
|
data += String.fromCodePoint(1) |
|
|
|
data += encodeAsCodePoint(0) |
|
|
|
let attributes = +this.cursor.visible |
|
|
|
let attributes = +this.cursor.visible |
|
|
|
attributes |= (3 << 5) * +this.trackMouse // track mouse controls both
|
|
|
|
attributes |= (3 << 5) * +this.trackMouse // track mouse controls both
|
|
|
|
attributes |= 3 << 7 // buttons/links always visible
|
|
|
|
attributes |= 3 << 7 // buttons/links always visible
|
|
|
|
attributes |= (this.cursor.style << 9) |
|
|
|
attributes |= (this.cursor.style << 9) |
|
|
|
data += String.fromCodePoint(attributes + 1) |
|
|
|
data += encodeAsCodePoint(attributes) |
|
|
|
return data |
|
|
|
return data |
|
|
|
} |
|
|
|
} |
|
|
|
getButtons () { |
|
|
|
getButtons () { |
|
|
|
let data = 'B' |
|
|
|
let data = 'B' |
|
|
|
data += String.fromCodePoint(6) |
|
|
|
data += encodeAsCodePoint(5) |
|
|
|
data += this.buttonLabels.map(x => x + '\x01').join('') |
|
|
|
data += this.buttonLabels.map(x => x + '\x01').join('') |
|
|
|
return data |
|
|
|
return data |
|
|
|
} |
|
|
|
} |
|
|
|
getCursor () { |
|
|
|
getCursor () { |
|
|
|
let data = 'C' |
|
|
|
let data = 'C' |
|
|
|
data += String.fromCodePoint(this.cursor.y + 1) |
|
|
|
data += encodeAsCodePoint(this.cursor.y) |
|
|
|
data += String.fromCodePoint(this.cursor.x + 1) |
|
|
|
data += encodeAsCodePoint(this.cursor.x) |
|
|
|
data += String.fromCodePoint(1) |
|
|
|
data += encodeAsCodePoint(0) |
|
|
|
return data |
|
|
|
return data |
|
|
|
} |
|
|
|
} |
|
|
|
encodeColor (color) { |
|
|
|
encodeColor (color) { |
|
|
|
if (color < 256) { |
|
|
|
if (color < 256) { |
|
|
|
return String.fromCodePoint(color + 1) |
|
|
|
return encodeAsCodePoint(color) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
color -= 256 |
|
|
|
color -= 256 |
|
|
|
return String.fromCodePoint(((color & 0xFFF) | 0x10000) + 1) + String.fromCodePoint((color >> 12) + 1) |
|
|
|
return encodeAsCodePoint((color & 0xFFF) | 0x10000) + encodeAsCodePoint(color >> 12) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
serializeScreen () { |
|
|
|
serializeScreen () { |
|
|
|
let serialized = 'S' |
|
|
|
let serialized = 'S' |
|
|
|
serialized += String.fromCodePoint(1) + String.fromCodePoint(1) |
|
|
|
serialized += encodeAsCodePoint(0) + encodeAsCodePoint(0) |
|
|
|
serialized += String.fromCodePoint(this.height + 1) + String.fromCodePoint(this.width + 1) |
|
|
|
serialized += encodeAsCodePoint(this.height) + encodeAsCodePoint(this.width) |
|
|
|
|
|
|
|
|
|
|
|
let lastStyle = [null, null, null] |
|
|
|
let lastStyle = [null, null, null] |
|
|
|
let index = 0 |
|
|
|
let index = 0 |
|
|
@ -334,14 +335,14 @@ class ScrollingTerminal { |
|
|
|
|
|
|
|
|
|
|
|
if (setForeground && setBackground) { |
|
|
|
if (setForeground && setBackground) { |
|
|
|
if (foreground < 256 && background < 256) { |
|
|
|
if (foreground < 256 && background < 256) { |
|
|
|
serialized += '\x03' + String.fromCodePoint(((background << 8) | foreground) + 1) |
|
|
|
serialized += '\x03' + encodeAsCodePoint((background << 8) | foreground) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
serialized += '\x05' + this.encodeColor(foreground) |
|
|
|
serialized += '\x05' + this.encodeColor(foreground) |
|
|
|
serialized += '\x06' + this.encodeColor(background) |
|
|
|
serialized += '\x06' + this.encodeColor(background) |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (setForeground) serialized += '\x05' + this.encodeColor(foreground) |
|
|
|
} else if (setForeground) serialized += '\x05' + this.encodeColor(foreground) |
|
|
|
else if (setBackground) serialized += '\x06' + this.encodeColor(background) |
|
|
|
else if (setBackground) serialized += '\x06' + this.encodeColor(background) |
|
|
|
if (setAttributes) serialized += '\x04' + String.fromCodePoint(attributes + 1) |
|
|
|
if (setAttributes) serialized += '\x04' + encodeAsCodePoint(attributes) |
|
|
|
lastStyle = style |
|
|
|
lastStyle = style |
|
|
|
|
|
|
|
|
|
|
|
serialized += cell[0] |
|
|
|
serialized += cell[0] |
|
|
@ -372,7 +373,7 @@ class ScrollingTerminal { |
|
|
|
topicData.push(screen) |
|
|
|
topicData.push(screen) |
|
|
|
} |
|
|
|
} |
|
|
|
if (!topicData.length) return '' |
|
|
|
if (!topicData.length) return '' |
|
|
|
return 'U' + String.fromCodePoint(topics + 1) + topicData.join('') |
|
|
|
return 'U' + encodeAsCodePoint(topics) + topicData.join('') |
|
|
|
} |
|
|
|
} |
|
|
|
loadTimer () { |
|
|
|
loadTimer () { |
|
|
|
clearInterval(this._loadTimer) |
|
|
|
clearInterval(this._loadTimer) |
|
|
|