Move mksegment out of core

This commit is contained in:
Kim Silkebækken 2012-12-05 17:35:21 +01:00
parent 4d225179d0
commit d4d84a4346
2 changed files with 23 additions and 21 deletions

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from lib.colors import cterm_to_hex
from segment import mksegment
class Powerline(object):
@ -140,23 +140,3 @@ class Powerline(object):
that the segments have been rendered using the render() method first.
'''
return len(''.join([segment['rendered_raw'] for segment in self.segments]))
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''
return {
'contents': contents,
'fg': (cterm_fg, hex_fg or cterm_to_hex.get(cterm_fg, 0xffffff)),
'bg': (cterm_bg, hex_bg or cterm_to_hex.get(cterm_bg, 0x000000)),
'attr': attr,
'side': side,
'draw_divider': False if filler else draw_divider,
'priority': priority,
'filler': filler,
}

View File

@ -1 +1,23 @@
# -*- coding: utf-8 -*-
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''
return {
'contents': contents,
'fg': (cterm_fg, hex_fg or cterm_to_hex.get(cterm_fg, 0xffffff)),
'bg': (cterm_bg, hex_bg or cterm_to_hex.get(cterm_bg, 0x000000)),
'attr': attr,
'side': side,
'draw_divider': False if filler else draw_divider,
'priority': priority,
'filler': filler,
}