Purge out constants from classes, lowercase TERM_24_BIT

Remove recursive import as well
This commit is contained in:
ZyX 2013-02-11 07:43:13 +04:00
parent 21b59149bf
commit e18665c5fe
6 changed files with 30 additions and 27 deletions

View File

@ -1,13 +1,16 @@
# -*- coding: utf-8 -*-
DEFAULT_MODE_KEY = None
ATTR_BOLD = 1
ATTR_ITALIC = 2
ATTR_UNDERLINE = 4
class Colorscheme(object):
DEFAULT_MODE_KEY = '__default__'
def __init__(self, colorscheme):
'''Initialize a colorscheme.'''
self.colors = {}
self.modes_groups = {self.DEFAULT_MODE_KEY: {}}
self.modes_groups = {DEFAULT_MODE_KEY: {}}
# Create a dict of color tuples with both a cterm and hex value
for color_name, color in colorscheme['colors'].items():
@ -19,7 +22,7 @@ class Colorscheme(object):
# Create highlighting groups for all modes
for group_name, group_props in colorscheme['groups'].items():
group_attr_flag = self._get_attr_flag(group_props.get('attr', []))
self.modes_groups[self.DEFAULT_MODE_KEY][group_name] = {
self.modes_groups[DEFAULT_MODE_KEY][group_name] = {
'fg': self.colors[group_props['fg']],
'bg': self.colors[group_props['bg']],
'attr': group_attr_flag,
@ -67,7 +70,7 @@ class Colorscheme(object):
the default mode is returned.
'''
if not mode or mode not in self.modes_groups:
mode = self.DEFAULT_MODE_KEY
mode = DEFAULT_MODE_KEY
try:
return self.modes_groups[mode][group]
except TypeError:
@ -79,14 +82,13 @@ class Colorscheme(object):
def _get_attr_flag(self, attributes):
'''Convert an attribute array to a renderer flag.'''
from powerline.renderer import Renderer
attr_flag = 0
if 'bold' in attributes:
attr_flag |= Renderer.ATTR_BOLD
attr_flag |= ATTR_BOLD
if 'italic' in attributes:
attr_flag |= Renderer.ATTR_ITALIC
attr_flag |= ATTR_ITALIC
if 'underline' in attributes:
attr_flag |= Renderer.ATTR_UNDERLINE
attr_flag |= ATTR_UNDERLINE
return attr_flag
cterm_to_hex = {

View File

@ -1,21 +1,18 @@
# -*- coding: utf-8 -*-
from powerline.colorscheme import Colorscheme
from powerline.colorscheme import DEFAULT_MODE_KEY
from powerline.theme import Theme
class Renderer(object):
ATTR_BOLD = 1
ATTR_ITALIC = 2
ATTR_UNDERLINE = 4
TERM_24BIT_COLORS = False
term_truecolor = False
def __init__(self, theme_config, local_themes, theme_kwargs, term_24bit_colors=False):
self.theme = Theme(theme_config=theme_config, **theme_kwargs)
self.local_themes = local_themes
self.theme_kwargs = theme_kwargs
self.TERM_24BIT_COLORS = term_24bit_colors
self.term_truecolor = term_24bit_colors
def add_local_theme(self, matcher, theme):
if matcher in self.local_themes:
@ -92,7 +89,7 @@ class Renderer(object):
'''
segments_len = len(segments)
try:
mode = mode if mode in segments[0]['highlight'] else Colorscheme.DEFAULT_MODE_KEY
mode = mode if mode in segments[0]['highlight'] else DEFAULT_MODE_KEY
except IndexError:
pass

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from powerline.renderer import Renderer
from powerline.colorscheme import ATTR_BOLD, ATTR_ITALIC, ATTR_UNDERLINE
class PangoMarkupRenderer(Renderer):
@ -21,10 +22,10 @@ class PangoMarkupRenderer(Renderer):
if bg is not False and bg[1] is not False:
awesome_attr += ['background="#{0:06x}"'.format(bg[1])]
if attr is not None and attr is not False:
if attr & Renderer.ATTR_BOLD:
if attr & ATTR_BOLD:
awesome_attr += ['font_weight="bold"']
if attr & Renderer.ATTR_ITALIC:
if attr & ATTR_ITALIC:
awesome_attr += ['font_style="italic"']
if attr & Renderer.ATTR_UNDERLINE:
if attr & ATTR_UNDERLINE:
awesome_attr += ['underline="single"']
return '<span ' + ' '.join(awesome_attr) + '>' + contents + '</span>'

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from powerline.renderer import Renderer
from powerline.colorscheme import ATTR_BOLD, ATTR_ITALIC, ATTR_UNDERLINE
class ShellRenderer(Renderer):
@ -20,7 +21,7 @@ class ShellRenderer(Renderer):
if fg is False or fg[0] is False:
ansi += [39]
else:
if self.TERM_24BIT_COLORS:
if self.term_truecolor:
ansi += [38, 2] + list(self._int_to_rgb(fg[1]))
else:
ansi += [38, 5, fg[0]]
@ -28,7 +29,7 @@ class ShellRenderer(Renderer):
if bg is False or bg[0] is False:
ansi += [49]
else:
if self.TERM_24BIT_COLORS:
if self.term_truecolor:
ansi += [48, 2] + list(self._int_to_rgb(bg[1]))
else:
ansi += [48, 5, bg[0]]
@ -36,7 +37,7 @@ class ShellRenderer(Renderer):
if attr is False:
ansi += [22]
else:
if attr & Renderer.ATTR_BOLD:
if attr & ATTR_BOLD:
ansi += [1]
return self.escape_hl_start + '[{0}m'.format(';'.join(str(attr) for attr in ansi)) + self.escape_hl_end

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from powerline.renderer import Renderer
from powerline.colorscheme import ATTR_BOLD, ATTR_ITALIC, ATTR_UNDERLINE
class TmuxRenderer(Renderer):
@ -25,15 +26,15 @@ class TmuxRenderer(Renderer):
if attr is False:
tmux_attr += ['nobold', 'noitalics', 'nounderscore']
else:
if attr & Renderer.ATTR_BOLD:
if attr & ATTR_BOLD:
tmux_attr += ['bold']
else:
tmux_attr += ['nobold']
if attr & Renderer.ATTR_ITALIC:
if attr & ATTR_ITALIC:
tmux_attr += ['italics']
else:
tmux_attr += ['noitalics']
if attr & Renderer.ATTR_UNDERLINE:
if attr & ATTR_UNDERLINE:
tmux_attr += ['underscore']
else:
tmux_attr += ['nounderscore']

View File

@ -4,6 +4,7 @@ from __future__ import absolute_import
from powerline.bindings.vim import vim_get_func
from powerline.renderer import Renderer
from powerline.colorscheme import ATTR_BOLD, ATTR_ITALIC, ATTR_UNDERLINE
import vim
@ -79,11 +80,11 @@ class VimRenderer(Renderer):
hl_group['guibg'] = bg[1]
if attr:
hl_group['attr'] = []
if attr & self.ATTR_BOLD:
if attr & ATTR_BOLD:
hl_group['attr'].append('bold')
if attr & self.ATTR_ITALIC:
if attr & ATTR_ITALIC:
hl_group['attr'].append('italic')
if attr & self.ATTR_UNDERLINE:
if attr & ATTR_UNDERLINE:
hl_group['attr'].append('underline')
hl_group['name'] = 'Pl_' + \
str(hl_group['ctermfg']) + '_' + \