| 99 | |
| 100 | // extract button data from buttonCode |
| 101 | function evalButtonCode(code: number): any { |
| 102 | if (code > 255) { |
| 103 | return { button: 'invalid', action: 'invalid', modifier: {} }; |
| 104 | } |
| 105 | const modifier = { shift: !!(code & 4), meta: !!(code & 8), control: !!(code & 16) }; |
| 106 | const move = code & 32; |
| 107 | let button = code & 3; |
| 108 | if (code & 128) { |
| 109 | button |= 8; |
| 110 | } |
| 111 | if (code & 64) { |
| 112 | button |= 4; |
| 113 | } |
| 114 | let actionS = 'press'; |
| 115 | let buttonS = reverseButtons[button]; |
| 116 | if (button === 3) { |
| 117 | buttonS = '<none>'; |
| 118 | actionS = 'release'; |
| 119 | } |
| 120 | if (move) { |
| 121 | actionS = 'move'; |
| 122 | } else if (4 <= button && button <= 7) { |
| 123 | buttonS = 'wheel'; |
| 124 | actionS = button === 4 ? 'up' : button === 5 ? 'down' : button === 6 ? 'left' : 'right'; |
| 125 | } |
| 126 | return { button: buttonS, action: actionS, modifier }; |
| 127 | } |
| 128 | |
| 129 | // parse a single mouse report |
| 130 | function parseReport(encoding: string, msg: number[]): { state: any, row: number, col: number } | string { |