Add support for .startup and .shutdown methods
This commit is contained in:
parent
c237e66958
commit
abe0b1a647
|
@ -36,7 +36,7 @@ class Powerline(object):
|
|||
the package imported like this: ``powerline.renders.{render_module}``.
|
||||
'''
|
||||
|
||||
def __init__(self, ext, renderer_module=None):
|
||||
def __init__(self, ext, renderer_module=None, run_once=False):
|
||||
self.config_paths = self.get_config_paths()
|
||||
|
||||
# Load main config file
|
||||
|
@ -58,6 +58,7 @@ class Powerline(object):
|
|||
'ext': ext,
|
||||
'common_config': common_config,
|
||||
'segment_info': self.get_segment_info(),
|
||||
'run_once': run_once,
|
||||
}
|
||||
local_themes = self.get_local_themes(ext_config.get('local_themes'))
|
||||
|
||||
|
|
|
@ -92,4 +92,5 @@ augroup Powerline
|
|||
autocmd!
|
||||
autocmd ColorScheme * :exec s:powerline_pycmd 'powerline.renderer.reset_highlight()'
|
||||
autocmd VimEnter * :redrawstatus!
|
||||
autocmd VimLeave * :exec s:powerline_pycmd 'powerline.renderer.shutdown()'
|
||||
augroup END
|
||||
|
|
|
@ -31,6 +31,12 @@ class VimRenderer(Renderer):
|
|||
super(VimRenderer, self).__init__(*args, **kwargs)
|
||||
self.hl_groups = {}
|
||||
|
||||
def shutdown(self):
|
||||
self.theme.shutdown()
|
||||
for match in self.local_themes.values():
|
||||
if 'theme' in match:
|
||||
match['theme'].shutdown()
|
||||
|
||||
def add_local_theme(self, matcher, theme):
|
||||
if matcher in self.local_themes:
|
||||
raise KeyError('There is already a local theme with given matcher')
|
||||
|
|
|
@ -79,6 +79,8 @@ def gen_segment_getter(ext, path, theme_configs, default_module=None):
|
|||
'include_modes': segment.get('include_modes', []),
|
||||
'width': segment.get('width'),
|
||||
'align': segment.get('align', 'l'),
|
||||
'shutdown': getattr(contents_func, 'shutdown', None),
|
||||
'startup': getattr(contents_func, 'startup', None),
|
||||
'_rendered_raw': '',
|
||||
'_rendered_hl': '',
|
||||
'_len': 0,
|
||||
|
|
|
@ -17,7 +17,7 @@ class ShellPowerline(Powerline):
|
|||
def __init__(self, args):
|
||||
self.args = args
|
||||
self.theme_option = mergeargs(args.theme_option) or {}
|
||||
super(ShellPowerline, self).__init__(args.ext[0], args.renderer_module)
|
||||
super(ShellPowerline, self).__init__(args.ext[0], args.renderer_module, run_once=True)
|
||||
|
||||
def get_segment_info(self):
|
||||
return self.args
|
||||
|
|
|
@ -24,7 +24,7 @@ def requires_segment_info(func):
|
|||
|
||||
|
||||
class Theme(object):
|
||||
def __init__(self, ext, theme_config, common_config, top_theme_config=None, segment_info=None):
|
||||
def __init__(self, ext, theme_config, common_config, top_theme_config=None, segment_info=None, run_once=False):
|
||||
self.dividers = theme_config.get('dividers', common_config['dividers'])
|
||||
self.spaces = theme_config.get('spaces', common_config['spaces'])
|
||||
self.segments = {
|
||||
|
@ -42,6 +42,18 @@ class Theme(object):
|
|||
get_segment = gen_segment_getter(ext, common_config['paths'], theme_configs, theme_config.get('default_module'))
|
||||
for side in ['left', 'right']:
|
||||
self.segments[side].extend((get_segment(segment, side) for segment in theme_config['segments'].get(side, [])))
|
||||
if not run_once:
|
||||
for segment in self.segments[side]:
|
||||
if segment['startup']:
|
||||
segment['startup'](**segment['args'])
|
||||
|
||||
def shutdown(self):
|
||||
for segments in self.segments.values():
|
||||
for segment in segments:
|
||||
try:
|
||||
segment['shutdown']()
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
def get_divider(self, side='left', type='soft'):
|
||||
'''Return segment divider.'''
|
||||
|
|
Loading…
Reference in New Issue