mirror of
https://github.com/amix/vimrc
synced 2025-07-12 14:15:00 +08:00
Add support for Coc.nvim.
This commit is contained in:
73
sources_non_forked/coc.nvim/bin/prompt.js
Normal file
73
sources_non_forked/coc.nvim/bin/prompt.js
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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 == '<bs>') {
|
||||
return
|
||||
}
|
||||
if (k == '<cr>') {
|
||||
process.exit()
|
||||
return
|
||||
}
|
||||
if (k == '<esc>') {
|
||||
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 '<esc>'
|
||||
}
|
||||
if (key.sequence == '\r') {
|
||||
return '<cr>'
|
||||
}
|
||||
if (key.sequence == '\t') {
|
||||
return key.shift ? '<s-tab>' : '<tab>'
|
||||
}
|
||||
// handle them can cause bug with terminal
|
||||
// if (key.name == 'backspace') {
|
||||
// return '<bs>'
|
||||
// }
|
||||
// if (key.name == 'left') {
|
||||
// return '<left>'
|
||||
// }
|
||||
// if (key.name == 'right') {
|
||||
// return '<right>'
|
||||
// }
|
||||
if (key.name == 'up') {
|
||||
return '<up>'
|
||||
}
|
||||
if (key.name == 'down') {
|
||||
return '<down>'
|
||||
}
|
||||
return ''
|
||||
}
|
12
sources_non_forked/coc.nvim/bin/terminateProcess.sh
Executable file
12
sources_non_forked/coc.nvim/bin/terminateProcess.sh
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
terminateTree() {
|
||||
for cpid in $(pgrep -P $1); do
|
||||
terminateTree $cpid
|
||||
done
|
||||
kill -9 $1 > /dev/null 2>&1
|
||||
}
|
||||
|
||||
for pid in $*; do
|
||||
terminateTree $pid
|
||||
done
|
||||
|
Reference in New Issue
Block a user