sgr_pixels mouse report

This commit is contained in:
Jörg Breitbart
2022-09-01 00:50:11 +02:00
parent 3acf08bc0c
commit 06d6e08347
10 changed files with 172 additions and 116 deletions
+36 -20
View File
@@ -123,19 +123,19 @@ const ENC = {
row: report[5] - 32
})
],
'UTF8' : [
'\x1b[?1005h',
// format: CSI M <button + 32> <row + 32> <col + 32>
// + utf8 encoding on row/col
report => {
const sReport = report.toString(); // decode with utf8
return {
state: evalButtonCode(sReport.charCodeAt(3) - 32),
col: sReport.charCodeAt(4) - 32,
row: sReport.charCodeAt(5) - 32
};
}
],
// 'UTF8' : [
// '\x1b[?1005h',
// // format: CSI M <button + 32> <row + 32> <col + 32>
// // + utf8 encoding on row/col
// report => {
// const sReport = report.toString(); // decode with utf8
// return {
// state: evalButtonCode(sReport.charCodeAt(3) - 32),
// col: sReport.charCodeAt(4) - 32,
// row: sReport.charCodeAt(5) - 32
// };
// }
// ],
'SGR' : [
'\x1b[?1006h',
// format: CSI < Pbutton ; Prow ; Pcol M
@@ -150,14 +150,28 @@ const ENC = {
return {state, row, col};
}
],
'URXVT': [
'\x1b[?1015h',
// format: CSI <button + 32> ; Prow ; Pcol M
// 'URXVT': [
// '\x1b[?1015h',
// // format: CSI <button + 32> ; Prow ; Pcol M
// report => {
// // strip off introducer + M
// const sReport = report.toString().slice(2, -1);
// const [button, col, row] = sReport.split(';');
// return {state: evalButtonCode(button - 32), row, col};
// }
// ],
'SGR_PIXELS' : [
'\x1b[?1016h',
// format: CSI < Pbutton ; Prow ; Pcol M
report => {
// strip off introducer + M
const sReport = report.toString().slice(2, -1);
const [button, col, row] = sReport.split(';');
return {state: evalButtonCode(button - 32), row, col};
const sReport = report.toString().slice(3, -1);
const [buttonCode, col, row] = sReport.split(';');
const state = evalButtonCode(buttonCode);
if (report[report.length - 1] === 'm'.charCodeAt(0)) {
state.action = 'release';
}
return {state, row, col};
}
]
}
@@ -205,7 +219,9 @@ function applyReportData(data) {
let {state, row, col} = ENC[Object.keys(ENC)[activeEnc]][1](data);
console.log('\x1b[2KButton:', state.button, 'Action:', state.action, 'Modifier:', state.modifier, 'row:', row, 'col:', col);
// apply to cursor position
process.stdout.write(`\x1b[${row};${col}H`);
if (Object.keys(ENC)[activeEnc] !== 'SGR_PIXELS') {
process.stdout.write(`\x1b[${row};${col}H`);
}
}
printMenu();