Move add_local_theme and get_theme to vim renderer

In any case for all other extensions they are useless. (Except for ipython, but
it is TODO and I am not going to use matchers this way, simple dictionary
lookup is better in this case.)
This commit is contained in:
ZyX 2013-03-09 13:30:24 +04:00
parent 657fcd1a99
commit 551a2685f4
4 changed files with 26 additions and 21 deletions

View File

@ -56,7 +56,7 @@ class Powerline(object):
'common_config': common_config,
'segment_info': self.get_segment_info(),
}
local_themes = self.get_local_themes(ext_config.get('local_themes', {}))
local_themes = self.get_local_themes(ext_config.get('local_themes'))
# Load and initialize extension renderer
renderer_module_name = renderer_module or ext
@ -125,14 +125,15 @@ class Powerline(object):
required.
:param dict local_themes:
Usually accepts ``{matcher_name : theme_name}``.
Usually accepts ``{matcher_name : theme_name}``. May also receive
None in case there is no local_themes configuration.
:return:
anything accepted by ``self.renderer.get_theme`` and processable by
``self.renderer.add_local_theme``. Renderer module is determined by
``__init__`` arguments, refer to its documentation.
'''
return {}
return None
@staticmethod
def get_segment_info():

View File

@ -18,20 +18,8 @@ class Renderer(object):
self.theme_kwargs = theme_kwargs
self.colorscheme = colorscheme
def add_local_theme(self, matcher, theme):
if matcher in self.local_themes:
raise KeyError('There is already a local theme with given matcher')
self.local_themes[matcher] = theme
def get_theme(self, matcher_info):
for matcher in self.local_themes.keys():
if matcher(matcher_info):
match = self.local_themes[matcher]
if 'config' in match:
match['theme'] = Theme(theme_config=match.pop('config'), top_theme_config=self.theme_config, **self.theme_kwargs)
return match['theme']
else:
return self.theme
return self.theme
def get_highlighting(self, segment, mode):
segment['highlight'] = self.colorscheme.get_highlighting(segment['highlight_group'], mode, segment.get('gradient_level'))

View File

@ -5,6 +5,7 @@ from __future__ import absolute_import
from powerline.bindings.vim import vim_get_func
from powerline.renderer import Renderer
from powerline.colorscheme import ATTR_BOLD, ATTR_ITALIC, ATTR_UNDERLINE
from powerline.theme import Theme
import vim
@ -24,6 +25,21 @@ class VimRenderer(Renderer):
super(VimRenderer, self).__init__(*args, **kwargs)
self.hl_groups = {}
def add_local_theme(self, matcher, theme):
if matcher in self.local_themes:
raise KeyError('There is already a local theme with given matcher')
self.local_themes[matcher] = theme
def get_theme(self, matcher_info):
for matcher in self.local_themes.keys():
if matcher(matcher_info):
match = self.local_themes[matcher]
if 'config' in match:
match['theme'] = Theme(theme_config=match.pop('config'), top_theme_config=self.theme_config, **self.theme_kwargs)
return match['theme']
else:
return self.theme
def render(self, window_id, winidx, current):
'''Render all segments.

View File

@ -65,12 +65,12 @@ class VimPowerline(Powerline):
'g:powerline_theme_overrides__' + name)
def get_local_themes(self, local_themes):
if not local_themes:
return {}
self.get_matcher = gen_matcher_getter(self.ext, self.import_paths)
r = {}
for key, local_theme_name in local_themes.items():
key = self.get_matcher(key)
r[key] = {'config': self.load_theme_config(local_theme_name)}
return r
return dict(((self.get_matcher(key), {'config': self.load_theme_config(val)})
for key, val in local_themes.items()))
def get_config_paths(self):
if vim_exists('g:powerline_config_path'):