diff --git a/js/term/index.js b/js/term/index.js index a382d1a..c6d8d82 100644 --- a/js/term/index.js +++ b/js/term/index.js @@ -26,6 +26,30 @@ module.exports = function (opts) { 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 showSplash = (obj, delay = 250) => { clearTimeout(showSplashTimeout) diff --git a/js/term/screen.js b/js/term/screen.js index 2fb13eb..9c9fe1f 100644 --- a/js/term/screen.js +++ b/js/term/screen.js @@ -60,7 +60,8 @@ module.exports = class TermScreen extends EventEmitter { gridScaleY: 1.2, fitIntoWidth: 0, fitIntoHeight: 0, - debug: false, + // two bits. LSB: debug enabled by user, MSB: debug enabled by server + debug: 0, graphics: 0, statusScreen: null } @@ -85,6 +86,8 @@ module.exports = class TermScreen extends EventEmitter { fitIntoHeight: 0 } + const self = this + // current selection this.selection = { // 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 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 this.mouseMode = { clicks: false, movement: false } // make writing to window update size and draw - const self = this this.window = new Proxy(this._window, { set (target, key, value, receiver) { if (target[key] !== value) { diff --git a/js/term/screen_parser.js b/js/term/screen_parser.js index 93f4b09..6c6149e 100644 --- a/js/term/screen_parser.js +++ b/js/term/screen_parser.js @@ -1,6 +1,3 @@ -const $ = require('../lib/chibi') -const { qs } = require('../utils') - const { ATTR_FG, ATTR_BG, @@ -66,10 +63,7 @@ module.exports = class ScreenParser { */ hideLoadFailedMsg () { if (!this.contentLoaded) { - let scr = qs('#screen') - let errmsg = qs('#load-failed') - if (scr) scr.classList.remove('failed') - if (errmsg) errmsg.parentNode.removeChild(errmsg) + this.screen.emit('TEMP:hide-load-failed-msg') this.contentLoaded = true } } @@ -150,8 +144,7 @@ module.exports = class ScreenParser { } this.screen.input.setMouseMode(trackMouseClicks, trackMouseMovement) - this.screen.selection.selectable = !trackMouseClicks && !trackMouseMovement - $(this.screen.canvas).toggleClass('selectable', this.screen.selection.selectable) + this.screen.selection.setSelectable(!trackMouseClicks && !trackMouseMovement) this.screen.mouseMode = { clicks: trackMouseClicks, movement: trackMouseMovement @@ -160,15 +153,15 @@ module.exports = class ScreenParser { const showButtons = !!(attributes & OPT_SHOW_BUTTONS) const showConfigLinks = !!(attributes & OPT_SHOW_CONFIG_LINKS) - $('.x-term-conf-btn').toggleClass('hidden', !showConfigLinks) - $('#action-buttons').toggleClass('hidden', !showButtons) + this.screen.emit('TEMP:show-config-links', showConfigLinks) + this.screen.emit('TEMP:show-buttons', showButtons) this.screen.bracketedPaste = !!(attributes & OPT_BRACKETED_PASTE) this.screen.reverseVideo = !!(attributes & OPT_REVERSE_VIDEO) const debugbar = !!(attributes & OPT_DEBUGBAR) - // TODO do something with debugbar + this.screen.window.debug &= 0b01 | (+debugbar < 1) } else if (topic === TOPIC_CURSOR) { // cursor position @@ -193,12 +186,7 @@ module.exports = class ScreenParser { this.screen.renderer.scheduleDraw('cursor-moved') } else if (topic === TOPIC_TITLE) { - - text = collectOneTerminatedString() - qs('#screen-title').textContent = text - if (text.length === 0) text = 'Terminal' - qs('title').textContent = `${text} :: ESPTerm` - + this.screen.emit('TEMP:update-title', collectOneTerminatedString()) } else if (topic === TOPIC_BUTTONS) { const count = du(strArray[ci++])