eslint tuning, re-enabled some rules

cpsdqs/unified-input
Ondřej Hruška 7 years ago
parent 4731a259dd
commit 11d9a40951
  1. 6
      .eslintrc
  2. 4
      jssrc/appcommon.js
  3. 2
      jssrc/modal.js
  4. 5
      jssrc/soft_keyboard.js
  5. 23
      jssrc/term_conn.js
  6. 29
      jssrc/term_input.js
  7. 40
      jssrc/term_screen.js
  8. 2
      jssrc/term_upload.js
  9. 6
      jssrc/utils.js
  10. 8
      jssrc/wifi.js

@ -30,7 +30,7 @@
"accessor-pairs": "error", "accessor-pairs": "error",
"arrow-spacing": ["error", { "before": true, "after": true }], "arrow-spacing": ["error", { "before": true, "after": true }],
"block-spacing": ["error", "always"], "block-spacing": ["error", "always"],
"brace-style": ["error", "1tbs", { "allowSingleLine": true }], "brace-style": ["warn", "1tbs", { "allowSingleLine": true }],
"camelcase": ["off", { "properties": "never" }], "camelcase": ["off", { "properties": "never" }],
"comma-dangle": ["error", { "comma-dangle": ["error", {
"arrays": "never", "arrays": "never",
@ -45,7 +45,7 @@
"curly": ["error", "multi-line"], "curly": ["error", "multi-line"],
"dot-location": ["error", "property"], "dot-location": ["error", "property"],
"eol-last": "error", "eol-last": "error",
"eqeqeq": ["off", "always", { "null": "ignore" }], "eqeqeq": ["error", "smart"],
"func-call-spacing": ["error", "never"], "func-call-spacing": ["error", "never"],
"generator-star-spacing": ["error", { "before": true, "after": true }], "generator-star-spacing": ["error", { "before": true, "after": true }],
"handle-callback-err": ["error", "^(err|error)$" ], "handle-callback-err": ["error", "^(err|error)$" ],
@ -97,7 +97,7 @@
"allowSamePrecedence": true "allowSamePrecedence": true
}], }],
"no-mixed-spaces-and-tabs": "error", "no-mixed-spaces-and-tabs": "error",
"no-multi-spaces": "off", "no-multi-spaces": "warn",
"no-multi-str": "error", "no-multi-str": "error",
"no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 0 }], "no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 0 }],
"no-negated-in-lhs": "error", "no-negated-in-lhs": "error",

