Only drop segments whose contents are None

This commit is contained in:
Kim Silkebækken 2012-12-06 14:59:50 +01:00
parent 11ee10851c
commit 636f1719fb
2 changed files with 7 additions and 6 deletions

View File

@ -5,10 +5,10 @@ class Powerline(object):
def __init__(self, segments):
'''Create a new Powerline.
Segments that have empty contents and aren't filler segments are
Segments that aren't filler segments and whose contents aren't None are
dropped from the segment array.
'''
self.segments = [segment for segment in segments if segment['contents'] or segment['filler']]
self.segments = [segment for segment in segments if segment['contents'] is not None or segment['filler']]
def render(self, renderer, width=None):
r = renderer(self.segments)

View File

@ -6,10 +6,11 @@ from colorscheme import cterm_to_hex
def mksegment(contents=None, cterm_fg=False, cterm_bg=False, attr=False, hex_fg=False, hex_bg=False, side='l', draw_divider=True, priority=-1, filler=False):
'''Convenience wrapper for segment generation.
'''
try:
contents = unicode(contents or u'')
except UnicodeDecodeError:
contents = contents.decode('utf-8') or u''
if contents is not None or filler:
try:
contents = unicode(contents or u'')
except UnicodeDecodeError:
contents = contents.decode('utf-8') or u''
return {
'contents': contents,