Skip to content

Commit

Permalink
Devtool: Add small utility to log keys
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed Jan 7, 2024
1 parent 244e9e8 commit 77f9ef3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tools/keys.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as readline from 'node:readline';

function handler(input, key) {
rl.output.write(JSON.stringify(key, null, 2) + `\n`);
if (key.ctrl && key.name === 'c') {
rl.input.removeListener('keypress', handler);
rl.close();
}
}

const rl = readline.createInterface({
terminal: true,
input: process.stdin,
output: process.stdout,
});

rl.input.on('keypress', handler);
console.log('Press any key...');

0 comments on commit 77f9ef3

Please sign in to comment.