1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-24 05:30:07 +08:00

Check statuslien len

This commit is contained in:
wsdjeg 2017-12-05 14:06:28 +08:00
parent ce0308cdbd
commit 9d4fcd6bcc

View File

@ -1,48 +1,75 @@
let s:self = {}
function! s:self.check_width(len, sec, winwidth) abort
return a:len + self.len(a:sec) < a:winwidth
endfunction
function! s:self.len(sec) abort
return len(substitute(a:sec, '%{.*}', '', 'g'))
endfunction
function! s:self.build(left_sections, right_sections, lsep, rsep, fname, hi_a, hi_b, hi_c, hi_z, winwidth) abort
let l = '%#' . a:hi_a . '#' . a:left_sections[0]
let l .= '%#' . a:hi_a . '_' . a:hi_b . '#' . a:lsep
let flag = 1
for sec in filter(a:left_sections[1:], '!empty(v:val)')
if flag == 1
let l .= '%#' . a:hi_b . '#' . sec
let l .= '%#' . a:hi_b . '_' . a:hi_c . '#' . a:lsep
else
let l .= '%#' . a:hi_c . '#' . sec
let l .= '%#' . a:hi_c . '_' . a:hi_b . '#' . a:lsep
endif
let flag = flag * -1
endfor
let l = l[:len(a:lsep) * -1 - 1]
if empty(a:right_sections)
if flag == 1
return l . '%#' . a:hi_c . '#'
else
return l . '%#' . a:hi_b . '#'
endif
let l = '%#' . a:hi_a . '#' . a:left_sections[0]
let l .= '%#' . a:hi_a . '_' . a:hi_b . '#' . a:lsep
let flag = 1
let len = 0
for sec in filter(a:left_sections[1:], '!empty(v:val)')
if self.check_width(len, sec, a:winwidth)
let len += self.len(sec)
if flag == 1
let l .= '%#' . a:hi_b . '#' . sec
let l .= '%#' . a:hi_b . '_' . a:hi_c . '#' . a:lsep
else
let l .= '%#' . a:hi_c . '#' . sec
let l .= '%#' . a:hi_c . '_' . a:hi_b . '#' . a:lsep
endif
let flag = flag * -1
endif
endfor
let l = l[:len(a:lsep) * -1 - 1]
if empty(a:right_sections)
if flag == 1
let l .= '%#' . a:hi_c . '_' . a:hi_z . '#' . a:lsep . a:fname . '%='
return l . '%#' . a:hi_c . '#'
else
let l .= '%#' . a:hi_b . '_' . a:hi_z . '#' . a:lsep . a:fname . '%='
return l . '%#' . a:hi_b . '#'
endif
let l .= '%#' . a:hi_b . '_' . a:hi_z . '#' . a:rsep
let flag = 1
for sec in filter(a:right_sections, '!empty(v:val)')
if flag == 1
let l .= '%#' . a:hi_b . '#' . sec
let l .= '%#' . a:hi_c . '_' . a:hi_b . '#' . a:rsep
else
let l .= '%#' . a:hi_c . '#' . sec
let l .= '%#' . a:hi_b . '_' . a:hi_c . '#' . a:rsep
endif
let flag = flag * -1
endfor
return l[:-4]
endif
if self.check_width(len, a:fname, a:winwidth)
let len += self.len(a:fname)
if flag == 1
let l .= '%#' . a:hi_c . '_' . a:hi_z . '#' . a:lsep . a:fname . '%='
else
let l .= '%#' . a:hi_b . '_' . a:hi_z . '#' . a:lsep . a:fname . '%='
endif
else
if flag == 1
let l .= '%#' . a:hi_c . '_' . a:hi_z . '#' . a:lsep . '%='
else
let l .= '%#' . a:hi_b . '_' . a:hi_z . '#' . a:lsep . '%='
endif
endif
let l .= '%#' . a:hi_b . '_' . a:hi_z . '#' . a:rsep
let flag = 1
for sec in filter(a:right_sections, '!empty(v:val)')
if self.check_width(len, sec, a:winwidth)
let len += self.len(sec)
if flag == 1
let l .= '%#' . a:hi_b . '#' . sec
let l .= '%#' . a:hi_c . '_' . a:hi_b . '#' . a:rsep
else
let l .= '%#' . a:hi_c . '#' . sec
let l .= '%#' . a:hi_b . '_' . a:hi_c . '#' . a:rsep
endif
let flag = flag * -1
endif
endfor
return l[:-4]
endfunction
function! SpaceVim#api#vim#statusline#get() abort
return deepcopy(s:self)
return deepcopy(s:self)
endfunction
" vim:set et sw=2 cc=80 nowrap: