Fix segment padding

The padding argument has been removed and is now handled automatically.
Segments without dividers are not padded anymore.

This was necessary to ensure that segments are rendered correctly when
cropping segments (overriding the padding argument screwed up the
padding for segments without dividers and without padding).
This commit is contained in:
Kim Silkebækken 2012-11-14 22:37:50 +01:00
parent 89375b5c6a
commit cff4fcdd88
1 changed files with 9 additions and 11 deletions

View File

@ -37,7 +37,7 @@ class Segment:
ATTR_ITALIC = 2 ATTR_ITALIC = 2
ATTR_UNDERLINE = 4 ATTR_UNDERLINE = 4
def __init__(self, contents=None, fg=None, bg=None, attr=None, side=None, padding=None, draw_divider=None, priority=None, filler=None): def __init__(self, contents=None, fg=None, bg=None, attr=None, side=None, draw_divider=None, priority=None, filler=None):
'''Create a new Powerline segment. '''Create a new Powerline segment.
''' '''
self.parent = None self.parent = None
@ -47,7 +47,6 @@ class Segment:
self.bg = bg self.bg = bg
self.attr = attr self.attr = attr
self.side = side self.side = side
self.padding = padding
self.draw_divider = draw_divider self.draw_divider = draw_divider
self.priority = priority self.priority = priority
self.filler = filler self.filler = filler
@ -93,7 +92,6 @@ class Segment:
self.bg = lookup_attr('bg', False) self.bg = lookup_attr('bg', False)
self.attr = lookup_attr('attr', False) self.attr = lookup_attr('attr', False)
self.side = lookup_attr('side', 'l') self.side = lookup_attr('side', 'l')
self.padding = lookup_attr('padding', ' ')
self.draw_divider = lookup_attr('draw_divider', True) self.draw_divider = lookup_attr('draw_divider', True)
self.priority = lookup_attr('priority', -1) self.priority = lookup_attr('priority', -1)
self.filler = lookup_attr('filler', False) self.filler = lookup_attr('filler', False)
@ -119,8 +117,8 @@ class Segment:
This method flattens the segment and all its child segments into This method flattens the segment and all its child segments into
a one-dimensional array. It then loops through this array and compares a one-dimensional array. It then loops through this array and compares
the foreground/background colors and divider/padding properties and the foreground/background colors and divider properties and returns the
returns the rendered statusline as a string. rendered statusline as a string.
When a width is provided, low-priority segments are dropped one at When a width is provided, low-priority segments are dropped one at
a time until the line is shorter than the width, or only segments a time until the line is shorter than the width, or only segments
@ -170,12 +168,12 @@ class Segment:
# the opposite side only draw the divider if it's a hard # the opposite side only draw the divider if it's a hard
# divider # divider
if segment.side == 'l': if segment.side == 'l':
segment_format = '{segment_hl}{padding}{contents}{padding}{divider_hl}{divider}' segment_format = '{segment_hl}{outer_padding}{contents} {divider_hl}{divider} '
else: else:
segment_format = '{divider_hl}{divider}{segment_hl}{padding}{contents}{padding}' segment_format = ' {divider_hl}{divider}{segment_hl} {contents}{outer_padding}'
elif segment.contents: elif segment.contents:
# Soft divided segments # Segments without divider
segment_format = '{segment_hl}{padding}{contents}{padding}' segment_format = '{segment_hl}{contents}{outer_padding}'
else: else:
# Unknown segment type, skip it # Unknown segment type, skip it
continue continue
@ -185,20 +183,20 @@ class Segment:
# %=%< segment which disappears), so they will be skipped # %=%< segment which disappears), so they will be skipped
# when calculating the width using the raw rendering # when calculating the width using the raw rendering
rendered_raw += segment_format.format( rendered_raw += segment_format.format(
padding=segment.padding,
divider=divider, divider=divider,
contents=segment.contents, contents=segment.contents,
divider_hl='', divider_hl='',
segment_hl='', segment_hl='',
outer_padding=' ' if idx == 0 or idx == len(segments) - 1 else '',
) )
if render_highlighted is True: if render_highlighted is True:
rendered_highlighted += segment_format.format( rendered_highlighted += segment_format.format(
padding=segment.padding,
divider=divider, divider=divider,
contents=segment.contents, contents=segment.contents,
divider_hl='' if divider_type == 'soft' else renderer.hl(segment.bg, compare_segment.bg), divider_hl='' if divider_type == 'soft' else renderer.hl(segment.bg, compare_segment.bg),
segment_hl=renderer.hl(segment.fg, segment.bg, segment.attr), segment_hl=renderer.hl(segment.fg, segment.bg, segment.attr),
outer_padding=' ' if idx == 0 or idx == len(segments) - 1 else '',
) )
return { return {