Ignore highlight definitions for function segments

Also removed divider_highlight_group from configuration: it is actually used
only in function segments.

Fixes #215
This commit is contained in:
ZyX 2013-02-23 15:04:15 +04:00 committed by Kim Silkebækken
parent 045d60fbc4
commit f319ddc33b
11 changed files with 69 additions and 42 deletions

View File

@ -90,7 +90,6 @@ segments that you may want to customize right away:
{
"name": "weather",
"priority": 50,
"divider_highlight_group": "background:divider"
"args": {
"unit": "f",
"location_query": "oslo, norway"
@ -289,6 +288,8 @@ Themes
of highlighting groups, where the first highlighting group that is
available in the colorscheme is used.
Ignored for segments that have ``function`` type.
``before``
.. _config-themes-seg-before:

View File

@ -29,8 +29,7 @@
"name": "cwd",
"args": {
"dir_limit_depth": 3
},
"divider_highlight_group": "cwd:divider"
}
}
],
"right": [

View File

@ -32,8 +32,7 @@
"name": "cwd",
"args": {
"dir_limit_depth": 3
},
"divider_highlight_group": "cwd:divider"
}
},
{
"name": "last_status",

View File

@ -22,37 +22,33 @@
"right": [
{
"name": "uptime",
"priority": 50,
"divider_highlight_group": "background:divider"
"priority": 50
},
{
"name": "external_ip",
"priority": 50,
"divider_highlight_group": "background:divider"
"priority": 50
},
{
"name": "network_load",
"priority": 50,
"divider_highlight_group": "background:divider"
"priority": 50
},
{
"name": "system_load",
"priority": 50,
"divider_highlight_group": "background:divider"
"priority": 50
},
{
"name": "weather",
"priority": 50,
"divider_highlight_group": "background:divider"
"priority": 50
},
{
"name": "date"
},
{
"name": "date",
"args": {"format": "%H:%M"},
"highlight_group": ["time", "date"],
"divider_highlight_group": "time:divider"
"args": {
"format": "%H:%M",
"istime": true
}
},
{
"name": "email_imap_alert",

View File

@ -28,8 +28,7 @@
{
"name": "branch",
"exclude_modes": ["nc"],
"priority": 60,
"divider_highlight_group": "branch:divider"
"priority": 60
},
{
"name": "readonly_indicator",
@ -66,20 +65,17 @@
"name": "file_format",
"draw_divider": false,
"exclude_modes": ["nc"],
"priority": 50,
"divider_highlight_group": "background:divider"
"priority": 50
},
{
"name": "file_encoding",
"exclude_modes": ["nc"],
"priority": 50,
"divider_highlight_group": "background:divider"
"priority": 50
},
{
"name": "file_type",
"exclude_modes": ["nc"],
"priority": 50,
"divider_highlight_group": "background:divider"
"priority": 50
},
{
"name": "line_percent",

View File

@ -4,18 +4,18 @@
"right": [
{
"name": "weather",
"priority": 50,
"divider_highlight_group": "background:divider"
"priority": 50
},
{
"name": "date"
},
{
"name": "date",
"args": {"format": "%H:%M"},
"before": "⌚ ",
"highlight_group": ["time", "date"],
"divider_highlight_group": "time:divider"
"args": {
"format": "%H:%M",
"istime": true
},
"before": "⌚ "
},
{
"name": "email_imap_alert",

View File

@ -1,3 +1,5 @@
from functools import wraps
from powerline.lib.memoize import memoize # NOQA
from powerline.lib.humanize_bytes import humanize_bytes # NOQA
from powerline.lib.url import urllib_read, urllib_urlencode # NOQA
@ -16,3 +18,19 @@ def mergedicts(d1, d2):
mergedicts(d1[k], d2[k])
else:
d1[k] = d2[k]
def add_divider_highlight_group(highlight_group):
def dec(func):
@wraps(func)
def f(**kwargs):
r = func(**kwargs)
if r:
return [{
'contents': r,
'divider_highlight_group': highlight_group,
}]
else:
return None
return f
return dec

View File

@ -30,7 +30,7 @@ class Renderer(object):
def get_highlighting(self, segment, mode):
segment['highlight'] = self.colorscheme.get_highlighting(segment['highlight_group'], mode, segment.get('gradient_level'))
if segment['divider_highlight_group']:
segment['divider_highlight'] = self.colorscheme.get_highlighting(segment['divider_highlight_group'], mode)
segment['divider_highlight'] = self.colorscheme.get_highlighting([segment['divider_highlight_group']], mode)
else:
segment['divider_highlight'] = None
return segment

View File

@ -66,12 +66,11 @@ def gen_segment_getter(ext, path, theme_configs, default_module=None):
except KeyError:
raise TypeError('Unknown segment type: {0}'.format(segment_type))
contents, contents_func, module = get_segment_info(data, segment)
highlight_group = segment.get('highlight_group', segment.get('name'))
divider_highlight_group = segment.get('divider_highlight_group')
highlight_group = segment_type != 'function' and segment.get('highlight_group') or segment.get('name')
return {
'type': segment_type,
'highlight_group': scalar_to_list(highlight_group),
'divider_highlight_group': scalar_to_list(divider_highlight_group) if divider_highlight_group else None,
'divider_highlight_group': None,
'before': get_key(segment, module, 'before', ''),
'after': get_key(segment, module, 'after', ''),
'contents_func': contents_func,

View File

@ -3,7 +3,8 @@
import os
import sys
from powerline.lib import memoize, urllib_read, urllib_urlencode
from powerline.lib import memoize, urllib_read, urllib_urlencode, add_divider_highlight_group
from functools import wraps
def hostname(only_if_ssh=False):
@ -80,19 +81,24 @@ def cwd(dir_shorten_len=None, dir_limit_depth=None):
continue
ret.append({
'contents': part,
'divider_highlight_group': 'cwd:divider',
})
ret[-1]['highlight_group'] = ['cwd:current_folder', 'cwd']
return ret
def date(format='%Y-%m-%d'):
def date(format='%Y-%m-%d', istime=False):
'''Return the current date.
:param str format:
strftime-style date format string
'''
from datetime import datetime
return datetime.now().strftime(format)
return [{
'contents': datetime.now().strftime(format),
'highlight_group': (['time'] if istime else []) + ['date'],
'divider_highlight_group': 'time:divider' if istime else None,
}]
def fuzzy_time():
@ -148,6 +154,7 @@ def fuzzy_time():
@memoize(600)
@add_divider_highlight_group('background:divider')
def external_ip(query_url='http://ipv4.icanhazip.com/'):
'''Return external IP address.
@ -163,6 +170,7 @@ def external_ip(query_url='http://ipv4.icanhazip.com/'):
return urllib_read(query_url).strip()
@add_divider_highlight_group('background:divider')
def uptime(format='{days:02d}d {hours:02d}h {minutes:02d}m'):
'''Return system uptime.
@ -265,6 +273,7 @@ weather_conditions_icons = {
@memoize(1800)
@add_divider_highlight_group('background:divider')
def weather(unit='c', location_query=None, icons=None):
'''Return weather from Yahoo! Weather.
@ -360,6 +369,7 @@ def system_load(format='{avg:.1f}', threshold_good=1, threshold_bad=2):
'contents': format.format(avg=avg),
'highlight_group': [hl, 'system_load'],
'draw_divider': False,
'divider_highlight_group': 'background:divider',
})
ret[0]['draw_divider'] = True
ret[0]['contents'] += ' '
@ -383,6 +393,7 @@ def cpu_load_percent(measure_interval=.5):
return u'{0}%'.format(cpu_percent)
@add_divider_highlight_group('background:divider')
def network_load(interface='eth0', measure_interval=1, suffix='B/s', binary_prefix=False):
'''Return the network load.

View File

@ -10,7 +10,7 @@ except ImportError:
from powerline.bindings.vim import vim_get_func, getbufvar
from powerline.theme import requires_segment_info
from powerline.lib import memoize, humanize_bytes
from powerline.lib import memoize, humanize_bytes, add_divider_highlight_group
from powerline.lib.vcs import guess
from collections import defaultdict
@ -201,6 +201,7 @@ def file_size(segment_info, suffix='B', binary_prefix=False):
@requires_segment_info
@add_divider_highlight_group('background:divider')
def file_format(segment_info):
'''Return file format (i.e. line ending type).
@ -210,6 +211,7 @@ def file_format(segment_info):
@requires_segment_info
@add_divider_highlight_group('background:divider')
def file_encoding(segment_info):
'''Return file encoding/character set.
@ -219,6 +221,7 @@ def file_encoding(segment_info):
@requires_segment_info
@add_divider_highlight_group('background:divider')
def file_type(segment_info):
'''Return file type.
@ -262,7 +265,9 @@ def col_current(segment_info):
@window_cached
def virtcol_current():
'''Return current visual column with concealed characters ingored'''
return vim_funcs['virtcol']('.')
return [{'contents': vim_funcs['virtcol']('.'),
'highlight_group': ['virtcol_current', 'col_current'],
}]
def modified_buffers(text=u'+', join_str=','):
@ -286,7 +291,10 @@ def branch(segment_info):
'''Return the current working branch.'''
repo = guess(path=os.path.abspath(segment_info['buffer'].name or os.getcwd()))
if repo:
return repo.branch()
return [{
'contents': repo.branch(),
'divider_highlight_group': 'branch:divider',
}]
return None