added option to not capture f5,f11,f12

cpsdqs/unified-input
Ondřej Hruška 7 years ago
parent 8548c619d8
commit bdadb9b532
  1. 13
      _debug_replacements.php
  2. 5
      js/term.js
  3. 57
      js/term_input.js
  4. 1
      lang/en.php
  5. 6
      pages/cfg_term.php
  6. 6
      pages/term.php

@ -7,13 +7,15 @@
*/
$vers = '???';
$f = file_get_contents(__DIR__ . '/../user/version.h');
preg_match_all('/#define FW_V_.*? (\d+)/', $f, $vm);
$versfn = __DIR__ . '/../user/version.h';
if (file_exists($versfn)) {
$f = file_get_contents($versfn);
preg_match_all('/#define FW_V_.*? (\d+)/', $f, $vm);
#define FW_V_MAJOR 1
#define FW_V_MINOR 0
#define FW_V_PATCH 0
$vers = $vm[1][0].'.'.$vm[1][1].'.'.$vm[1][2];
$vers = $vm[1][0] . '.' . $vm[1][1] . '.' . $vm[1][2];
}
return [
'term_title' => ESP_DEMO ? 'ESPTerm Web UI Demo' : 'ESPTerm local debug',
@ -29,6 +31,7 @@ return [
'bm4' => '',
'bm5' => '05',
'labels_seq' => ESP_DEMO ? 'TESPTerm Web UI DemoOKCancelHelp' : 'TESPTerm local debugOKCancelHelp',
'want_all_fn' => '0',
'parser_tout_ms' => 10,
'display_tout_ms' => 15,
@ -55,7 +58,7 @@ return [
'time' => date('G:i'),
'vers_httpd' => '0.4',
'vers_sdk' => '010502',
'githubrepo' => 'https://github.com/MightyPork/esp-vt100-firmware',
'githubrepo' => 'https://github.com/espterm/espterm-firmware',
'ap_dhcp_time' => '120',
'ap_dhcp_start' => '192.168.4.100',

@ -1,5 +1,6 @@
/** Init the terminal sub-module - called from HTML */
window.termInit = function (labels, theme) {
window.termInit = function (opts) {
let { labels, theme, allFn } = opts
const screen = new TermScreen()
const conn = Conn(screen)
const input = Input(conn)
@ -8,7 +9,7 @@ window.termInit = function (labels, theme) {
screen.input = input
conn.init()
input.init()
input.init({ allFn })
termUpload.init()
Notify.init()

@ -15,7 +15,7 @@
* m - mouse move
*/
window.Input = function (conn) {
let opts = {
let cfg = {
np_alt: false,
cu_alt: false,
fn_alt: false,
@ -37,24 +37,24 @@ window.Input = function (conn) {
/** Fn alt choice for key message */
function fa (alt, normal) {
return opts.fn_alt ? alt : normal
return cfg.fn_alt ? alt : normal
}
/** Cursor alt choice for key message */
function ca (alt, normal) {
return opts.cu_alt ? alt : normal
return cfg.cu_alt ? alt : normal
}
/** Numpad alt choice for key message */
function na (alt, normal) {
return opts.np_alt ? alt : normal
return cfg.np_alt ? alt : normal
}
function _bindFnKeys () {
function _bindFnKeys (allFn) {
const keymap = {
'tab': '\x09',
'backspace': '\x08',
'enter': opts.crlf_mode ? '\x0d\x0a' : '\x0d',
'enter': cfg.crlf_mode ? '\x0d\x0a' : '\x0d',
'ctrl+enter': '\x0a',
'esc': '\x1b',
'up': ca('\x1bOA', '\x1b[A'),
@ -109,7 +109,12 @@ window.Input = function (conn) {
// we don't implement numlock key (should change in numpad_alt mode, but it's even more useless than the rest)
}
const blacklist = [
'f5', 'f11', 'f12', 'shift+f5'
]
for (let k in keymap) {
if (!allFn && blacklist.includes(k)) continue
if (keymap.hasOwnProperty(k)) {
bind(k, keymap[k])
}
@ -127,17 +132,19 @@ window.Input = function (conn) {
key.unbind(combo)
key(combo, function (e) {
if (opts.no_keys) return
if (cfg.no_keys) return
e.preventDefault()
sendStrMsg(str)
})
}
/** Bind/rebind key messages */
function _initKeys () {
function _initKeys (opts) {
let { allFn } = opts
// This takes care of text characters typed
window.addEventListener('keypress', function (evt) {
if (opts.no_keys) return
if (cfg.no_keys) return
let str = ''
if (evt.key) str = evt.key
else if (evt.which) str = String.fromCodePoint(evt.which)
@ -185,7 +192,7 @@ window.Input = function (conn) {
bind('⌘+backspace', '\x15') // ⌘⌫ to delete to the beginning of a line (possibly ^U)
/* eslint-enable */
_bindFnKeys()
_bindFnKeys(allFn)
}
// mouse button states
@ -194,8 +201,8 @@ window.Input = function (conn) {
let mb3 = 0
/** Init the Input module */
function init () {
_initKeys()
function init (opts) {
_initKeys(opts)
// Button presses
$('#action-buttons button').forEach(function (s) {
@ -235,11 +242,11 @@ window.Input = function (conn) {
/** Enable alternate key modes (cursors, numpad, fn) */
setAlts: function (cu, np, fn, crlf) {
if (opts.cu_alt !== cu || opts.np_alt !== np || opts.fn_alt !== fn || opts.crlf_mode !== crlf) {
opts.cu_alt = cu
opts.np_alt = np
opts.fn_alt = fn
opts.crlf_mode = crlf
if (cfg.cu_alt !== cu || cfg.np_alt !== np || cfg.fn_alt !== fn || cfg.crlf_mode !== crlf) {
cfg.cu_alt = cu
cfg.np_alt = np
cfg.fn_alt = fn
cfg.crlf_mode = crlf
// rebind keys - codes have changed
_bindFnKeys()
@ -247,20 +254,20 @@ window.Input = function (conn) {
},
setMouseMode: function (click, move) {
opts.mt_click = click
opts.mt_move = move
cfg.mt_click = click
cfg.mt_move = move
},
// Mouse events
onMouseMove: function (x, y) {
if (!opts.mt_move) return
if (!cfg.mt_move) return
const b = mb1 ? 1 : mb2 ? 2 : mb3 ? 3 : 0
const m = packModifiersForMouse()
conn.send('m' + encode2B(y) + encode2B(x) + encode2B(b) + encode2B(m))
},
onMouseDown: function (x, y, b) {
if (!opts.mt_click) return
if (!cfg.mt_click) return
if (b > 3 || b < 1) return
const m = packModifiersForMouse()
conn.send('p' + encode2B(y) + encode2B(x) + encode2B(b) + encode2B(m))
@ -268,7 +275,7 @@ window.Input = function (conn) {
},
onMouseUp: function (x, y, b) {
if (!opts.mt_click) return
if (!cfg.mt_click) return
if (b > 3 || b < 1) return
const m = packModifiersForMouse()
conn.send('r' + encode2B(y) + encode2B(x) + encode2B(b) + encode2B(m))
@ -276,7 +283,7 @@ window.Input = function (conn) {
},
onMouseWheel: function (x, y, dir) {
if (!opts.mt_click) return
if (!cfg.mt_click) return
// -1 ... btn 4 (away from user)
// +1 ... btn 5 (towards user)
const m = packModifiersForMouse()
@ -286,11 +293,11 @@ window.Input = function (conn) {
},
mouseTracksClicks: function () {
return opts.mt_click
return cfg.mt_click
},
blockKeys: function (yes) {
opts.no_keys = yes
cfg.no_keys = yes
}
}
}

@ -60,6 +60,7 @@ return [
'term.show_buttons' => 'Show buttons',
'term.loopback' => 'Local Echo',
'term.crlf_mode' => 'Enter sends CR+LF',
'term.want_all_fn' => 'Capture all keys<br>(F5, F11, F12…)',
'term.button_msgs' => 'Button codes<br>(ASCII, dec, CSV)',
'cursor.block_blink' => 'Block, blinking',

@ -165,6 +165,12 @@
<input type="hidden" id="fn_alt_mode" name="fn_alt_mode" value="%fn_alt_mode%">
</div>
<div class="Row checkbox" >
<label><?= tr('term.want_all_fn') ?></label><!--
--><span class="box" tabindex=0 role=checkbox></span>
<input type="hidden" id="want_all_fn" name="want_all_fn" value="%want_all_fn%">
</div>
<div class="Row checkbox" >
<label><?= tr('term.crlf_mode') ?></label><!--
--><span class="box" tabindex=0 role=checkbox></span>

@ -72,7 +72,11 @@
<script>
try {
window.noAutoShow = true;
termInit('%j:labels_seq%', +'%theme%');
termInit({
labels: '%j:labels_seq%',
theme: +'%theme%',
allFn: !!+'%want_all_fn%',
});
} catch(e) {
console.error(e);
<?php if (!DEBUG): ?>

Loading…
Cancel
Save