Assume highlight group is always an iterable
According to the documentation and linter `'highlight_group': 'string'` was not correct even at the current stage, but it worked. This commit fixes this situation.
This commit is contained in:
parent
adc08d0cd8
commit
667cd4bce5
|
@ -32,14 +32,6 @@ def pick_gradient_value(grad_list, gradient_level):
|
|||
return grad_list[int(round(gradient_level * (len(grad_list) - 1) / 100))]
|
||||
|
||||
|
||||
def hl_iter(value):
|
||||
if type(value) is list:
|
||||
for v in value:
|
||||
yield v
|
||||
else:
|
||||
yield value
|
||||
|
||||
|
||||
class Colorscheme(object):
|
||||
def __init__(self, colorscheme_config, colors_config):
|
||||
'''Initialize a colorscheme.'''
|
||||
|
@ -105,12 +97,12 @@ class Colorscheme(object):
|
|||
|
||||
def get_highlighting(self, groups, mode, gradient_level=None):
|
||||
trans = self.translations.get(mode, {})
|
||||
for group in hl_iter(groups):
|
||||
for group in groups:
|
||||
group_props = self.get_group_props(mode, trans, group)
|
||||
if group_props:
|
||||
break
|
||||
else:
|
||||
raise KeyError('Highlighting groups not found in colorscheme: ' + ', '.join(hl_iter(groups)))
|
||||
raise KeyError('Highlighting groups not found in colorscheme: ' + ', '.join(groups))
|
||||
|
||||
if gradient_level is None:
|
||||
pick_color = self.colors.__getitem__
|
||||
|
|
|
@ -142,7 +142,7 @@ def set_segment_highlighting(pl, colorscheme, segment):
|
|||
)
|
||||
if segment['divider_highlight_group']:
|
||||
segment['divider_highlight'] = colorscheme.get_highlighting(
|
||||
segment['divider_highlight_group'],
|
||||
(segment['divider_highlight_group'],),
|
||||
segment['mode']
|
||||
)
|
||||
else:
|
||||
|
|
|
@ -750,7 +750,7 @@ def user(pl, segment_info=None, hide_user=None):
|
|||
euid = _geteuid()
|
||||
return [{
|
||||
'contents': username,
|
||||
'highlight_group': 'user' if euid != 0 else ['superuser', 'user'],
|
||||
'highlight_group': ['user'] if euid != 0 else ['superuser', 'user'],
|
||||
}]
|
||||
if 'psutil' not in globals():
|
||||
user = requires_segment_info(user)
|
||||
|
@ -966,7 +966,7 @@ class EmailIMAPSegment(KwThreadedSegment):
|
|||
elif type(unread_count) != int or not max_msgs:
|
||||
return [{
|
||||
'contents': str(unread_count),
|
||||
'highlight_group': 'email_alert',
|
||||
'highlight_group': ['email_alert'],
|
||||
}]
|
||||
else:
|
||||
return [{
|
||||
|
|
|
@ -29,7 +29,7 @@ def last_status(pl, segment_info):
|
|||
'''
|
||||
if not segment_info['args'].last_exit_code:
|
||||
return None
|
||||
return [{'contents': str(segment_info['args'].last_exit_code), 'highlight_group': 'exit_fail'}]
|
||||
return [{'contents': str(segment_info['args'].last_exit_code), 'highlight_group': ['exit_fail']}]
|
||||
|
||||
|
||||
@requires_segment_info
|
||||
|
@ -40,8 +40,14 @@ def last_pipe_status(pl, segment_info):
|
|||
'''
|
||||
last_pipe_status = segment_info['args'].last_pipe_status
|
||||
if any(last_pipe_status):
|
||||
return [{'contents': str(status), 'highlight_group': 'exit_fail' if status else 'exit_success', 'draw_inner_divider': True}
|
||||
for status in last_pipe_status]
|
||||
return [
|
||||
{
|
||||
'contents': str(status),
|
||||
'highlight_group': ['exit_fail' if status else 'exit_success'],
|
||||
'draw_inner_divider': True
|
||||
}
|
||||
for status in last_pipe_status
|
||||
]
|
||||
else:
|
||||
return None
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ class TestShell(TestCase):
|
|||
pl = Pl()
|
||||
segment_info = {'args': Args(last_exit_code=10)}
|
||||
self.assertEqual(shell.last_status(pl=pl, segment_info=segment_info), [
|
||||
{'contents': '10', 'highlight_group': 'exit_fail'}
|
||||
{'contents': '10', 'highlight_group': ['exit_fail']}
|
||||
])
|
||||
segment_info['args'].last_exit_code = 0
|
||||
self.assertEqual(shell.last_status(pl=pl, segment_info=segment_info), None)
|
||||
|
@ -45,9 +45,9 @@ class TestShell(TestCase):
|
|||
self.assertEqual(shell.last_pipe_status(pl=pl, segment_info=segment_info), None)
|
||||
segment_info['args'].last_pipe_status = [0, 2, 0]
|
||||
self.assertEqual(shell.last_pipe_status(pl=pl, segment_info=segment_info), [
|
||||
{'contents': '0', 'highlight_group': 'exit_success', 'draw_inner_divider': True},
|
||||
{'contents': '2', 'highlight_group': 'exit_fail', 'draw_inner_divider': True},
|
||||
{'contents': '0', 'highlight_group': 'exit_success', 'draw_inner_divider': True}
|
||||
{'contents': '0', 'highlight_group': ['exit_success'], 'draw_inner_divider': True},
|
||||
{'contents': '2', 'highlight_group': ['exit_fail'], 'draw_inner_divider': True},
|
||||
{'contents': '0', 'highlight_group': ['exit_success'], 'draw_inner_divider': True}
|
||||
])
|
||||
|
||||
def test_jobnum(self):
|
||||
|
@ -335,10 +335,10 @@ class TestCommon(TestCase):
|
|||
with replace_attr(common, 'psutil', new_psutil):
|
||||
with replace_attr(common, '_geteuid', lambda: 5):
|
||||
self.assertEqual(common.user(pl=pl, segment_info=segment_info), [
|
||||
{'contents': 'def', 'highlight_group': 'user'}
|
||||
{'contents': 'def', 'highlight_group': ['user']}
|
||||
])
|
||||
self.assertEqual(common.user(pl=pl, segment_info=segment_info, hide_user='abc'), [
|
||||
{'contents': 'def', 'highlight_group': 'user'}
|
||||
{'contents': 'def', 'highlight_group': ['user']}
|
||||
])
|
||||
self.assertEqual(common.user(pl=pl, segment_info=segment_info, hide_user='def'), None)
|
||||
with replace_attr(common, '_geteuid', lambda: 0):
|
||||
|
|
Loading…
Reference in New Issue