From a72c229ab3cf6895e40019da516e55a664a035f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sat, 23 Sep 2017 13:50:50 +0200 Subject: [PATCH] no such thing as inexplicable - removed theme setting to 0 in demo constructor - removed repeated theme setting in demo when not needed - moved showPage() to a better place in demo to properly wait for load --- _debug_replacements.php | 2 +- js/term/connection.js | 3 +-- js/term/demo.js | 17 +++++++++++------ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/_debug_replacements.php b/_debug_replacements.php index 508eced..c07a03c 100644 --- a/_debug_replacements.php +++ b/_debug_replacements.php @@ -90,7 +90,7 @@ return [ 'uart_stopbits' => 1, 'uart_parity' => 2, - 'theme' => 1, + 'theme' => 0, 'pwlock' => 1, 'access_name' => 'espterm', ]; diff --git a/js/term/connection.js b/js/term/connection.js index 1506695..8687adc 100644 --- a/js/term/connection.js +++ b/js/term/connection.js @@ -82,7 +82,7 @@ module.exports = class TermConnection extends EventEmitter { default: this.screen.load(evt.data) if (!this.pageShown) { - showPage() + window.showPage() this.pageShown = true } break @@ -139,7 +139,6 @@ module.exports = class TermConnection extends EventEmitter { window.alert('Demoing non-demo build!') // this will catch mistakes when deploying to the website } else { demo.init(this.screen) - showPage() } return } diff --git a/js/term/demo.js b/js/term/demo.js index 7f23aa7..33b515e 100644 --- a/js/term/demo.js +++ b/js/term/demo.js @@ -1,5 +1,6 @@ const EventEmitter = require('events') const { encode2B, encode3B, parse2B } = require('../utils') +const { themes } = require('./themes') class ANSIParser { constructor (handler) { @@ -119,13 +120,15 @@ class ScrollingTerminal { this.reset() this._lastLoad = Date.now() - this.termScreen.load(this.serialize(), 0) + this.termScreen.load(this.serialize()) + + window.showPage() } reset () { this.style = TERM_DEFAULT_STYLE this.cursor = { x: 0, y: 0, style: 1, visible: true } this.trackMouse = false - this.theme = 0 + this.theme = -1 this.rainbow = false this.parser.reset() this.clear() @@ -291,6 +294,7 @@ class ScrollingTerminal { clearTimeout(this._scheduledLoad) if (this._lastLoad < Date.now() - TERM_MIN_DRAW_DELAY) { this.termScreen.load(this.serialize(), this.theme) + this.theme = -1 // prevent useless theme setting next time } else { this._scheduledLoad = setTimeout(() => { this.termScreen.load(this.serialize()) @@ -441,7 +445,7 @@ let demoshIndex = { let drawCell = (x, y) => { moveTo(x, y) if (splash[y][x] === '@') { - this.emit('write', '\x1b[48;5;8m\x1b[38;5;255m▄\b') + this.emit('write', '\x1b[48;5;238m\x1b[38;5;255m▄\b') } else { let level = 231 + levels[splash[y][x]] let character = characters[splash[y][x]] @@ -548,9 +552,10 @@ let demoshIndex = { this.shell = shell } run (...args) { - let theme = args[0] | 0 - if (!args.length || !Number.isFinite(theme) || theme < 0 || theme > 5) { - this.emit('write', '\x1b[31mUsage: theme [0–5]\r\n') + let theme = +args[0] | 0 + const maxnum = themes.length + if (!args.length || !Number.isFinite(theme) || theme < 0 || theme >= maxnum) { + this.emit('write', `\x1b[31mUsage: theme [0–${maxnum-1}]\r\n`) this.destroy() return }