Clean up and add a few comments

pull/1/head
cpsdqs 7 years ago
parent c3f6b4d851
commit a460b5fe89
Signed by untrusted user: cpsdqs
GPG Key ID: 3F59586BB7448DD1
  1. 10
      js/term/index.js
  2. 1
      js/term/input.js
  3. 5
      js/term/screen.js
  4. 4
      js/term/screen_parser.js
  5. 7
      js/term/screen_renderer.js

@ -18,6 +18,7 @@ module.exports = function (opts) {
const termUpload = TermUpload(conn, input, screen) const termUpload = TermUpload(conn, input, screen)
input.termUpload = termUpload input.termUpload = termUpload
// forward screen input events
screen.on('mousedown', (...args) => input.onMouseDown(...args)) screen.on('mousedown', (...args) => input.onMouseDown(...args))
screen.on('mousemove', (...args) => input.onMouseMove(...args)) screen.on('mousemove', (...args) => input.onMouseMove(...args))
screen.on('mouseup', (...args) => input.onMouseUp(...args)) screen.on('mouseup', (...args) => input.onMouseUp(...args))
@ -25,6 +26,7 @@ module.exports = function (opts) {
screen.on('input-alts', (...args) => input.setAlts(...args)) screen.on('input-alts', (...args) => input.setAlts(...args))
screen.on('mouse-mode', (...args) => input.setMouseMode(...args)) screen.on('mouse-mode', (...args) => input.setMouseMode(...args))
// touch selection menu (the Copy button)
$.ready(() => { $.ready(() => {
const touchSelectMenu = qs('#touch-select-menu') const touchSelectMenu = qs('#touch-select-menu')
screen.on('show-touch-select-menu', (x, y) => { screen.on('show-touch-select-menu', (x, y) => {
@ -40,14 +42,16 @@ module.exports = function (opts) {
const copyButton = qs('#touch-select-copy-btn') const copyButton = qs('#touch-select-copy-btn')
if (copyButton) { if (copyButton) {
copyButton.addEventListener('click', () => { copyButton.addEventListener('click', () => {
this.copySelectionToClipboard() screen.copySelectionToClipboard()
}) })
} }
}) })
// buttons
const buttons = initButtons(input) const buttons = initButtons(input)
screen.on('button-labels', labels => { buttons.labels = labels }) screen.on('button-labels', labels => { buttons.labels = labels })
// TEMPORARY CODE
screen.on('TEMP:hide-load-failed-msg', () => { screen.on('TEMP:hide-load-failed-msg', () => {
let scr = qs('#screen') let scr = qs('#screen')
let errmsg = qs('#load-failed') let errmsg = qs('#load-failed')
@ -72,6 +76,8 @@ module.exports = function (opts) {
qs('title').textContent = `${text} :: ESPTerm` qs('title').textContent = `${text} :: ESPTerm`
}) })
// connection status
let showSplashTimeout = null let showSplashTimeout = null
let showSplash = (obj, delay = 250) => { let showSplash = (obj, delay = 250) => {
clearTimeout(showSplashTimeout) clearTimeout(showSplashTimeout)
@ -126,6 +132,8 @@ module.exports = function (opts) {
initSoftKeyboard(screen, input) initSoftKeyboard(screen, input)
if (attachDebugger) attachDebugger(screen, conn) if (attachDebugger) attachDebugger(screen, conn)
// fullscreen mode
let fullscreenIcon = {} // dummy let fullscreenIcon = {} // dummy
let isFullscreen = false let isFullscreen = false
let properFullscreen = false let properFullscreen = false

@ -1,4 +1,3 @@
const $ = require('../lib/chibi')
const { encode2B } = require('../utils') const { encode2B } = require('../utils')
/** /**

@ -5,6 +5,9 @@ const ScreenParser = require('./screen_parser')
const ScreenRenderer = require('./screen_renderer') const ScreenRenderer = require('./screen_renderer')
const { ATTR_BLINK } = require('./screen_attr_bits') const { ATTR_BLINK } = require('./screen_attr_bits')
/**
* A terminal screen.
*/
module.exports = class TermScreen extends EventEmitter { module.exports = class TermScreen extends EventEmitter {
constructor () { constructor () {
super() super()
@ -709,7 +712,7 @@ module.exports = class TermScreen extends EventEmitter {
break break
default: default:
console.log('Unhandled update', update) console.warn('Unhandled update', update)
} }
} }
} }

@ -18,6 +18,7 @@ const SEQ_SET_FG = 5
const SEQ_SET_BG = 6 const SEQ_SET_BG = 6
const SEQ_SET_ATTR_0 = 7 const SEQ_SET_ATTR_0 = 7
// decode a number encoded as a unicode code point
function du (str) { function du (str) {
if (!str) return NaN if (!str) return NaN
let num = str.codePointAt(0) let num = str.codePointAt(0)
@ -51,6 +52,9 @@ const OPT_REVERSE_VIDEO = (1 << 14)
/* eslint-enable no-multi-spaces */ /* eslint-enable no-multi-spaces */
/**
* A parser for screen update messages
*/
module.exports = class ScreenParser { module.exports = class ScreenParser {
constructor () { constructor () {
// true if full content was loaded // true if full content was loaded

@ -27,7 +27,10 @@ const frakturExceptions = {
'Z': '\u2128' 'Z': '\u2128'
} }
module.exports = class ScreenRenderer { /**
* A terminal screen renderer, using canvas 2D
*/
module.exports = class CanvasRenderer {
constructor (screen) { constructor (screen) {
this.screen = screen this.screen = screen
this.ctx = screen.ctx this.ctx = screen.ctx
@ -231,7 +234,7 @@ module.exports = class ScreenRenderer {
let overline = false let overline = false
if (attrs & ATTR_FAINT) ctx.globalAlpha = 0.5 if (attrs & ATTR_FAINT) ctx.globalAlpha = 0.5
if (attrs & ATTR_UNDERLINE) underline = true if (attrs & ATTR_UNDERLINE) underline = true
if (attrs & ATTR_FRAKTUR) text = ScreenRenderer.alphaToFraktur(text) if (attrs & ATTR_FRAKTUR) text = CanvasRenderer.alphaToFraktur(text)
if (attrs & ATTR_STRIKE) strike = true if (attrs & ATTR_STRIKE) strike = true
if (attrs & ATTR_OVERLINE) overline = true if (attrs & ATTR_OVERLINE) overline = true

Loading…
Cancel
Save