MCPcopy
hub / github.com/xtermjs/xterm.js / parseReport

Function parseReport

test/playwright/MouseTracking.test.ts:130–163  ·  view source on GitHub ↗
(encoding: string, msg: number[])

Source from the content-addressed store, hash-verified

128
129// parse a single mouse report
130function 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
165test.describe('Mouse Tracking Tests', () => {
166 test.beforeAll(async () => {

Callers 1

getReportsFunction · 0.85

Calls 3

applyMethod · 0.80
evalButtonCodeFunction · 0.70
mapMethod · 0.65

Tested by

no test coverage detected