mirror of
https://github.com/powerline/powerline.git
synced 2025-07-31 01:35:40 +02:00
Add last_status and last_pipe_status segments
This commit is contained in:
parent
c566064053
commit
17639a9e25
@ -61,6 +61,8 @@
|
|||||||
"cwd": { "fg": "gray9", "bg": "gray4" },
|
"cwd": { "fg": "gray9", "bg": "gray4" },
|
||||||
"cwd:current_folder": { "fg": "gray10", "bg": "gray4", "attr": ["bold"] },
|
"cwd:current_folder": { "fg": "gray10", "bg": "gray4", "attr": ["bold"] },
|
||||||
"cwd:divider": { "fg": "gray7", "bg": "gray4" },
|
"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" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,11 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"right": [
|
"right": [
|
||||||
|
{
|
||||||
|
"module": "powerline.segments.shell",
|
||||||
|
"name": "last_pipe_status",
|
||||||
|
"highlight_group": "exit_fail"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "branch",
|
"name": "branch",
|
||||||
"before": " "
|
"before": " "
|
||||||
|
@ -23,6 +23,11 @@
|
|||||||
"dir_limit_depth": 3
|
"dir_limit_depth": 3
|
||||||
},
|
},
|
||||||
"divider_highlight_group": "cwd:divider"
|
"divider_highlight_group": "cwd:divider"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "last_status",
|
||||||
|
"highlight_group": ["exit_fail"],
|
||||||
|
"module": "powerline.segments.shell"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ from powerline.lib import underscore_to_camelcase
|
|||||||
|
|
||||||
|
|
||||||
class Powerline(object):
|
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_home = os.environ.get('XDG_CONFIG_HOME', os.path.expanduser('~/.config'))
|
||||||
config_path = os.path.join(config_home, 'powerline')
|
config_path = os.path.join(config_home, 'powerline')
|
||||||
plugin_path = os.path.join(os.path.realpath(os.path.dirname(__file__)), 'config_files')
|
plugin_path = os.path.join(os.path.realpath(os.path.dirname(__file__)), 'config_files')
|
||||||
@ -35,6 +35,7 @@ class Powerline(object):
|
|||||||
'ext': ext,
|
'ext': ext,
|
||||||
'colorscheme': colorscheme,
|
'colorscheme': colorscheme,
|
||||||
'common_config': self.config,
|
'common_config': self.config,
|
||||||
|
'segment_info': segment_info,
|
||||||
}
|
}
|
||||||
local_themes = {}
|
local_themes = {}
|
||||||
for key, local_theme_name in self.config_ext.get('local_themes', {}).items():
|
for key, local_theme_name in self.config_ext.get('local_themes', {}).items():
|
||||||
|
16
powerline/segments/shell.py
Normal file
16
powerline/segments/shell.py
Normal 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
|
@ -12,7 +12,7 @@ except NameError:
|
|||||||
|
|
||||||
|
|
||||||
class Theme(object):
|
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.colorscheme = colorscheme
|
||||||
self.dividers = theme_config.get('dividers', common_config['dividers'])
|
self.dividers = theme_config.get('dividers', common_config['dividers'])
|
||||||
self.segments = {
|
self.segments = {
|
||||||
@ -23,6 +23,7 @@ class Theme(object):
|
|||||||
'contents': None,
|
'contents': None,
|
||||||
'highlight': defaultdict(lambda: {'fg': False, 'bg': False, 'attr': 0})
|
'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
|
get_segment = Segment(ext, common_config['paths'], colorscheme, theme_config.get('default_module')).get
|
||||||
for side in ['left', 'right']:
|
for side in ['left', 'right']:
|
||||||
self.segments[side].extend((get_segment(segment, side) for segment in theme_config['segments'].get(side, [])))
|
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 = []
|
parsed_segments = []
|
||||||
for segment in self.segments[side]:
|
for segment in self.segments[side]:
|
||||||
if segment['type'] == 'function':
|
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:
|
if contents is None:
|
||||||
continue
|
continue
|
||||||
if isinstance(contents, list):
|
if isinstance(contents, list):
|
||||||
|
@ -20,7 +20,7 @@ parser.add_argument('--last_pipe_status', default=None)
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
args = parser.parse_args()
|
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)
|
rendered = powerline.renderer.render(side=args.side)
|
||||||
try:
|
try:
|
||||||
sys.stdout.write(rendered)
|
sys.stdout.write(rendered)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user