From 033afade95b89eafe2a619993e06438f8805e5ec Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 20 Jan 2013 02:15:10 +0400 Subject: [PATCH] Fix highlighting when there are only 2 segments in theme Here are two fixes: - defaultdict makes it not throw KeyErrors. - Replacing (False, False) with False makes it not throw vim.error (no color ctermbg=False) --- powerline/renderers/terminal.py | 4 ++-- powerline/renderers/tmux.py | 4 ++-- powerline/theme.py | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/powerline/renderers/terminal.py b/powerline/renderers/terminal.py index 023a73c8..9f3c76de 100644 --- a/powerline/renderers/terminal.py +++ b/powerline/renderers/terminal.py @@ -26,12 +26,12 @@ class TerminalRenderer(Renderer): ''' ansi = [] if fg is not None: - if fg[0] is False: + if fg is False or fg[0] is False: ansi += [39] else: ansi += [38, 5, fg[0]] if bg is not None: - if bg[0] is False: + if bg is False or bg[0] is False: ansi += [49] else: ansi += [48, 5, bg[0]] diff --git a/powerline/renderers/tmux.py b/powerline/renderers/tmux.py index c0112edb..1b2a93a2 100644 --- a/powerline/renderers/tmux.py +++ b/powerline/renderers/tmux.py @@ -12,12 +12,12 @@ class TmuxRenderer(Renderer): return '' tmux_attr = [] if fg is not None: - if fg[0] is False: + if fg is False or fg[0] is False: tmux_attr += ['fg=default'] else: tmux_attr += ['fg=colour' + str(fg[0])] if bg is not None: - if bg[0] is False: + if bg is False or bg[0] is False: tmux_attr += ['bg=default'] else: tmux_attr += ['bg=colour' + str(bg[0])] diff --git a/powerline/theme.py b/powerline/theme.py index 7875b0fe..97811b19 100644 --- a/powerline/theme.py +++ b/powerline/theme.py @@ -2,6 +2,7 @@ import copy +from collections import defaultdict class Theme(object): def __init__(self, ext, colorscheme, theme_config, common_config, get_segment): @@ -10,7 +11,7 @@ class Theme(object): self.segments = [] self.EMPTY_SEGMENT = { 'contents': None, - 'highlight': {self.colorscheme.DEFAULT_MODE_KEY: {'fg': (False, False), 'bg': (False, False), 'attr': 0}} + 'highlight': defaultdict(lambda : {'fg': False, 'bg': False, 'attr': 0}) } for side in ['left', 'right']: self.segments.extend((get_segment(segment, side) for segment in theme_config['segments'].get(side, [])))