(encoding: string, msg: number[])
| 128 | |
| 129 | // parse a single mouse report |
| 130 | function parseReport(encoding: string, msg: number[]): { state: any, row: number, col: number } | string { |
| 131 | let sReport: string; |
| 132 | let buttonCode: number; |
| 133 | let row: number; |
| 134 | let col: number; |
| 135 | // unpack msg |
| 136 | const report = String.fromCharCode.apply(null, msg); |
| 137 | // skip non mouse reports |
| 138 | if (!report || report[0] !== '\x1b') { |
| 139 | return report; |
| 140 | } |
| 141 | switch (encoding) { |
| 142 | case 'DEFAULT': |
| 143 | return { |
| 144 | state: evalButtonCode(report.charCodeAt(3) - 32), |
| 145 | col: report.charCodeAt(4) - 32, |
| 146 | row: report.charCodeAt(5) - 32 |
| 147 | }; |
| 148 | case 'SGR': |
| 149 | sReport = report.slice(3, -1); |
| 150 | [buttonCode, col, row] = sReport.split(';').map(el => parseInt(el)); |
| 151 | const state = evalButtonCode(buttonCode); |
| 152 | if (report[report.length - 1] === 'm') { |
| 153 | state.action = 'release'; |
| 154 | } |
| 155 | return { state, row, col }; |
| 156 | default: |
| 157 | return { |
| 158 | state: evalButtonCode(report.charCodeAt(3) - 32), |
| 159 | col: report.charCodeAt(4) - 32, |
| 160 | row: report.charCodeAt(5) - 32 |
| 161 | }; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | test.describe('Mouse Tracking Tests', () => { |
| 166 | test.beforeAll(async () => { |
no test coverage detected