1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
" VimTeX - LaTeX plugin for Vim
"
" Maintainer: Karl Yngve LervÄg
" Email: karl.yngve@gmail.com
"
function! vimtex#ui#legacy#confirm(prompt) abort " {{{1
let l:prompt = type(a:prompt) == v:t_list ? a:prompt : [a:prompt]
let l:prompt[-1] .= ' [y]es/[n]o: '
while v:true
redraw!
call vimtex#ui#echo(l:prompt)
let l:input = nr2char(getchar())
if index(["\<c-c>", "\<esc>"], l:input) >= 0
break
endif
if index(['y', 'Y', 'n', 'N'], l:input) >= 0
echon l:input
sleep 75m
redraw!
break
endif
endwhile
return l:input ==? 'y'
endfunction
" }}}1
function! vimtex#ui#legacy#input(options) abort " {{{1
if g:vimtex_echo_verbose_input && !empty(a:options.info)
redraw!
call vimtex#ui#echo(a:options.info)
endif
echohl VimtexMsg
let l:input = has_key(a:options, 'completion')
\ ? input(a:options.prompt, a:options.text, a:options.completion)
\ : input(a:options.prompt, a:options.text)
echohl None
return l:input
endfunction
" }}}1
function! vimtex#ui#legacy#select(options, list) abort " {{{1
let l:length = len(a:list)
let l:digits = len(l:length)
" Use simple menu when in operator mode
if !empty(&operatorfunc)
let l:choices = map(deepcopy(a:list), { i, x -> (i+1) . ': ' . x })
let l:choice = inputlist(l:choices) - 1
return l:choice >= 0 && l:choice < l:length
\ ? [l:choice, a:list[l:choice]]
\ : [-1, '']
endif
" Create the menu
let l:menu = [a:options.prompt]
let l:format = printf('%%%dd: ', l:digits)
let l:i = 0
for l:x in a:list
let l:i += 1
call add(l:menu, [
\ ['VimtexWarning', printf(l:format, l:i)],
\ type(l:x) == v:t_dict ? l:x.name : l:x
\])
endfor
if !a:options.force_choice
call add(l:menu, [
\ ['VimtexWarning', repeat(' ', l:digits - 1) . 'x: '],
\ 'Abort'
\])
endif
" Loop to get a valid choice
let l:value = ''
while v:true
redraw!
for l:line in l:menu
call vimtex#ui#echo(l:line)
endfor
let l:choice = vimtex#ui#get_number(
\ l:length, l:digits, a:options.force_choice, v:true)
if !a:options.force_choice && l:choice == -2
break
endif
if l:choice >= 0 && l:choice < l:length
let l:value = a:list[l:choice]
break
endif
endwhile
sleep 75m
redraw!
return [l:choice, l:value]
endfunction
" }}}1
|