Add last_status and last_pipe_status segments

This commit is contained in:
ZyX 2013-01-26 18:36:39 +04:00 committed by Kim Silkebækken
parent c566064053
commit 17639a9e25
7 changed files with 39 additions and 5 deletions

View File

@ -61,6 +61,8 @@
"cwd": { "fg": "gray9", "bg": "gray4" },
"cwd:current_folder": { "fg": "gray10", "bg": "gray4", "attr": ["bold"] },
"cwd:divider": { "fg": "gray7", "bg": "gray4" },
"hostname": { "fg": "brightyellow", "bg": "mediumorange" }
"hostname": { "fg": "brightyellow", "bg": "mediumorange" },
"exit_fail": { "fg": "white", "bg": "darkestred" },
"exit_success": { "fg": "white", "bg": "darkestgreen" }
}
}

View File

@ -25,6 +25,11 @@
}
],
"right": [
{
"module": "powerline.segments.shell",
"name": "last_pipe_status",
"highlight_group": "exit_fail"
},
{
"name": "branch",
"before": " "

View File

@ -23,6 +23,11 @@
"dir_limit_depth": 3
},
"divider_highlight_group": "cwd:divider"
},
{
"name": "last_status",
"highlight_group": ["exit_fail"],
"module": "powerline.segments.shell"
}
]
}

View File

@ -11,7 +11,7 @@ from powerline.lib import underscore_to_camelcase
class Powerline(object):
def __init__(self, ext, renderer_module=None):
def __init__(self, ext, renderer_module=None, segment_info=None):
config_home = os.environ.get('XDG_CONFIG_HOME', os.path.expanduser('~/.config'))
config_path = os.path.join(config_home, 'powerline')
plugin_path = os.path.join(os.path.realpath(os.path.dirname(__file__)), 'config_files')
@ -35,6 +35,7 @@ class Powerline(object):
'ext': ext,
'colorscheme': colorscheme,
'common_config': self.config,
'segment_info': segment_info,
}
local_themes = {}
for key, local_theme_name in self.config_ext.get('local_themes', {}).items():

View File

@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
def last_status(segment_info):
return str(segment_info.last_exit_code) if segment_info.last_exit_code else None
last_status.requires_powerline_segment_info = True
def last_pipe_status(segment_info):
pipe_status = [int(status) for status in segment_info.last_pipe_status.split()]
if any(pipe_status):
return [{"contents": str(status), "highlight_group": "exit_fail" if status else "exit_success"}
for status in pipe_status]
else:
return None
last_pipe_status.requires_powerline_segment_info = True

View File

@ -12,7 +12,7 @@ except NameError:
class Theme(object):
def __init__(self, ext, colorscheme, theme_config, common_config):
def __init__(self, ext, colorscheme, theme_config, common_config, segment_info=None):
self.colorscheme = colorscheme
self.dividers = theme_config.get('dividers', common_config['dividers'])
self.segments = {
@ -23,6 +23,7 @@ class Theme(object):
'contents': None,
'highlight': defaultdict(lambda: {'fg': False, 'bg': False, 'attr': 0})
}
self.segment_info = segment_info
get_segment = Segment(ext, common_config['paths'], colorscheme, theme_config.get('default_module')).get
for side in ['left', 'right']:
self.segments[side].extend((get_segment(segment, side) for segment in theme_config['segments'].get(side, [])))
@ -41,7 +42,11 @@ class Theme(object):
parsed_segments = []
for segment in self.segments[side]:
if segment['type'] == 'function':
contents = segment['contents_func'](**segment['args'])
if (hasattr(segment['contents_func'], 'requires_powerline_segment_info')
and segment['contents_func'].requires_powerline_segment_info):
contents = segment['contents_func'](segment_info=self.segment_info, **segment['args'])
else:
contents = segment['contents_func'](**segment['args'])
if contents is None:
continue
if isinstance(contents, list):

View File

@ -20,7 +20,7 @@ parser.add_argument('--last_pipe_status', default=None)
if __name__ == '__main__':
args = parser.parse_args()
powerline = Powerline(ext=args.ext, renderer_module=args.renderer_module)
powerline = Powerline(ext=args.ext, renderer_module=args.renderer_module, segment_info=args)
rendered = powerline.renderer.render(side=args.side)
try:
sys.stdout.write(rendered)