Update vim renderer to handle all vim-specific stuff

This commit is contained in:
Kim Silkebækken 2012-12-12 12:36:27 +01:00
parent e22a9241d0
commit 32f6893189
1 changed files with 19 additions and 0 deletions

View File

@ -2,14 +2,23 @@
from powerline.renderer import Renderer
import vim
class VimRenderer(Renderer):
'''Powerline vim segment renderer.
'''
PERCENT_PLACEHOLDER = u''
def __init__(self, theme):
super(VimRenderer, self).__init__(theme)
self.hl_groups = {}
def render(self, mode, width=None):
statusline = super(VimRenderer, self).render(mode, width)
statusline = statusline.replace(self.PERCENT_PLACEHOLDER, '%%')
return statusline
def hl(self, fg=None, bg=None, attr=None):
'''Highlight a segment.
@ -57,4 +66,14 @@ class VimRenderer(Renderer):
self.hl_groups[(fg, bg, attr)] = hl_group
# Create highlighting group in vim
vim.command('hi {group} ctermfg={ctermfg} guifg={guifg} guibg={guibg} ctermbg={ctermbg} cterm={attr} gui={attr}'.format(
group=hl_group['name'],
ctermfg=hl_group['ctermfg'],
guifg='#{0:06x}'.format(hl_group['guifg']) if hl_group['guifg'] != 'NONE' else 'NONE',
ctermbg=hl_group['ctermbg'],
guibg='#{0:06x}'.format(hl_group['guibg']) if hl_group['guibg'] != 'NONE' else 'NONE',
attr=','.join(hl_group['attr']),
))
return '%#' + self.hl_groups[(fg, bg, attr)]['name'] + '#'