1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-03 04:40:06 +08:00

feat(unicode#box, lsp): improve drawing_box() && workspace viewer

This commit is contained in:
Shidong Wang 2021-10-07 22:52:20 +08:00
parent cc73d9dd30
commit 6ad6022d96
No known key found for this signature in database
GPG Key ID: 41BB7053E835C848
2 changed files with 19 additions and 3 deletions

View File

@ -95,7 +95,16 @@ function! s:self.drawing_table(json, ...) abort
endfunction
" @vimlint(EVL102, 1, l:j)
function! s:self.drawing_box(data, h, w, bw) abort
" @param data: a list of string
" @param h: max height of box
" @param w: max width of box
" @param bw: cell width
" @param [opt]: a dict of options
" align: right/left/center
function! s:self.drawing_box(data, h, w, bw, ...) abort
let opt = get(a:000, 0, {
\ 'align': 'center'
\ })
if &encoding ==# 'utf-8'
let top_left_corner = '╭'
let top_right_corner = '╮'
@ -141,7 +150,13 @@ function! s:self.drawing_box(data, h, w, bw) abort
let ls = 1
let line = side
for sel in a:data
let line .=self._string.fill_middle(sel, a:bw) . side
if opt.align == 'center'
let line .=self._string.fill_middle(sel, a:bw) . side
elseif opt.align == 'right'
let line .=self._string.fill_left(sel, a:bw) . side
else
let line .=self._string.fill(sel, a:bw) . side
endif
let i += 1
if i == a:w
call add(box, line)

View File

@ -53,7 +53,8 @@ if (has('nvim-0.5.0') && s:NVIM_VERSION.is_release_version()) || has('nvim-0.6.0
endfunction
function! SpaceVim#lsp#list_workspace_folder() abort
let workspace = luaeval('vim.lsp.buf.list_workspace_folders()')
let box = s:box.drawing_box(workspace, 1, 1, 100)
let bw = max(map(deepcopy(workspace), 'strwidth(v:val)')) + 5
let box = s:box.drawing_box(workspace, 1, 1, bw, {'align' : 'left'})
echo join(box, "\n")
endfunction
function! SpaceVim#lsp#add_workspace_folder() abort