Always specify all keys in segment_info

This commit is contained in:
ZyX 2014-08-22 20:39:31 +04:00
parent da48e9d84e
commit 6481f1b65e
3 changed files with 25 additions and 29 deletions

View File

@ -84,36 +84,33 @@ class VimRenderer(Renderer):
def get_segment_info(self, segment_info, mode):
return segment_info or self.segment_info
def render(self, window=None, window_id=None, winnr=None):
def render(self, window=None, window_id=None, winnr=None, is_tabline=False):
'''Render all segments.'''
segment_info = self.segment_info.copy()
if window is not None:
if window is vim.current.window:
mode = vim_mode(1)
mode = mode_translations.get(mode, mode)
else:
mode = 'nc'
segment_info.update(
window=window,
mode=mode,
window_id=window_id,
winnr=winnr,
buffer=window.buffer,
tabpage=current_tabpage(),
)
segment_info['tabnr'] = segment_info['tabpage'].number
segment_info['bufnr'] = segment_info['buffer'].number
winwidth = segment_info['window'].width
matcher_info = segment_info
if window is vim.current.window:
mode = vim_mode(1)
mode = mode_translations.get(mode, mode)
else:
mode = None
winwidth = int(vim.eval('&columns'))
matcher_info = None
mode = 'nc'
segment_info.update(
window=window,
mode=mode,
window_id=window_id,
winnr=winnr,
buffer=window.buffer,
tabpage=current_tabpage(),
)
segment_info['tabnr'] = segment_info['tabpage'].number
segment_info['bufnr'] = segment_info['buffer'].number
winwidth = segment_info['window'].width
statusline = super(VimRenderer, self).render(
mode=mode,
width=winwidth,
segment_info=segment_info,
matcher_info=matcher_info,
matcher_info=(None if is_tabline else segment_info),
)
return statusline

View File

@ -4,7 +4,7 @@ from __future__ import absolute_import
import sys
from powerline.bindings.vim import vim_get_func, vim_getvar
from powerline import Powerline
from powerline import Powerline, FailedUnicode
from powerline.lib import mergedicts
import vim
from itertools import count
@ -228,15 +228,14 @@ class VimPowerline(Powerline):
def statusline(self, window_id):
window, window_id, winnr = self.win_idx(window_id) or (None, None, None)
if not window:
return 'No window {0}'.format(window_id)
return FailedUnicode('No window {0}'.format(window_id))
return self.render(window, window_id, winnr)
def tabline(self):
return self.render()
return self.render(*self.win_idx(None), is_tabline=True)
def new_window(self):
window, window_id, winnr = self.win_idx(None)
return self.render(window, window_id, winnr)
return self.render(*self.win_idx(None))
if not hasattr(vim, 'bindeval'):
# Method for PowerlinePyeval function. Is here to reduce the number of

View File

@ -53,7 +53,7 @@ class TestConfig(TestCase):
outputs[out] = (i, (args, kwargs), mode)
with vim_module._with('bufname', '/tmp/foo.txt'):
out = powerline.render()
out = powerline.render(vim_module.current.window, 1, vim_module.current.window.number, is_tabline=True)
outputs[out] = (-1, (None, None), 'tab')
with vim_module._with('globals', powerline_config_path=cfg_path):
exclude = set(('no', 'v', 'V', VBLOCK, 's', 'S', SBLOCK, 'R', 'Rv', 'c', 'cv', 'ce', 'r', 'rm', 'r?', '!'))