/* * Used for prompt popup on vim */ const readline = require("readline") const rl = readline.createInterface({ input: process.stdin, output: process.stdout, escapeCodeTimeout: 0 }) rl.setPrompt('') let value = process.argv[2] if (value) { rl.write(value) } rl.on('line', input => { let text = input.replace(/"/g, '\\"') console.log(createSequences(JSON.stringify(['call', 'CocPopupCallback', ['confirm', text]]))) process.exit() }) function createSequences(str) { return '\033]51;' + str + '\x07' } process.stdin.on('keypress', (_, key) => { if (key) { let k = getKey(key) if (k == '') { return } if (k == '') { process.exit() return } if (k == '') { console.log(createSequences(JSON.stringify(['call', 'CocPopupCallback', ['exit', '']]))) process.exit() return } if (k) { console.log(createSequences(JSON.stringify(['call', 'CocPopupCallback', ['send', k]]))) } } }) function getKey(key) { if (key.sequence == '\u001b') { return '' } if (key.sequence == '\r') { return '' } if (key.sequence == '\t') { return key.shift ? '' : '' } // handle them can cause bug with terminal // if (key.name == 'backspace') { // return '' // } // if (key.name == 'left') { // return '' // } // if (key.name == 'right') { // return '' // } if (key.name == 'up') { return '' } if (key.name == 'down') { return '' } return '' }