Improve error reporting: do not fail on one segment in theme.py
This commit is contained in:
parent
dbc994887d
commit
e1e591fedd
|
@ -220,6 +220,30 @@ def process_segment(pl, side, segment_info, parsed_segments, segment, mode, colo
|
|||
|
||||
always_true = lambda pl, segment_info, mode: True
|
||||
|
||||
get_fallback_segment = {
|
||||
'name': 'fallback',
|
||||
'type': 'string',
|
||||
'highlight_group': 'background',
|
||||
'divider_highlight_group': None,
|
||||
'before': None,
|
||||
'after': None,
|
||||
'contents': '',
|
||||
'priority': None,
|
||||
'draw_soft_divider': True,
|
||||
'draw_hard_divider': True,
|
||||
'draw_inner_divider': True,
|
||||
'display_condition': always_true,
|
||||
'width': None,
|
||||
'align': None,
|
||||
'expand': None,
|
||||
'truncate': None,
|
||||
'startup': None,
|
||||
'shutdown': None,
|
||||
'_rendered_raw': '',
|
||||
'_rendered_hl': '',
|
||||
'_len': None,
|
||||
'_contents_len': None,
|
||||
}.copy
|
||||
|
||||
def gen_segment_getter(pl, ext, common_config, theme_configs, default_module, get_module_attr, top_theme):
|
||||
data = {
|
||||
|
|
|
@ -3,8 +3,8 @@ from __future__ import (unicode_literals, division, absolute_import, print_funct
|
|||
|
||||
import itertools
|
||||
|
||||
from powerline.segment import gen_segment_getter, process_segment
|
||||
from powerline.lib.unicode import u
|
||||
from powerline.segment import gen_segment_getter, process_segment, get_fallback_segment
|
||||
from powerline.lib.unicode import u, safe_unicode
|
||||
|
||||
|
||||
def requires_segment_info(func):
|
||||
|
@ -147,23 +147,35 @@ class Theme(object):
|
|||
)
|
||||
for segment in parsed_segments:
|
||||
self.pl.prefix = segment['name']
|
||||
width = segment['width']
|
||||
align = segment['align']
|
||||
if width == 'auto' and segment['expand'] is None:
|
||||
segment['expand'] = expand_functions.get(align)
|
||||
if segment['expand'] is None:
|
||||
self.pl.error('Align argument must be “r”, “l” or “c”, not “{0}”', align)
|
||||
try:
|
||||
width = segment['width']
|
||||
align = segment['align']
|
||||
if width == 'auto' and segment['expand'] is None:
|
||||
segment['expand'] = expand_functions.get(align)
|
||||
if segment['expand'] is None:
|
||||
self.pl.error('Align argument must be “r”, “l” or “c”, not “{0}”', align)
|
||||
|
||||
segment['contents'] = segment['before'] + u(segment['contents'] if segment['contents'] is not None else '') + segment['after']
|
||||
# Align segment contents
|
||||
if segment['width'] and segment['width'] != 'auto':
|
||||
if segment['align'] == 'l':
|
||||
segment['contents'] = segment['contents'].ljust(segment['width'])
|
||||
elif segment['align'] == 'r':
|
||||
segment['contents'] = segment['contents'].rjust(segment['width'])
|
||||
elif segment['align'] == 'c':
|
||||
segment['contents'] = segment['contents'].center(segment['width'])
|
||||
# We need to yield a copy of the segment, or else mode-dependent
|
||||
# segment contents can’t be cached correctly e.g. when caching
|
||||
# non-current window contents for vim statuslines
|
||||
yield segment.copy()
|
||||
try:
|
||||
segment['contents'] = segment['before'] + u(
|
||||
segment['contents'] if segment['contents'] is not None else ''
|
||||
) + segment['after']
|
||||
except Exception as e:
|
||||
self.pl.exception('Failed to compute segment contents: {0}', str(e))
|
||||
segment['contents'] = safe_unicode(segment.get('contents'))
|
||||
# Align segment contents
|
||||
if segment['width'] and segment['width'] != 'auto':
|
||||
if segment['align'] == 'l':
|
||||
segment['contents'] = segment['contents'].ljust(segment['width'])
|
||||
elif segment['align'] == 'r':
|
||||
segment['contents'] = segment['contents'].rjust(segment['width'])
|
||||
elif segment['align'] == 'c':
|
||||
segment['contents'] = segment['contents'].center(segment['width'])
|
||||
# We need to yield a copy of the segment, or else mode-dependent
|
||||
# segment contents can’t be cached correctly e.g. when caching
|
||||
# non-current window contents for vim statuslines
|
||||
yield segment.copy()
|
||||
except Exception as e:
|
||||
self.pl.exception('Failed to compute segment: {0}', str(e))
|
||||
fallback = get_fallback_segment()
|
||||
fallback.update(side=side)
|
||||
yield fallback
|
||||
|
|
Loading…
Reference in New Issue