mirror of
https://github.com/powerline/powerline.git
synced 2025-04-08 19:25:04 +02:00
Add support for python-3.2
This commit is contained in:
parent
de33eb8140
commit
9fd63021f0
@ -3,6 +3,12 @@
|
|||||||
from powerline.theme import Theme
|
from powerline.theme import Theme
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
NBSP = unicode(' ', 'utf-8')
|
||||||
|
except NameError:
|
||||||
|
NBSP = ' '
|
||||||
|
|
||||||
|
|
||||||
class Renderer(object):
|
class Renderer(object):
|
||||||
def __init__(self, theme_config, local_themes, theme_kwargs, colorscheme, **options):
|
def __init__(self, theme_config, local_themes, theme_kwargs, colorscheme, **options):
|
||||||
self.__dict__.update(options)
|
self.__dict__.update(options)
|
||||||
@ -58,7 +64,7 @@ class Renderer(object):
|
|||||||
|
|
||||||
if not width:
|
if not width:
|
||||||
# No width specified, so we don't need to crop or pad anything
|
# No width specified, so we don't need to crop or pad anything
|
||||||
return self._returned_value(u''.join([segment['_rendered_hl'] for segment in segments]) + self.hlstyle(), segments, output_raw)
|
return self._returned_value(''.join([segment['_rendered_hl'] for segment in segments]) + self.hlstyle(), segments, output_raw)
|
||||||
|
|
||||||
# Create an ordered list of segments that can be dropped
|
# Create an ordered list of segments that can be dropped
|
||||||
segments_priority = [segment for segment in sorted(segments, key=lambda segment: segment['priority'], reverse=True) if segment['priority'] > 0]
|
segments_priority = [segment for segment in sorted(segments, key=lambda segment: segment['priority'], reverse=True) if segment['priority'] > 0]
|
||||||
@ -81,7 +87,7 @@ class Renderer(object):
|
|||||||
segment['_space_right'] += space_side
|
segment['_space_right'] += space_side
|
||||||
segments_spacers[0]['_space_right'] += distribute_len_remainder
|
segments_spacers[0]['_space_right'] += distribute_len_remainder
|
||||||
|
|
||||||
rendered_highlighted = u''.join([segment['_rendered_hl'] for segment in self._render_segments(theme, segments)]) + self.hlstyle()
|
rendered_highlighted = ''.join([segment['_rendered_hl'] for segment in self._render_segments(theme, segments)]) + self.hlstyle()
|
||||||
|
|
||||||
return self._returned_value(rendered_highlighted, segments, output_raw)
|
return self._returned_value(rendered_highlighted, segments, output_raw)
|
||||||
|
|
||||||
@ -99,8 +105,8 @@ class Renderer(object):
|
|||||||
segments_len = len(segments)
|
segments_len = len(segments)
|
||||||
|
|
||||||
for index, segment in enumerate(segments):
|
for index, segment in enumerate(segments):
|
||||||
segment['_rendered_raw'] = u''
|
segment['_rendered_raw'] = ''
|
||||||
segment['_rendered_hl'] = u''
|
segment['_rendered_hl'] = ''
|
||||||
|
|
||||||
prev_segment = segments[index - 1] if index > 0 else theme.EMPTY_SEGMENT
|
prev_segment = segments[index - 1] if index > 0 else theme.EMPTY_SEGMENT
|
||||||
next_segment = segments[index + 1] if index < segments_len - 1 else theme.EMPTY_SEGMENT
|
next_segment = segments[index + 1] if index < segments_len - 1 else theme.EMPTY_SEGMENT
|
||||||
@ -127,8 +133,8 @@ class Renderer(object):
|
|||||||
contents_raw = (segment['_space_left'] * ' ') + contents_raw + (segment['_space_right'] * ' ') + outer_padding
|
contents_raw = (segment['_space_left'] * ' ') + contents_raw + (segment['_space_right'] * ' ') + outer_padding
|
||||||
|
|
||||||
# Replace spaces with no-break spaces
|
# Replace spaces with no-break spaces
|
||||||
contents_raw = contents_raw.replace(' ', u'\u00a0')
|
contents_raw = contents_raw.replace(' ', NBSP)
|
||||||
divider_raw = divider_raw.replace(' ', u'\u00a0')
|
divider_raw = divider_raw.replace(' ', NBSP)
|
||||||
|
|
||||||
# Apply highlighting to padded dividers and contents
|
# Apply highlighting to padded dividers and contents
|
||||||
if render_highlighted:
|
if render_highlighted:
|
||||||
@ -182,4 +188,4 @@ class Renderer(object):
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def hl(self, contents, fg=None, bg=None, attr=None):
|
def hl(self, contents, fg=None, bg=None, attr=None):
|
||||||
return self.hlstyle(fg, bg, attr) + (contents or u'')
|
return self.hlstyle(fg, bg, attr) + (contents or '')
|
||||||
|
@ -79,8 +79,8 @@ def gen_segment_getter(ext, path, theme_configs, default_module=None):
|
|||||||
'include_modes': segment.get('include_modes', []),
|
'include_modes': segment.get('include_modes', []),
|
||||||
'width': segment.get('width'),
|
'width': segment.get('width'),
|
||||||
'align': segment.get('align', 'l'),
|
'align': segment.get('align', 'l'),
|
||||||
'_rendered_raw': u'',
|
'_rendered_raw': '',
|
||||||
'_rendered_hl': u'',
|
'_rendered_hl': '',
|
||||||
'_len': 0,
|
'_len': 0,
|
||||||
'_space_left': 0,
|
'_space_left': 0,
|
||||||
'_space_right': 0,
|
'_space_right': 0,
|
||||||
|
@ -74,7 +74,7 @@ def cwd(dir_shorten_len=None, dir_limit_depth=None):
|
|||||||
cwd_split_len = len(cwd_split)
|
cwd_split_len = len(cwd_split)
|
||||||
if dir_limit_depth and cwd_split_len > dir_limit_depth + 1:
|
if dir_limit_depth and cwd_split_len > dir_limit_depth + 1:
|
||||||
del(cwd_split[0:-dir_limit_depth])
|
del(cwd_split[0:-dir_limit_depth])
|
||||||
cwd_split.insert(0, u'⋯')
|
cwd_split.insert(0, '⋯')
|
||||||
cwd = [i[0:dir_shorten_len] if dir_shorten_len and i else i for i in cwd_split[:-1]] + [cwd_split[-1]]
|
cwd = [i[0:dir_shorten_len] if dir_shorten_len and i else i for i in cwd_split[:-1]] + [cwd_split[-1]]
|
||||||
ret = []
|
ret = []
|
||||||
if not cwd[0]:
|
if not cwd[0]:
|
||||||
@ -263,18 +263,18 @@ weather_conditions_codes = (
|
|||||||
# ('sunny', (32, 36)),
|
# ('sunny', (32, 36)),
|
||||||
# ('night', (31, 33))):
|
# ('night', (31, 33))):
|
||||||
weather_conditions_icons = {
|
weather_conditions_icons = {
|
||||||
'day': u'〇',
|
'day': '〇',
|
||||||
'blustery': u'⚑',
|
'blustery': '⚑',
|
||||||
'rainy': u'☔',
|
'rainy': '☔',
|
||||||
'cloudy': u'☁',
|
'cloudy': '☁',
|
||||||
'snowy': u'❅',
|
'snowy': '❅',
|
||||||
'stormy': u'☈',
|
'stormy': '☈',
|
||||||
'foggy': u'〰',
|
'foggy': '〰',
|
||||||
'sunny': u'☼',
|
'sunny': '☼',
|
||||||
'night': u'☾',
|
'night': '☾',
|
||||||
'windy': u'☴',
|
'windy': '☴',
|
||||||
'not_available': u'<EFBFBD>',
|
'not_available': '<EFBFBD>',
|
||||||
'unknown': u'⚠',
|
'unknown': '⚠',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -306,8 +306,8 @@ def weather(unit='c', location_query=None, icons=None):
|
|||||||
return None
|
return None
|
||||||
query_data = {
|
query_data = {
|
||||||
'q':
|
'q':
|
||||||
u'use "http://github.com/yql/yql-tables/raw/master/weather/weather.bylocation.xml" as we;'
|
'use "http://github.com/yql/yql-tables/raw/master/weather/weather.bylocation.xml" as we;'
|
||||||
u'select * from we where location="{0}" and unit="{1}"'.format(location_query, unit).encode('utf-8'),
|
'select * from we where location="{0}" and unit="{1}"'.format(location_query, unit).encode('utf-8'),
|
||||||
'format': 'json'
|
'format': 'json'
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
@ -339,7 +339,7 @@ def weather(unit='c', location_query=None, icons=None):
|
|||||||
'divider_highlight_group': 'background:divider',
|
'divider_highlight_group': 'background:divider',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'contents': u'{0}°{1}'.format(condition['temp'], unit.upper()),
|
'contents': '{0}°{1}'.format(condition['temp'], unit.upper()),
|
||||||
'highlight_group': ['weather_temp_cold' if int(condition['temp']) < 0 else 'weather_temp_hot', 'weather_temp', 'weather'],
|
'highlight_group': ['weather_temp_cold' if int(condition['temp']) < 0 else 'weather_temp_hot', 'weather_temp', 'weather'],
|
||||||
'draw_divider': False,
|
'draw_divider': False,
|
||||||
'divider_highlight_group': 'background:divider',
|
'divider_highlight_group': 'background:divider',
|
||||||
@ -397,7 +397,7 @@ def cpu_load_percent(measure_interval=.5):
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
return None
|
return None
|
||||||
cpu_percent = int(psutil.cpu_percent(interval=measure_interval))
|
cpu_percent = int(psutil.cpu_percent(interval=measure_interval))
|
||||||
return u'{0}%'.format(cpu_percent)
|
return '{0}%'.format(cpu_percent)
|
||||||
|
|
||||||
|
|
||||||
@add_divider_highlight_group('background:divider')
|
@add_divider_highlight_group('background:divider')
|
||||||
@ -443,7 +443,7 @@ def network_load(interface='eth0', measure_interval=1, suffix='B/s', si_prefix=F
|
|||||||
return None
|
return None
|
||||||
time.sleep(measure_interval)
|
time.sleep(measure_interval)
|
||||||
b2 = get_bytes()
|
b2 = get_bytes()
|
||||||
return u'⬇ {rx_diff} ⬆ {tx_diff}'.format(
|
return '⬇ {rx_diff} ⬆ {tx_diff}'.format(
|
||||||
rx_diff=humanize_bytes((b2[0] - b1[0]) / measure_interval, suffix, si_prefix).rjust(8),
|
rx_diff=humanize_bytes((b2[0] - b1[0]) / measure_interval, suffix, si_prefix).rjust(8),
|
||||||
tx_diff=humanize_bytes((b2[1] - b1[1]) / measure_interval, suffix, si_prefix).rjust(8),
|
tx_diff=humanize_bytes((b2[1] - b1[1]) / measure_interval, suffix, si_prefix).rjust(8),
|
||||||
)
|
)
|
||||||
@ -492,13 +492,13 @@ def email_imap_alert(username, password, server='imap.gmail.com', port=993, fold
|
|||||||
|
|
||||||
class NowPlayingSegment(object):
|
class NowPlayingSegment(object):
|
||||||
STATE_SYMBOLS = {
|
STATE_SYMBOLS = {
|
||||||
'fallback': u'♫',
|
'fallback': '♫',
|
||||||
'play': u'▶',
|
'play': '▶',
|
||||||
'pause': u'▮▮',
|
'pause': '▮▮',
|
||||||
'stop': u'■',
|
'stop': '■',
|
||||||
}
|
}
|
||||||
|
|
||||||
def __call__(self, player='mpd', format=u'{state_symbol} {artist} - {title} ({total})', *args, **kwargs):
|
def __call__(self, player='mpd', format='{state_symbol} {artist} - {title} ({total})', *args, **kwargs):
|
||||||
player_func = getattr(self, 'player_{0}'.format(player))
|
player_func = getattr(self, 'player_{0}'.format(player))
|
||||||
stats = {
|
stats = {
|
||||||
'state': None,
|
'state': None,
|
||||||
@ -538,7 +538,7 @@ class NowPlayingSegment(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _convert_seconds(seconds):
|
def _convert_seconds(seconds):
|
||||||
return u'{0:.0f}:{1:02.0f}'.format(*divmod(float(seconds), 60))
|
return '{0:.0f}:{1:02.0f}'.format(*divmod(float(seconds), 60))
|
||||||
|
|
||||||
def player_cmus(self):
|
def player_cmus(self):
|
||||||
'''Return cmus player information.
|
'''Return cmus player information.
|
||||||
|
@ -22,24 +22,24 @@ vim_funcs = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vim_modes = {
|
vim_modes = {
|
||||||
'n': u'NORMAL',
|
'n': 'NORMAL',
|
||||||
'no': u'N·OPER',
|
'no': 'N·OPER',
|
||||||
'v': u'VISUAL',
|
'v': 'VISUAL',
|
||||||
'V': u'V·LINE',
|
'V': 'V·LINE',
|
||||||
'^V': u'V·BLCK',
|
'^V': 'V·BLCK',
|
||||||
's': u'SELECT',
|
's': 'SELECT',
|
||||||
'S': u'S·LINE',
|
'S': 'S·LINE',
|
||||||
'^S': u'S·BLCK',
|
'^S': 'S·BLCK',
|
||||||
'i': u'INSERT',
|
'i': 'INSERT',
|
||||||
'R': u'REPLACE',
|
'R': 'REPLACE',
|
||||||
'Rv': u'V·RPLCE',
|
'Rv': 'V·RPLCE',
|
||||||
'c': u'COMMND',
|
'c': 'COMMND',
|
||||||
'cv': u'VIM EX',
|
'cv': 'VIM EX',
|
||||||
'ce': u'EX',
|
'ce': 'EX',
|
||||||
'r': u'PROMPT',
|
'r': 'PROMPT',
|
||||||
'rm': u'MORE',
|
'rm': 'MORE',
|
||||||
'r?': u'CONFIRM',
|
'r?': 'CONFIRM',
|
||||||
'!': u'SHELL',
|
'!': 'SHELL',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ def mode(segment_info, override=None):
|
|||||||
|
|
||||||
|
|
||||||
@requires_segment_info
|
@requires_segment_info
|
||||||
def modified_indicator(segment_info, text=u'+'):
|
def modified_indicator(segment_info, text='+'):
|
||||||
'''Return a file modified indicator.
|
'''Return a file modified indicator.
|
||||||
|
|
||||||
:param string text:
|
:param string text:
|
||||||
@ -139,7 +139,7 @@ def paste_indicator(segment_info, text='PASTE'):
|
|||||||
|
|
||||||
|
|
||||||
@requires_segment_info
|
@requires_segment_info
|
||||||
def readonly_indicator(segment_info, text=u''):
|
def readonly_indicator(segment_info, text=''):
|
||||||
'''Return a read-only indicator.
|
'''Return a read-only indicator.
|
||||||
|
|
||||||
:param string text:
|
:param string text:
|
||||||
@ -274,7 +274,7 @@ def virtcol_current():
|
|||||||
'highlight_group': ['virtcol_current', 'col_current']}]
|
'highlight_group': ['virtcol_current', 'col_current']}]
|
||||||
|
|
||||||
|
|
||||||
def modified_buffers(text=u'+ ', join_str=u','):
|
def modified_buffers(text='+ ', join_str=','):
|
||||||
'''Return a comma-separated list of modified buffers.
|
'''Return a comma-separated list of modified buffers.
|
||||||
|
|
||||||
:param str text:
|
:param str text:
|
||||||
|
@ -8,7 +8,7 @@ from .segment import gen_segment_getter
|
|||||||
try:
|
try:
|
||||||
from __builtin__ import unicode
|
from __builtin__ import unicode
|
||||||
except ImportError:
|
except ImportError:
|
||||||
unicode = str
|
unicode = str # NOQA
|
||||||
|
|
||||||
|
|
||||||
def u(s):
|
def u(s):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user