Remove refs to single-instance objects in parser

pull/1/head
cpsdqs 7 years ago
parent bd933657f4
commit e2cdb4091c
Signed by untrusted user: cpsdqs
GPG Key ID: 3F59586BB7448DD1
  1. 24
      js/term/index.js
  2. 16
      js/term/screen.js
  3. 24
      js/term/screen_parser.js

@ -26,6 +26,30 @@ module.exports = function (opts) {
buttons.update() buttons.update()
}) })
screen.on('TEMP:hide-load-failed-msg', () => {
let scr = qs('#screen')
let errmsg = qs('#load-failed')
if (scr) scr.classList.remove('failed')
if (errmsg) errmsg.parentNode.removeChild(errmsg)
})
screen.on('TEMP:show-config-links', show => {
let buttons = [...document.querySelectorAll('.x-term-conf-btn')]
if (show) buttons.forEach(x => x.classList.remove('hidden'))
else buttons.forEach(x => x.classList.add('hidden'))
})
screen.on('TEMP:show-buttons', show => {
if (show) qs('#action-buttons').classList.remove('hidden')
else qs('#action-buttons').classList.add('hidden')
})
screen.on('TEMP:update-title', text => {
qs('#screen-title').textContent = text
if (!text) text = 'Terminal'
qs('title').textContent = `${text} :: ESPTerm`
})
let showSplashTimeout = null let showSplashTimeout = null
let showSplash = (obj, delay = 250) => { let showSplash = (obj, delay = 250) => {
clearTimeout(showSplashTimeout) clearTimeout(showSplashTimeout)

@ -60,7 +60,8 @@ module.exports = class TermScreen extends EventEmitter {
gridScaleY: 1.2, gridScaleY: 1.2,
fitIntoWidth: 0, fitIntoWidth: 0,
fitIntoHeight: 0, fitIntoHeight: 0,
debug: false, // two bits. LSB: debug enabled by user, MSB: debug enabled by server
debug: 0,
graphics: 0, graphics: 0,
statusScreen: null statusScreen: null
} }
@ -85,6 +86,8 @@ module.exports = class TermScreen extends EventEmitter {
fitIntoHeight: 0 fitIntoHeight: 0
} }
const self = this
// current selection // current selection
this.selection = { this.selection = {
// when false, this will prevent selection in favor of mouse events, // when false, this will prevent selection in favor of mouse events,
@ -93,14 +96,21 @@ module.exports = class TermScreen extends EventEmitter {
// selection start and end (x, y) tuples // selection start and end (x, y) tuples
start: [0, 0], start: [0, 0],
end: [0, 0] end: [0, 0],
setSelectable (value) {
if (value !== this.selectable) {
this.selectable = value
if (value) self.classList.add('selectable')
else self.classList.remove('selectable')
}
}
} }
// mouse features // mouse features
this.mouseMode = { clicks: false, movement: false } this.mouseMode = { clicks: false, movement: false }
// make writing to window update size and draw // make writing to window update size and draw
const self = this
this.window = new Proxy(this._window, { this.window = new Proxy(this._window, {
set (target, key, value, receiver) { set (target, key, value, receiver) {
if (target[key] !== value) { if (target[key] !== value) {

@ -1,6 +1,3 @@
const $ = require('../lib/chibi')
const { qs } = require('../utils')
const { const {
ATTR_FG, ATTR_FG,
ATTR_BG, ATTR_BG,
@ -66,10 +63,7 @@ module.exports = class ScreenParser {
*/ */
hideLoadFailedMsg () { hideLoadFailedMsg () {
if (!this.contentLoaded) { if (!this.contentLoaded) {
let scr = qs('#screen') this.screen.emit('TEMP:hide-load-failed-msg')
let errmsg = qs('#load-failed')
if (scr) scr.classList.remove('failed')
if (errmsg) errmsg.parentNode.removeChild(errmsg)
this.contentLoaded = true this.contentLoaded = true
} }
} }
@ -150,8 +144,7 @@ module.exports = class ScreenParser {
} }
this.screen.input.setMouseMode(trackMouseClicks, trackMouseMovement) this.screen.input.setMouseMode(trackMouseClicks, trackMouseMovement)
this.screen.selection.selectable = !trackMouseClicks && !trackMouseMovement this.screen.selection.setSelectable(!trackMouseClicks && !trackMouseMovement)
$(this.screen.canvas).toggleClass('selectable', this.screen.selection.selectable)
this.screen.mouseMode = { this.screen.mouseMode = {
clicks: trackMouseClicks, clicks: trackMouseClicks,
movement: trackMouseMovement movement: trackMouseMovement
@ -160,15 +153,15 @@ module.exports = class ScreenParser {
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)
$('.x-term-conf-btn').toggleClass('hidden', !showConfigLinks) this.screen.emit('TEMP:show-config-links', showConfigLinks)
$('#action-buttons').toggleClass('hidden', !showButtons) this.screen.emit('TEMP:show-buttons', showButtons)
this.screen.bracketedPaste = !!(attributes & OPT_BRACKETED_PASTE) this.screen.bracketedPaste = !!(attributes & OPT_BRACKETED_PASTE)
this.screen.reverseVideo = !!(attributes & OPT_REVERSE_VIDEO) this.screen.reverseVideo = !!(attributes & OPT_REVERSE_VIDEO)
const debugbar = !!(attributes & OPT_DEBUGBAR) const debugbar = !!(attributes & OPT_DEBUGBAR)
// TODO do something with debugbar
this.screen.window.debug &= 0b01 | (+debugbar < 1)
} else if (topic === TOPIC_CURSOR) { } else if (topic === TOPIC_CURSOR) {
// cursor position // cursor position
@ -193,12 +186,7 @@ module.exports = class ScreenParser {
this.screen.renderer.scheduleDraw('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())
text = collectOneTerminatedString()
qs('#screen-title').textContent = text
if (text.length === 0) text = 'Terminal'
qs('title').textContent = `${text} :: ESPTerm`
} else if (topic === TOPIC_BUTTONS) { } else if (topic === TOPIC_BUTTONS) {
const count = du(strArray[ci++]) const count = du(strArray[ci++])

Loading…
Cancel
Save