Remove get_segment_info and passing segment_info through globals
This commit is contained in:
parent
49b54353a1
commit
b1f9edab4c
|
@ -57,7 +57,6 @@ class Powerline(object):
|
|||
theme_kwargs = {
|
||||
'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'))
|
||||
|
@ -143,14 +142,3 @@ class Powerline(object):
|
|||
``__init__`` arguments, refer to its documentation.
|
||||
'''
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def get_segment_info():
|
||||
'''Get information for segments that require ``segment_info`` argument.
|
||||
To be overridden in subclasses.
|
||||
|
||||
:return:
|
||||
anything accepted by segments as ``segment_info`` argument. Depends
|
||||
on the segments used, refer to Powerline subclass documentation.
|
||||
'''
|
||||
return None
|
||||
|
|
|
@ -61,10 +61,7 @@ class Renderer(object):
|
|||
reached.
|
||||
'''
|
||||
theme = self.get_theme(matcher_info)
|
||||
segments = theme.get_segments(side)
|
||||
|
||||
if segment_info:
|
||||
theme.segment_info.update(segment_info)
|
||||
segments = theme.get_segments(side, segment_info)
|
||||
|
||||
# Handle excluded/included segments for the current mode
|
||||
segments = [self.get_highlighting(segment, mode) for segment in segments
|
||||
|
|
|
@ -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, run_once=False):
|
||||
def __init__(self, ext, theme_config, common_config, top_theme_config=None, run_once=False):
|
||||
self.dividers = theme_config.get('dividers', common_config['dividers'])
|
||||
self.spaces = theme_config.get('spaces', common_config['spaces'])
|
||||
self.segments = {
|
||||
|
@ -35,7 +35,6 @@ class Theme(object):
|
|||
'contents': None,
|
||||
'highlight': {'fg': False, 'bg': False, 'attr': 0}
|
||||
}
|
||||
self.segment_info = segment_info
|
||||
theme_configs = [theme_config]
|
||||
if top_theme_config:
|
||||
theme_configs.append(top_theme_config)
|
||||
|
@ -62,7 +61,7 @@ class Theme(object):
|
|||
def get_spaces(self):
|
||||
return self.spaces
|
||||
|
||||
def get_segments(self, side=None):
|
||||
def get_segments(self, side=None, segment_info=None):
|
||||
'''Return all segments.
|
||||
|
||||
Function segments are called, and all segments get their before/after
|
||||
|
@ -74,7 +73,7 @@ class Theme(object):
|
|||
if segment['type'] == 'function':
|
||||
if (hasattr(segment['contents_func'], 'powerline_requires_segment_info')
|
||||
and segment['contents_func'].powerline_requires_segment_info):
|
||||
contents = segment['contents_func'](segment_info=self.segment_info, **segment['args'])
|
||||
contents = segment['contents_func'](segment_info=segment_info, **segment['args'])
|
||||
else:
|
||||
contents = segment['contents_func'](**segment['args'])
|
||||
if contents is None:
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''Powerline prompt and statusline script.'''
|
||||
import sys
|
||||
import os
|
||||
|
||||
try:
|
||||
from powerline.shell import ShellPowerline, get_argparser
|
||||
|
@ -13,7 +14,7 @@ except ImportError:
|
|||
if __name__ == '__main__':
|
||||
args = get_argparser(description=__doc__).parse_args()
|
||||
powerline = ShellPowerline(args, run_once=True)
|
||||
rendered = powerline.renderer.render(width=args.width, side=args.side)
|
||||
rendered = powerline.renderer.render(width=args.width, side=args.side, segment_info=args)
|
||||
try:
|
||||
sys.stdout.write(rendered)
|
||||
except UnicodeEncodeError:
|
||||
|
|
|
@ -76,18 +76,20 @@ class TestConfig(TestCase):
|
|||
|
||||
def test_zsh(self):
|
||||
from powerline.shell import ShellPowerline
|
||||
powerline = ShellPowerline(Args(last_pipe_status=[1, 0], ext=['shell'], renderer_module='zsh_prompt'), run_once=False)
|
||||
powerline.renderer.render()
|
||||
powerline = ShellPowerline(Args(last_pipe_status=[1, 0], ext=['shell'], renderer_module='zsh_prompt'), run_once=False)
|
||||
powerline.renderer.render()
|
||||
args = Args(last_pipe_status=[1, 0], ext=['shell'], renderer_module='zsh_prompt')
|
||||
powerline = ShellPowerline(args, run_once=False)
|
||||
powerline.renderer.render(segment_info=args)
|
||||
powerline = ShellPowerline(args, run_once=False)
|
||||
powerline.renderer.render(segment_info=args)
|
||||
shutdown(powerline)
|
||||
|
||||
def test_bash(self):
|
||||
from powerline.shell import ShellPowerline
|
||||
powerline = ShellPowerline(Args(last_exit_code=1, ext=['shell'], renderer_module='bash_prompt', config=[('ext', {'shell': {'theme': 'default_leftonly'}})]), run_once=False)
|
||||
powerline.renderer.render()
|
||||
powerline = ShellPowerline(Args(last_exit_code=1, ext=['shell'], renderer_module='bash_prompt', config=[('ext', {'shell': {'theme': 'default_leftonly'}})]), run_once=False)
|
||||
powerline.renderer.render()
|
||||
args = Args(last_exit_code=1, ext=['shell'], renderer_module='bash_prompt', config=[('ext', {'shell': {'theme': 'default_leftonly'}})])
|
||||
powerline = ShellPowerline(args, run_once=False)
|
||||
powerline.renderer.render(segment_info=args)
|
||||
powerline = ShellPowerline(args, run_once=False)
|
||||
powerline.renderer.render(segment_info=args)
|
||||
shutdown(powerline)
|
||||
|
||||
def test_ipython(self):
|
||||
|
|
Loading…
Reference in New Issue