Update vim statusline example
The statusline example mostly works now, even with different modes. The main problem is still non-current windows, which receive the contents of the currently active window for most segments.
This commit is contained in:
parent
c6ac449af1
commit
8960d15cf5
|
@ -1,54 +1,23 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import vim
|
||||
from powerline.core import Powerline
|
||||
from powerline.ext.vim.bindings import vim_get_func
|
||||
|
||||
vim_winwidth = vim_get_func('winwidth', rettype=int)
|
||||
vim_hlexists = vim_get_func('hlexists', rettype=int)
|
||||
vim_getwinvar = vim_get_func('getwinvar')
|
||||
vim_setwinvar = vim_get_func('setwinvar')
|
||||
|
||||
created_hl_groups = []
|
||||
percent_placeholder = u''
|
||||
|
||||
pl = Powerline('vim')
|
||||
|
||||
|
||||
def statusline(winnr):
|
||||
current = vim_getwinvar(winnr, 'current')
|
||||
windata = vim_getwinvar(winnr, 'powerline')
|
||||
winwidth = vim_winwidth(winnr)
|
||||
|
||||
if current or not windata:
|
||||
mode = vim_get_func('mode')()
|
||||
if mode == 'n':
|
||||
mode = '__default__'
|
||||
|
||||
stl = pl.renderer.render(mode, winwidth)
|
||||
|
||||
vim_setwinvar(winnr, 'powerline', stl)
|
||||
else:
|
||||
if not current:
|
||||
mode = 'nc'
|
||||
stl = vim_getwinvar(winnr, 'powerline').decode('utf-8')
|
||||
|
||||
# Replace percent placeholders
|
||||
stl = stl.replace(percent_placeholder, '%%')
|
||||
statusline = pl.renderer.render(mode, winwidth)
|
||||
|
||||
# Create highlighting groups
|
||||
for hl in pl.renderer.hl_groups.values():
|
||||
if hl['name'] in created_hl_groups:
|
||||
continue
|
||||
|
||||
vim.command('hi {group} ctermfg={ctermfg} guifg={guifg} guibg={guibg} ctermbg={ctermbg} cterm={attr} gui={attr}'.format(
|
||||
group=hl['name'],
|
||||
ctermfg=hl['ctermfg'],
|
||||
guifg='#{0:06x}'.format(hl['guifg']) if hl['guifg'] != 'NONE' else 'NONE',
|
||||
ctermbg=hl['ctermbg'],
|
||||
guibg='#{0:06x}'.format(hl['guibg']) if hl['guibg'] != 'NONE' else 'NONE',
|
||||
attr=','.join(hl['attr']),
|
||||
))
|
||||
|
||||
created_hl_groups.append(hl['name'])
|
||||
|
||||
return stl
|
||||
return statusline
|
||||
|
|
Loading…
Reference in New Issue