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

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

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

@ -60,6 +60,7 @@ return [
'term.show_buttons' => 'Show buttons', 'term.show_buttons' => 'Show buttons',
'term.loopback' => 'Local Echo', 'term.loopback' => 'Local Echo',
'term.crlf_mode' => 'Enter sends CR+LF', '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)', 'term.button_msgs' => 'Button codes<br>(ASCII, dec, CSV)',
'cursor.block_blink' => 'Block, blinking', 'cursor.block_blink' => 'Block, blinking',

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

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

Loading…
Cancel
Save