spacevim/bundle/vim-choosewin/autoload/choosewin/font.vim
JIe 2bb7059579
Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
init
2024-08-21 14:17:26 +08:00

116 lines
2.8 KiB
VimL

" Static Var:
" char list of ['!'..'~'].
let s:chars = map(range(33, 126), 'nr2char(v:val)')
" data file path
let s:data_large = expand("<sfile>:h") . '/data/large'
let s:data_small = expand("<sfile>:h") . '/data/small'
" Util:
let s:_ = choosewin#util#get()
function! s:scan_char(str, char) "{{{1
" Return List of index where char mached to string
" ex)
" s:scan_char(' ## ', '#') => [3, 4]
" s:scan_char(' ', '#') => []
let R = []
for [index, char] in map(split(a:str, '\zs'), '[v:key, v:val]')
if char is a:char
call add(R, index)
endif
endfor
return R
endfunction
"}}}
" Font:
function! s:font_new(data) "{{{1
" Generate Font(=Dictionary) used by Overlay.
let [line_used, col_used, pattern] = s:pattern_gen(a:data)
let height = max(line_used) + 1
let width = max(col_used)
return {
\ 'width': width,
\ 'height': height,
\ 'col_used': col_used,
\ 'line_used': line_used,
\ 'pattern': pattern,
\ }
endfunction
function! s:pattern_gen(data) "{{{1
" Return Regexp pattern font_data represent.
" This Regexp can't use without replacing special vars like '%{L+1}, %{C+1} ..'
let R = []
let line_used = []
let col_used = []
for [i, val] in map(a:data, '[v:key, s:scan_char(v:val, "#")]')
if empty(val)
continue
endif
call extend(col_used, val)
call add(line_used, i)
call add(R, s:_parse_column(i, val))
endfor
let col_used = s:_.uniq(col_used)
return [line_used, col_used, '\v' . join(R, '|')]
endfunction
function! s:_parse_column(line, column_list) "{{{1
" c_base = previous column position
let R = []
let c_previous = -1
for c in a:column_list
if c is c_previous
let R[-1] .= '.'
else
call add(R, '%{C+'. c .'}c.')
endif
let col_previous = c
endfor
let prefix = "%{L+". a:line ."}l"
return join(map(R, 'prefix . v:val'), "|")
endfunction
"}}}
" Table:
function! s:read_data(file) "{{{1
" file = font data file path
" return Dictionary where key=char, val=fontdata as List.
" {
" '!': [' ## ', ' ## ', ' ## ', ' ', ' ## '],
" '"': [' ## ## ', ' ## ## ', ' # # ', ' ', ' '],
" .......
" }
let R = {}
for c in s:chars | let R[c] = [] | endfor
let lines = readfile(a:file)
for c in s:chars
while 1
let line = remove(lines, 0)
if line =~# '\v^---'
break
endif
call add(R[c], line)
endwhile
endfor
return R
endfunction
"}}}
" API:
function! choosewin#font#small() "{{{1
return map(s:read_data(s:data_small),'s:font_new(v:val)')
endfunction
function! choosewin#font#large() "{{{1
return map(s:read_data(s:data_large),'s:font_new(v:val)')
endfunction
"}}}
" vim: foldmethod=marker