@ -27,7 +27,7 @@ $.ready(function () {
$('form').forEach(function (x) { $('form').forEach(function (x) {
$(x).on('keypress', function (e) { $(x).on('keypress', function (e) {
if ((e.keyCode == 10 || e.keyCode == 13) && e.ctrlKey) { if ((e.keyCode === 10 || e.keyCode === 13) && e.ctrlKey) {
x.submit() x.submit()
} }
}) })
@ -38,7 +38,7 @@ $.ready(function () {
$('.anim-dots').each(function (x) { $('.anim-dots').each(function (x) {
let $x = $(x) let $x = $(x)
let dots = $x.html() + '.' let dots = $x.html() + '.'
if (dots.length == 5) dots = '.' if (dots.length === 5) dots = '.'
$x.html(dots) $x.html(dots)
}) })
}, 1000) }, 1000)

@ -34,7 +34,7 @@
// Hide all modals on esc // Hide all modals on esc
$(window).on('keydown', function (e) { $(window).on('keydown', function (e) {
if (e.which == 27) { if (e.which === 27) {
modal.hide('.Modal') modal.hide('.Modal')
} }
}) })

@ -15,7 +15,9 @@ $.ready(() => {
keyboardOpen = true keyboardOpen = true
updateInputPosition() updateInputPosition()
}) })
input.addEventListener('blur', () => (keyboardOpen = false)) input.addEventListener('blur', () => (keyboardOpen = false))
Screen.on('cursor-moved', updateInputPosition) Screen.on('cursor-moved', updateInputPosition)
window.kbOpen = function openSoftKeyboard (open) { window.kbOpen = function openSoftKeyboard (open) {
@ -60,6 +62,7 @@ $.ready(() => {
if (e.key === 'Backspace') Input.sendString('\b') if (e.key === 'Backspace') Input.sendString('\b')
else if (e.key === 'Enter') Input.sendString('\x0d') else if (e.key === 'Enter') Input.sendString('\x0d')
}) })
input.addEventListener('input', e => { input.addEventListener('input', e => {
e.stopPropagation() e.stopPropagation()
@ -73,10 +76,12 @@ $.ready(() => {
} }
} }
}) })
input.addEventListener('compositionstart', e => { input.addEventListener('compositionstart', e => {
lastCompositionString = '' lastCompositionString = ''
compositing = true compositing = true
}) })
input.addEventListener('compositionend', e => { input.addEventListener('compositionend', e => {
lastCompositionString = '' lastCompositionString = ''
compositing = false compositing = false

@ -29,15 +29,8 @@ window.Conn = (function () {
try { try {
// . = heartbeat // . = heartbeat
switch (evt.data.charAt(0)) { switch (evt.data.charAt(0)) {
case 'B': case '.':
case 'T': // heartbeat, no-op message
case 'S':
case 'G':
Screen.load(evt.data)
if (!pageShown) {
showPage()
pageShown = true
}
break break
case '-': case '-':
@ -53,6 +46,14 @@ window.Conn = (function () {
xoff = false xoff = false
clearTimeout(autoXoffTout) clearTimeout(autoXoffTout)
break break
default:
Screen.load(evt.data)
if (!pageShown) {
showPage()
pageShown = true
}
break
} }
heartbeat() heartbeat()
} catch (e) { } catch (e) {
@ -76,7 +77,7 @@ window.Conn = (function () {
} }
if (!ws) return false // for dry testing if (!ws) return false // for dry testing
if (ws.readyState != 1) { if (ws.readyState !== 1) {
console.error('Socket not ready') console.error('Socket not ready')
return false return false
} }
@ -116,7 +117,7 @@ window.Conn = (function () {
pingIv = setInterval(function () { pingIv = setInterval(function () {
console.log('> ping') console.log('> ping')
$.get('http://' + _root + '/system/ping', function (resp, status) { $.get('http://' + _root + '/system/ping', function (resp, status) {
if (status == 200) { if (status === 200) {
clearInterval(pingIv) clearInterval(pingIv)
console.info('Server ready, reloading page...') console.info('Server ready, reloading page...')
location.reload() location.reload()

@ -153,6 +153,7 @@ window.Input = (function () {
for (let i = 1; i <= 26; i++) { for (let i = 1; i <= 26; i++) {
bind('ctrl+' + String.fromCharCode(96 + i), String.fromCharCode(i)) bind('ctrl+' + String.fromCharCode(96 + i), String.fromCharCode(i))
} }
/* eslint-disable */
bind('ctrl+]', '\x1b') // alternate way to enter ESC bind('ctrl+]', '\x1b') // alternate way to enter ESC
bind('ctrl+\\', '\x1c') bind('ctrl+\\', '\x1c')
bind('ctrl+[', '\x1d') bind('ctrl+[', '\x1d')
@ -176,12 +177,13 @@ window.Input = (function () {
bind('shift+end', '\x1f[1;2F') bind('shift+end', '\x1f[1;2F')
// macOS editing commands // macOS editing commands
bind('⌥+left', '\x1fb') // ⌥← to go back a word (^[b) bind('⌥+left', '\x1fb') // ⌥← to go back a word (^[b)
bind('⌥+right', '\x1ff') // ⌥→ to go forward one word (^[f) bind('⌥+right', '\x1ff') // ⌥→ to go forward one word (^[f)
bind('⌘+left', '\x01') // ⌘← to go to the beginning of a line (^A) bind('⌘+left', '\x01') // ⌘← to go to the beginning of a line (^A)
bind('⌘+right', '\x05') // ⌘→ to go to the end of a line (^E) bind('⌘+right', '\x05') // ⌘→ to go to the end of a line (^E)
bind('⌥+backspace', '\x17') // ⌥⌫ to delete a word (^W, I think) bind('⌥+backspace', '\x17') // ⌥⌫ to delete a word (^W, I think)
bind('⌘+backspace', '\x15') // ⌘⌫ to delete to the beginning of a line (possibly ^U) bind('⌘+backspace', '\x15') // ⌘⌫ to delete to the beginning of a line (possibly ^U)
/* eslint-enable */
_bindFnKeys() _bindFnKeys()
} }
@ -204,15 +206,15 @@ window.Input = (function () {
// global mouse state tracking - for motion reporting // global mouse state tracking - for motion reporting
window.addEventListener('mousedown', function (evt) { window.addEventListener('mousedown', function (evt) {
if (evt.button == 0) mb1 = 1 if (evt.button === 0) mb1 = 1
if (evt.button == 1) mb2 = 1 if (evt.button === 1) mb2 = 1
if (evt.button == 2) mb3 = 1 if (evt.button === 2) mb3 = 1
}) })
window.addEventListener('mouseup', function (evt) { window.addEventListener('mouseup', function (evt) {
if (evt.button == 0) mb1 = 0 if (evt.button === 0) mb1 = 0
if (evt.button == 1) mb2 = 0 if (evt.button === 1) mb2 = 0
if (evt.button == 2) mb3 = 0 if (evt.button === 2) mb3 = 0
}) })
} }
@ -233,7 +235,7 @@ window.Input = (function () {
/** Enable alternate key modes (cursors, numpad, fn) */ /** Enable alternate key modes (cursors, numpad, fn) */
setAlts: function (cu, np, fn, crlf) { setAlts: function (cu, np, fn, crlf) {
if (opts.cu_alt != cu || opts.np_alt != np || opts.fn_alt != fn || opts.crlf_mode != crlf) { if (opts.cu_alt !== cu || opts.np_alt !== np || opts.fn_alt !== fn || opts.crlf_mode !== crlf) {
opts.cu_alt = cu opts.cu_alt = cu
opts.np_alt = np opts.np_alt = np
opts.fn_alt = fn opts.fn_alt = fn
@ -256,6 +258,7 @@ window.Input = (function () {
const m = packModifiersForMouse() const m = packModifiersForMouse()
Conn.send('m' + encode2B(y) + encode2B(x) + encode2B(b) + encode2B(m)) Conn.send('m' + encode2B(y) + encode2B(x) + encode2B(b) + encode2B(m))
}, },
onMouseDown: function (x, y, b) { onMouseDown: function (x, y, b) {
if (!opts.mt_click) return if (!opts.mt_click) return
if (b > 3 || b < 1) return if (b > 3 || b < 1) return
@ -263,6 +266,7 @@ window.Input = (function () {
Conn.send('p' + encode2B(y) + encode2B(x) + encode2B(b) + encode2B(m)) Conn.send('p' + encode2B(y) + encode2B(x) + encode2B(b) + encode2B(m))
// console.log("B ",b," M ",m); // console.log("B ",b," M ",m);
}, },
onMouseUp: function (x, y, b) { onMouseUp: function (x, y, b) {
if (!opts.mt_click) return if (!opts.mt_click) return
if (b > 3 || b < 1) return if (b > 3 || b < 1) return
@ -270,6 +274,7 @@ window.Input = (function () {
Conn.send('r' + encode2B(y) + encode2B(x) + encode2B(b) + encode2B(m)) Conn.send('r' + encode2B(y) + encode2B(x) + encode2B(b) + encode2B(m))
// console.log("B ",b," M ",m); // console.log("B ",b," M ",m);
}, },
onMouseWheel: function (x, y, dir) { onMouseWheel: function (x, y, dir) {
if (!opts.mt_click) return if (!opts.mt_click) return
// -1 ... btn 4 (away from user) // -1 ... btn 4 (away from user)
@ -279,9 +284,11 @@ window.Input = (function () {
Conn.send('p' + encode2B(y) + encode2B(x) + encode2B(b) + encode2B(m)) Conn.send('p' + encode2B(y) + encode2B(x) + encode2B(b) + encode2B(m))
// console.log("B ",b," M ",m); // console.log("B ",b," M ",m);
}, },
mouseTracksClicks: function () { mouseTracksClicks: function () {
return opts.mt_click return opts.mt_click
}, },
blockKeys: function (yes) { blockKeys: function (yes) {
opts.no_keys = yes opts.no_keys = yes
} }

@ -43,6 +43,8 @@ const themes = [
] ]
] ]
// TODO move this to the initializer so it's not run on non-terminal pages
// 256color lookup table // 256color lookup table
// should not be used to look up 0-15 (will return transparent) // should not be used to look up 0-15 (will return transparent)
const colorTable256 = new Array(16).fill('rgba(0, 0, 0, 0)') const colorTable256 = new Array(16).fill('rgba(0, 0, 0, 0)')
@ -160,17 +162,20 @@ class TermScreen {
this.resetCursorBlink() this.resetCursorBlink()
let selecting = false let selecting = false
let selectStart = (x, y) => { let selectStart = (x, y) => {
if (selecting) return if (selecting) return
selecting = true selecting = true
this.selection.start = this.selection.end = this.screenToGrid(x, y) this.selection.start = this.selection.end = this.screenToGrid(x, y)
this.scheduleDraw() this.scheduleDraw()
} }
let selectMove = (x, y) => { let selectMove = (x, y) => {
if (!selecting) return if (!selecting) return
this.selection.end = this.screenToGrid(x, y) this.selection.end = this.screenToGrid(x, y)
this.scheduleDraw() this.scheduleDraw()
} }
let selectEnd = (x, y) => { let selectEnd = (x, y) => {
if (!selecting) return if (!selecting) return
selecting = false selecting = false
@ -187,9 +192,11 @@ class TermScreen {
e.button + 1) e.button + 1)
} }
}) })
window.addEventListener('mousemove', e => { window.addEventListener('mousemove', e => {
selectMove(e.offsetX, e.offsetY) selectMove(e.offsetX, e.offsetY)
}) })
window.addEventListener('mouseup', e => { window.addEventListener('mouseup', e => {
selectEnd(e.offsetX, e.offsetY) selectEnd(e.offsetX, e.offsetY)
}) })
@ -198,15 +205,18 @@ class TermScreen {
let touchDownTime = 0 let touchDownTime = 0
let touchSelectMinTime = 500 let touchSelectMinTime = 500
let touchDidMove = false let touchDidMove = false
let getTouchPositionOffset = touch => { let getTouchPositionOffset = touch => {
let rect = this.canvas.getBoundingClientRect() let rect = this.canvas.getBoundingClientRect()
return [touch.clientX - rect.left, touch.clientY - rect.top] return [touch.clientX - rect.left, touch.clientY - rect.top]
} }
this.canvas.addEventListener('touchstart', e => { this.canvas.addEventListener('touchstart', e => {
touchPosition = getTouchPositionOffset(e.touches[0]) touchPosition = getTouchPositionOffset(e.touches[0])
touchDidMove = false touchDidMove = false
touchDownTime = Date.now() touchDownTime = Date.now()
}) })
this.canvas.addEventListener('touchmove', e => { this.canvas.addEventListener('touchmove', e => {
touchPosition = getTouchPositionOffset(e.touches[0]) touchPosition = getTouchPositionOffset(e.touches[0])
@ -221,10 +231,12 @@ class TermScreen {
touchDidMove = true touchDidMove = true
}) })
this.canvas.addEventListener('touchend', e => { this.canvas.addEventListener('touchend', e => {
if (e.touches[0]) { if (e.touches[0]) {
touchPosition = getTouchPositionOffset(e.touches[0]) touchPosition = getTouchPositionOffset(e.touches[0])
} }
if (selecting) { if (selecting) {
e.preventDefault() e.preventDefault()
selectEnd(...touchPosition) selectEnd(...touchPosition)
@ -282,12 +294,14 @@ class TermScreen {
Input.onMouseMove(...this.screenToGrid(e.offsetX, e.offsetY)) Input.onMouseMove(...this.screenToGrid(e.offsetX, e.offsetY))
} }
}) })
this.canvas.addEventListener('mouseup', e => { this.canvas.addEventListener('mouseup', e => {
if (!selecting) { if (!selecting) {
Input.onMouseUp(...this.screenToGrid(e.offsetX, e.offsetY), Input.onMouseUp(...this.screenToGrid(e.offsetX, e.offsetY),
e.button + 1) e.button + 1)
} }
}) })
this.canvas.addEventListener('wheel', e => { this.canvas.addEventListener('wheel', e => {
if (this.mouseMode.clicks) { if (this.mouseMode.clicks) {
Input.onMouseWheel(...this.screenToGrid(e.offsetX, e.offsetY), Input.onMouseWheel(...this.screenToGrid(e.offsetX, e.offsetY),
@ -297,6 +311,7 @@ class TermScreen {
e.preventDefault() e.preventDefault()
} }
}) })
this.canvas.addEventListener('contextmenu', e => { this.canvas.addEventListener('contextmenu', e => {
if (this.mouseMode.clicks) { if (this.mouseMode.clicks) {
// prevent mouse keys getting stuck // prevent mouse keys getting stuck
@ -573,7 +588,6 @@ class TermScreen {
Notify.show('Copied to clipboard') Notify.show('Copied to clipboard')
} else { } else {
Notify.show('Failed to copy') Notify.show('Failed to copy')
// unsuccessful copy
} }
document.body.removeChild(textarea) document.body.removeChild(textarea)
} }
@ -596,10 +610,8 @@ class TermScreen {
drawCellBackground ({ x, y, cellWidth, cellHeight, bg }) { drawCellBackground ({ x, y, cellWidth, cellHeight, bg }) {
const ctx = this.ctx const ctx = this.ctx
ctx.fillStyle = this.getColor(bg) ctx.fillStyle = this.getColor(bg)
ctx.clearRect(x * cellWidth, y * cellHeight, ctx.clearRect(x * cellWidth, y * cellHeight, Math.ceil(cellWidth), Math.ceil(cellHeight))
Math.ceil(cellWidth), Math.ceil(cellHeight)) ctx.fillRect(x * cellWidth, y * cellHeight, Math.ceil(cellWidth), Math.ceil(cellHeight))
ctx.fillRect(x * cellWidth, y * cellHeight,
Math.ceil(cellWidth), Math.ceil(cellHeight))
} }
drawCell ({ x, y, charSize, cellWidth, cellHeight, text, fg, bg, attrs }) { drawCell ({ x, y, charSize, cellWidth, cellHeight, text, fg, bg, attrs }) {
@ -1020,17 +1032,19 @@ class TermScreen {
} }
showNotification (text) { showNotification (text) {
console.log(`Notification: ${text}`) console.info(`Notification: ${text}`)
// TODO: request permission earlier
// the requestPermission should be user-triggered; asking upfront seems
// a little awkward
if (Notification && Notification.permission === 'granted') { if (Notification && Notification.permission === 'granted') {
let notification = new Notification('ESPTerm', { let notification = new Notification('ESPTerm', {
body: text body: text
}) })
notification.addEventListener('click', () => window.focus()) notification.addEventListener('click', () => window.focus())
} else { } else {
Notify.show(text) if (Notification && Notification.permission !== 'denied') {
Notification.requestPermission()
} else {
// Fallback using the built-in notification balloon
Notify.show(text)
}
} }
} }
@ -1044,17 +1058,21 @@ class TermScreen {
case 'S': case 'S':
this.loadContent(content) this.loadContent(content)
break break
case 'T': case 'T':
this.loadLabels(content) this.loadLabels(content)
break break
case 'B': case 'B':
this.beep() this.beep()
break break
case 'G': case 'G':
this.showNotification(content) this.showNotification(content)
break break
default: default:
console.warn(`Bad data message type; ignoring.\n${JSON.stringify(content)}`) console.warn(`Bad data message type; ignoring.\n${JSON.stringify(str)}`)
} }
} }

@ -71,7 +71,7 @@ window.TermUpl = (function () {
return return
} }
if (inline_pos == 0) { if (inline_pos === 0) {
curLine = lines[line_i++] + nl_str curLine = lines[line_i++] + nl_str
} }

@ -25,7 +25,7 @@ function bool (x) {
*/ */
function cr (hdl) { function cr (hdl) {
return function (e) { return function (e) {
if (e.which == 10 || e.which == 13 || e.which == 32) { if (e.which === 10 || e.which === 13 || e.which === 32) {
hdl() hdl()
} }
} }
@ -33,7 +33,7 @@ function cr (hdl) {
/** Extend an objects with options */ /** Extend an objects with options */
function extend (defaults, options) { function extend (defaults, options) {
var target = {} let target = {}
Object.keys(defaults).forEach(function (k) { Object.keys(defaults).forEach(function (k) {
target[k] = defaults[k] target[k] = defaults[k]
@ -53,7 +53,7 @@ function rgxe (str) {
/** Format number to N decimal places, output as string */ /** Format number to N decimal places, output as string */
function numfmt (x, places) { function numfmt (x, places) {
var pow = Math.pow(10, places) const pow = Math.pow(10, places)
return Math.round(x * pow) / pow return Math.round(x * pow) / pow
} }

@ -12,11 +12,11 @@
$('#sta_ssid').val(name) $('#sta_ssid').val(name)
$('#sta_password').val(password) $('#sta_password').val(password)
$('#sta-nw').toggleClass('hidden', name.length == 0) $('#sta-nw').toggleClass('hidden', name.length === 0)
$('#sta-nw-nil').toggleClass('hidden', name.length > 0) $('#sta-nw-nil').toggleClass('hidden', name.length > 0)
$('#sta-nw .essid').html(e(name)) $('#sta-nw .essid').html(e(name))
const nopw = undef(password) || password.length == 0 const nopw = undef(password) || password.length === 0
$('#sta-nw .passwd').toggleClass('hidden', nopw) $('#sta-nw .passwd').toggleClass('hidden', nopw)
$('#sta-nw .nopasswd').toggleClass('hidden', !nopw) $('#sta-nw .nopasswd').toggleClass('hidden', !nopw)
$('#sta-nw .ip').html(ip.length > 0 ? tr('wifi.connected_ip_is') + ip : tr('wifi.not_conn')) $('#sta-nw .ip').html(ip.length > 0 ? tr('wifi.connected_ip_is') + ip : tr('wifi.not_conn'))
@ -34,7 +34,7 @@
// } // }
// }; // };
if (status != 200) { if (status !== 200) {
// bad response // bad response
rescan(5000) // wait 5sm then retry rescan(5000) // wait 5sm then retry
return return
@ -77,7 +77,7 @@
.addClass('AP') .addClass('AP')
// mark current SSID // mark current SSID
if (ap.essid == curSSID) { if (ap.essid === curSSID) {
$item.addClass('selected') $item.addClass('selected')
} }

Loading…
Cancel
Save