Skip to content

Commit

Permalink
node: support node inspect, ts-node etc
Browse files Browse the repository at this point in the history
  • Loading branch information
lincheney committed Jun 26, 2023
1 parent 4b38311 commit 322df20
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions node/fzf-node-completion.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,32 @@
const child_process = require('node:child_process');
const repl = require('node:repl');

process.stdin.on('keypress', function(str, key) {
if (!repl.repl) {
return;
}
const start = repl.start;
repl.start = function(...args) {
const replServer = start(...args);
replServer.input.on('keypress', function(str, key) {
if (key.sequence == '\t') {
// sabotage the key so the repl doesn't get it
key.name = '';
key.ctrl = 1;
key.sequence = '';

if (key.sequence == '\t') {
// sabotage the key so the repl doesn't get it
key.name = '';
key.ctrl = 1;
key.sequence = '';

repl.repl.completer(repl.repl.line.slice(0, repl.repl.cursor), function(error, [completions, prefix]) {
if (completions.length == 0) {
return;
}
let stdout = prefix;
const input = completions.filter(x => x !== '').join('\n');
try {
stdout = child_process.execFileSync('rl_custom_complete', [prefix], {input, stdio: ['pipe', 'pipe', 'inherit']}).toString().trim('\n');
} catch(e) {
}
repl.repl.line = repl.repl.line.slice(0, repl.repl.cursor - prefix.length) + stdout + repl.repl.line.slice(repl.repl.cursor);
repl.repl.cursor += stdout.length - prefix.length;
// fzf will have destroyed the prompt, so fix it
repl.repl._refreshLine();
});
}
})
replServer.completer(replServer.line.slice(0, replServer.cursor), function(error, [completions, prefix]) {
if (completions.length == 0) {
return;
}
let stdout = prefix;
const input = completions.filter(x => x !== '').join('\n');
try {
stdout = child_process.execFileSync('rl_custom_complete', [prefix], {input, stdio: ['pipe', 'pipe', 'inherit']}).toString().trim('\n');
} catch(e) {
}
replServer.line = replServer.line.slice(0, replServer.cursor - prefix.length) + stdout + replServer.line.slice(replServer.cursor);
replServer.cursor += stdout.length - prefix.length;
// fzf will have destroyed the prompt, so fix it
replServer._refreshLine();
});
}
});
return replServer;
};

0 comments on commit 322df20

Please sign in to comment.