fix general purpose test script

This commit is contained in:
Jörg Breitbart
2019-07-24 12:51:24 +02:00
parent 6391742951
commit fb38bd13cd
2 changed files with 54 additions and 30 deletions
+50 -27
View File
@@ -48,43 +48,66 @@ stdin.addListener('data', function(data) {
} }
}); });
// basic button codes (modifier keys are added on top) // button definitions
const BUTTONS = { const buttons = {
0: ['left', 'press'], '<none>': -1,
1: ['middle', 'press'], left: 0,
2: ['right', 'press'], middle: 1,
3: ['', 'release'], right: 2,
32: ['left', 'move'], released: 3,
33: ['middle', 'move'], wheelUp: 4,
34: ['right', 'move'], wheelDown: 5,
35: ['', 'move'], wheelLeft: 6,
64: ['wheel', 'up'], wheelRight: 7,
65: ['wheel', 'down'] aux1: 8,
aux2: 9,
aux3: 10,
aux4: 11,
aux5: 12,
aux6: 13,
aux7: 14,
aux8: 15
}; };
const reverseButtons = {};
for (const el in buttons) {
reverseButtons[buttons[el]] = el;
}
// extract button data from buttonCode
function evalButtonCode(code) { function evalButtonCode(code) {
// 2 bits: 0 - left, 1 - middle, 2 - right, 3 - release // more than 15 buttons are not supported
// higher bits: 4 - shift, 8 - meta, 16 - control if (code > 255) {
const modifier = {shift: !!(code & 4), meta: !!(code & 8), control: !!(code & 16)}; return {button: 'invalid', action: 'invalid', modifier: {}};
const wheel = code & 64;
let action;
let button;
if (wheel) {
action = (code & 1) ? 'down' : 'up';
button = 'wheel';
} else {
action = code & 32 ? 'move' : code === 3 ? 'release' : 'press';
code &= 3; // TODO: more than 3 buttons + wheel
button = code === 0 ? 'left' : code === 1 ? 'middle' : code === 2 ? 'right' : '<none>';
} }
return {button, action, modifier}; const modifier = {shift: !!(code & 4), meta: !!(code & 8), control: !!(code & 16)};
const move = code & 32;
let button = code & 3;
if (code & 128) {
button |= 8;
}
if (code & 64) {
button |= 4
}
let actionS = 'press';
let buttonS = reverseButtons[button];
if (button === 3) {
buttonS = '<none>';
actionS = 'release';
}
if (move) {
actionS = 'move';
} else if (4 <= button && button <= 7) {
buttonS = 'wheel';
actionS = button === 4 ? 'up' : button === 5 ? 'down' : button === 6 ? 'left' : 'right';
}
return {button: buttonS, action: actionS, modifier};
} }
// protocols // protocols
const PROTOCOLS = { const PROTOCOLS = {
'9 (X10: press only)': '\x1b[?9h', '9 (X10: press only)': '\x1b[?9h',
'1000 (VT200: press, release, wheel)': '\x1b[?1000h', '1000 (VT200: press, release, wheel)': '\x1b[?1000h',
// '1001 (VT200 highlight)': '\x1b[?1001h', // handle of backreport not implemented // '1001 (VT200 highlight)': '\x1b[?1001h', // handle of backreport - not implemented
'1002 (press, release, move on pressed, wheel)': '\x1b[?1002h', '1002 (press, release, move on pressed, wheel)': '\x1b[?1002h',
'1003 (press, relase, move, wheel)': '\x1b[?1003h' '1003 (press, relase, move, wheel)': '\x1b[?1003h'
} }
+4 -3
View File
@@ -138,11 +138,12 @@ function evalButtonCode(code: number): any {
} }
let actionS = 'press'; let actionS = 'press';
let buttonS = reverseButtons[button]; let buttonS = reverseButtons[button];
if (move) { if (button === 3) {
actionS = 'move';
} else if (button === 3) {
buttonS = '<none>'; buttonS = '<none>';
actionS = 'release'; actionS = 'release';
}
if (move) {
actionS = 'move';
} else if (4 <= button && button <= 7) { } else if (4 <= button && button <= 7) {
buttonS = 'wheel'; buttonS = 'wheel';
actionS = button === 4 ? 'up' : button === 5 ? 'down' : button === 6 ? 'left' : 'right'; actionS = button === 4 ? 'up' : button === 5 ? 'down' : button === 6 ? 'left' : 'right';