-
Notifications
You must be signed in to change notification settings - Fork 31
UI Integration
Linwei edited this page Aug 15, 2022
·
11 revisions
Usage:
:Leaderf --nowrap task
vimrc:
function! s:lf_task_source(...)
let rows = asynctasks#source(&columns * 48 / 100)
let source = []
for row in rows
let name = row[0]
let source += [name . ' ' . row[1] . ' : ' . row[2]]
endfor
return source
endfunction
function! s:lf_task_accept(line, arg)
let pos = stridx(a:line, '<')
if pos < 0
return
endif
let name = strpart(a:line, 0, pos)
let name = substitute(name, '^\s*\(.\{-}\)\s*$', '\1', '')
if name != ''
exec "AsyncTask " . name
endif
endfunction
function! s:lf_task_digest(line, mode)
let pos = stridx(a:line, '<')
if pos < 0
return [a:line, 0]
endif
let name = strpart(a:line, 0, pos)
return [name, 0]
endfunction
function! s:lf_win_init(...)
setlocal nonumber
setlocal nowrap
endfunction
let g:Lf_Extensions = get(g:, 'Lf_Extensions', {})
let g:Lf_Extensions.task = {
\ 'source': string(function('s:lf_task_source'))[10:-3],
\ 'accept': string(function('s:lf_task_accept'))[10:-3],
\ 'get_digest': string(function('s:lf_task_digest'))[10:-3],
\ 'highlights_def': {
\ 'Lf_hl_funcScope': '^\S\+',
\ 'Lf_hl_funcDirname': '^\S\+\s*\zs<.*>\ze\s*:',
\ },
\ 'help' : 'navigate available tasks from asynctasks.vim',
\ }
Usage:
:AsyncTaskFzf
vimrc:
function! s:fzf_sink(what)
let p1 = stridx(a:what, '<')
if p1 >= 0
let name = strpart(a:what, 0, p1)
let name = substitute(name, '^\s*\(.\{-}\)\s*$', '\1', '')
if name != ''
exec "AsyncTask ". fnameescape(name)
endif
endif
endfunction
function! s:fzf_task()
let rows = asynctasks#source(&columns * 48 / 100)
let source = []
for row in rows
let name = row[0]
let source += [name . ' ' . row[1] . ' : ' . row[2]]
endfor
let opts = { 'source': source, 'sink': function('s:fzf_sink'),
\ 'options': '+m --nth 1 --inline-info --tac' }
if exists('g:fzf_layout')
for key in keys(g:fzf_layout)
let opts[key] = deepcopy(g:fzf_layout[key])
endfor
endif
call fzf#run(opts)
endfunction
command! -nargs=0 AsyncTaskFzf call s:fzf_task()
Usage:
:CocList tasks
Install:
:CocInstall coc-tasks
Initialize:
local fzf_lua = require('fzf-lua')
vim.keymap.set('n', '\\t',
function()
local rows = vim.fn['asynctasks#source'](vim.go.columns * 48 / 100)
fzf_lua.fzf_exec(function(cb)
for _, e in ipairs(rows) do
local color = fzf_lua.utils.ansi_codes
local line = color.green(e[1]) .. ' ' .. color.cyan(e[2]) .. ': ' .. color.yellow(e[3])
cb(line)
end
cb()
end,
{
actions = {
['default'] = function(selected)
local str = fzf_lua.utils.strsplit(selected[1], ' ')
local command = 'AsyncTask ' .. vim.fn.fnameescape(str[1]);
vim.api.nvim_exec(command, false)
end
},
fzf_opts = {
["--no-multi"] = '',
["--nth"] = '1',
},
winopts = {
height = 0.6,
width = 0.6,
}
})
end,
{ noremap = true, silent = true })