Move more vim stuff into the renderer

This commit is contained in:
Kim Silkebækken 2012-12-12 18:15:21 +01:00
parent 8960d15cf5
commit 04993264e4
3 changed files with 19 additions and 26 deletions

View File

@ -1,23 +0,0 @@
# -*- coding: utf-8 -*-
from powerline.core import Powerline
from powerline.ext.vim.bindings import vim_get_func
vim_winwidth = vim_get_func('winwidth', rettype=int)
vim_getwinvar = vim_get_func('getwinvar')
vim_setwinvar = vim_get_func('setwinvar')
pl = Powerline('vim')
def statusline(winnr):
current = vim_getwinvar(winnr, 'current')
winwidth = vim_winwidth(winnr)
mode = vim_get_func('mode')()
if not current:
mode = 'nc'
statusline = pl.renderer.render(mode, winwidth)
return statusline

View File

@ -4,6 +4,8 @@
python import sys, vim, os
python sys.path.append(vim.eval('expand("<sfile>:h:h:h")'))
python from examples.vim.pl import statusline
python from powerline.core import Powerline
python pl = Powerline('vim')
if exists('*pyeval')
let s:pyeval = function('pyeval')
@ -15,7 +17,7 @@ else
endif
function! Powerline(winnr)
return s:pyeval('statusline('. a:winnr .')')
return s:pyeval('pl.renderer.render('. a:winnr .')')
endfunction
function! s:WinDoPowerline()

View File

@ -1,9 +1,15 @@
# -*- coding: utf-8 -*-
from powerline.ext.vim.bindings import vim_get_func
from powerline.renderer import Renderer
import vim
vim_mode = vim_get_func('mode')
vim_winwidth = vim_get_func('winwidth', rettype=int)
vim_getwinvar = vim_get_func('getwinvar')
vim_setwinvar = vim_get_func('setwinvar')
class VimRenderer(Renderer):
'''Powerline vim segment renderer.
@ -14,9 +20,17 @@ class VimRenderer(Renderer):
super(VimRenderer, self).__init__(theme)
self.hl_groups = {}
def render(self, mode, width=None):
statusline = super(VimRenderer, self).render(mode, width)
def render(self, winnr):
current = vim_getwinvar(winnr, 'current')
winwidth = vim_winwidth(winnr)
mode = vim_mode()
if not current:
mode = 'nc'
statusline = super(VimRenderer, self).render(mode, winwidth)
statusline = statusline.replace(self.PERCENT_PLACEHOLDER, '%%')
return statusline
def hl(self, fg=None, bg=None, attr=None):