Get color configuration from variables exported by setcolors
This commit is contained in:
parent
ddac11a64a
commit
e6fc2911c2
|
@ -7,10 +7,11 @@ import sys
|
|||
|
||||
from powerline.config import POWERLINE_ROOT, TMUX_CONFIG_DIRECTORY
|
||||
from powerline.lib.config import ConfigLoader
|
||||
from powerline import generate_config_finder, load_config, create_logger, PowerlineLogger, finish_common_config
|
||||
from powerline import generate_config_finder, load_config, create_logger, PowerlineLogger, finish_common_config, Powerline
|
||||
from powerline.lib.shell import which
|
||||
from powerline.bindings.tmux import TmuxVersionInfo, run_tmux_command, get_tmux_version
|
||||
from powerline.lib.encoding import get_preferred_output_encoding
|
||||
from powerline.renderers.tmux import attr_to_tmux_attr
|
||||
|
||||
|
||||
CONFIG_FILE_NAME = re.compile(r'powerline_tmux_(?P<major>\d+)\.(?P<minor>\d+)(?P<suffix>[a-z]+)?(?:_(?P<mod>plus|minus))?\.conf')
|
||||
|
@ -75,6 +76,83 @@ def source_tmux_files(pl, args):
|
|||
run_tmux_command('refresh-client')
|
||||
|
||||
|
||||
def init_color_variables(pl, args):
|
||||
powerline = Powerline('tmux')
|
||||
# TODO Move configuration files loading out of Powerline object and use it
|
||||
# directly
|
||||
powerline.update_renderer()
|
||||
# FIXME Use something more stable then `theme_kwargs`
|
||||
colorscheme = powerline.renderer_options['theme_kwargs']['colorscheme']
|
||||
|
||||
def get_highlighting(group):
|
||||
return colorscheme.get_highlighting([group], None)
|
||||
|
||||
for varname, highlight_group in (
|
||||
('_POWERLINE_BACKGROUND_COLOR', 'background'),
|
||||
('_POWERLINE_ACTIVE_WINDOW_STATUS_COLOR', 'active_window_status'),
|
||||
('_POWERLINE_WINDOW_STATUS_COLOR', 'window_status'),
|
||||
('_POWERLINE_ACTIVITY_STATUS_COLOR', 'activity_status'),
|
||||
('_POWERLINE_BELL_STATUS_COLOR', 'bell_status'),
|
||||
('_POWERLINE_WINDOW_COLOR', 'window'),
|
||||
('_POWERLINE_WINDOW_DIVIDER_COLOR', 'window:divider'),
|
||||
('_POWERLINE_WINDOW_CURRENT_COLOR', 'window:current'),
|
||||
('_POWERLINE_WINDOW_NAME_COLOR', 'window_name'),
|
||||
('_POWERLINE_SESSION_COLOR', 'session'),
|
||||
):
|
||||
highlight = get_highlighting(highlight_group)
|
||||
run_tmux_command('set-environment', '-g', varname, powerline.renderer.hlstyle(**highlight)[2:-1])
|
||||
run_tmux_command('set-environment', '-r', varname)
|
||||
for varname, prev_group, next_group in (
|
||||
('_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_COLOR', 'window', 'window:current'),
|
||||
('_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_NEXT_COLOR', 'window:current', 'window'),
|
||||
('_POWERLINE_SESSION_HARD_DIVIDER_NEXT_COLOR', 'session', 'background'),
|
||||
):
|
||||
prev_highlight = get_highlighting(prev_group)
|
||||
next_highlight = get_highlighting(next_group)
|
||||
run_tmux_command(
|
||||
'set-environment', '-g', varname,
|
||||
powerline.renderer.hlstyle(
|
||||
fg=prev_highlight['bg'],
|
||||
bg=next_highlight['bg'],
|
||||
attr=0,
|
||||
)[2:-1]
|
||||
)
|
||||
run_tmux_command('set-environment', '-r', varname)
|
||||
for varname, attr, group in (
|
||||
('_POWERLINE_ACTIVE_WINDOW_FG', 'fg', 'active_window_status'),
|
||||
('_POWERLINE_WINDOW_STATUS_FG', 'fg', 'window_status'),
|
||||
('_POWERLINE_ACTIVITY_STATUS_FG', 'fg', 'activity_status'),
|
||||
('_POWERLINE_ACTIVITY_STATUS_ATTR', 'attr', 'activity_status'),
|
||||
('_POWERLINE_BELL_STATUS_FG', 'fg', 'bell_status'),
|
||||
('_POWERLINE_BELL_STATUS_ATTR', 'attr', 'bell_status'),
|
||||
('_POWERLINE_BACKGROUND_FG', 'fg', 'background'),
|
||||
('_POWERLINE_BACKGROUND_BG', 'bg', 'background'),
|
||||
('_POWERLINE_SESSION_FG', 'fg', 'session'),
|
||||
('_POWERLINE_SESSION_BG', 'bg', 'session'),
|
||||
('_POWERLINE_SESSION_ATTR', 'attr', 'session'),
|
||||
('_POWERLINE_SESSION_PREFIX_FG', 'fg', 'session:prefix'),
|
||||
('_POWERLINE_SESSION_PREFIX_BG', 'bg', 'session:prefix'),
|
||||
('_POWERLINE_SESSION_PREFIX_ATTR', 'attr', 'session:prefix'),
|
||||
):
|
||||
if attr == 'attr':
|
||||
attrs = attr_to_tmux_attr(get_highlighting(group)[attr])
|
||||
run_tmux_command(
|
||||
'set-environment', '-g', varname,
|
||||
']#['.join(attrs)
|
||||
)
|
||||
run_tmux_command(
|
||||
'set-environment', '-g', varname + '_LEGACY',
|
||||
','.join(attrs)
|
||||
)
|
||||
run_tmux_command('set-environment', '-r', varname + '_LEGACY')
|
||||
else:
|
||||
run_tmux_command(
|
||||
'set-environment', '-g', varname,
|
||||
'colour' + str(get_highlighting(group)[attr][0])
|
||||
)
|
||||
run_tmux_command('set-environment', '-r', varname)
|
||||
|
||||
|
||||
def get_main_config(args):
|
||||
find_config_files = generate_config_finder()
|
||||
config_loader = ConfigLoader(run_once=True)
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
if-shell 'test -z "$POWERLINE_CONFIG_COMMAND"' 'set-environment -g POWERLINE_CONFIG_COMMAND powerline-config'
|
||||
|
||||
# Don’t version-check for this core functionality -- anything too old to
|
||||
# support these options likely won’t work well with powerline
|
||||
run-shell 'eval $POWERLINE_CONFIG_COMMAND tmux setcolors'
|
||||
set -g status on
|
||||
set -g status-utf8 on
|
||||
set -g status-interval 2
|
||||
set -g status-left-length 20
|
||||
set -g status-right '#(eval $POWERLINE_COMMAND tmux right -R pane_id=`tmux display -p "#D"`)'
|
||||
set -g status-right-length 150
|
||||
set -g window-status-format "#[fg=colour244,bg=colour234] #I #[fg=colour240] #[default]#W "
|
||||
set -g window-status-current-format "#[fg=colour234,bg=colour31]#[fg=colour117,bg=colour31] #I #[fg=colour231,bold]#W #[fg=colour31,bg=colour234,nobold]"
|
||||
set -g window-status-format "#[$_POWERLINE_WINDOW_COLOR] #I #[$_POWERLINE_WINDOW_DIVIDER_COLOR] #[default]#W "
|
||||
set -g window-status-current-format "#[$_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_COLOR]#[$_POWERLINE_WINDOW_CURRENT_COLOR] #I #[$_POWERLINE_WINDOW_NAME_COLOR]#W #[$_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_NEXT_COLOR]"
|
||||
|
||||
# Legacy status-left definition to be overwritten for tmux Versions 1.8+
|
||||
set -g status-left '#[fg=colour16,bg=colour254,bold] #S #[fg=colour254,bg=colour234,nobold]#(eval $POWERLINE_COMMAND tmux left)'
|
||||
set -g status-left "#[$_POWERLINE_SESSION_COLOR] #S #[$_POWERLINE_SESSION_HARD_DIVIDER_NEXT_COLOR]#(eval \$POWERLINE_COMMAND tmux left)"
|
||||
|
||||
# Simplify tmux version checking by using multiple config files. Source these
|
||||
# config files based on the version in which tmux features were added and/or
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# powerline_tmux_1.8.conf
|
||||
# tmux Version 1.8 introduces window-status-last-{attr,bg,fg}, which is
|
||||
# deprecated for versions 1.9+, thus only applicable to version 1.8.
|
||||
set -qg window-status-last-fg colour31
|
||||
set -qg window-status-last-fg "$_POWERLINE_ACTIVE_WINDOW_FG"
|
||||
# vim: ft=tmux
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
# powerline_tmux_legacy_common.conf
|
||||
# tmux Version 1.8 and earlier (legacy) common options. The foo-{attr,bg,fg}
|
||||
# options are deprecated starting with tmux Version 1.9.
|
||||
set -g status-fg colour231
|
||||
set -g status-bg colour234
|
||||
set-window-option -g window-status-fg colour249
|
||||
set-window-option -g window-status-activity-attr none
|
||||
set-window-option -g window-status-bell-attr none
|
||||
set-window-option -g window-status-activity-fg yellow
|
||||
set-window-option -g window-status-bell-fg red
|
||||
set -g status-fg "$_POWERLINE_BACKGROUND_FG"
|
||||
set -g status-bg "$_POWERLINE_BACKGROUND_BG"
|
||||
set-window-option -g window-status-fg "$_POWERLINE_WINDOW_STATUS_FG"
|
||||
set-window-option -g window-status-activity-attr "$_POWERLINE_ACTIVITY_STATUS_ATTR_LEGACY"
|
||||
set-window-option -g window-status-bell-attr "$_POWERLINE_BELL_STATUS_ATTR_LEGACY"
|
||||
set-window-option -g window-status-activity-fg "$_POWERLINE_ACTIVITY_STATUS_FG"
|
||||
set-window-option -g window-status-bell-fg "$_POWERLINE_BELL_STATUS_FG"
|
||||
# vim: ft=tmux
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# powerline_tmux_1.8_plus.conf
|
||||
# tmux Version 1.8 introduces the 'client_prefix' format variable, applicable
|
||||
# for versions 1.8+
|
||||
set -qg status-left '#{?client_prefix,#[fg=colour254]#[bg=colour31]#[bold],#[fg=colour16]#[bg=colour254]#[bold]} #S #{?client_prefix,#[fg=colour31]#[bg=colour234]#[nobold],#[fg=colour254]#[bg=colour234]#[nobold]}#(eval $POWERLINE_COMMAND tmux left)'
|
||||
set -qg status-left "#{?client_prefix,#[fg=$_POWERLINE_SESSION_PREFIX_FG]#[bg=$_POWERLINE_SESSION_PREFIX_BG]#[$_POWERLINE_SESSION_PREFIX_ATTR],#[fg=$_POWERLINE_SESSION_FG]#[bg=$_POWERLINE_SESSION_BG]#[$_POWERLINE_SESSION_ATTR]} #S #{?client_prefix,#[fg=$_POWERLINE_SESSION_PREFIX_BG],#[fg=$_POWERLINE_SESSION_BG]}#[bg=$_POWERLINE_BACKGROUND_BG]#[nobold]#(eval \$POWERLINE_COMMAND tmux left)"
|
||||
# vim: ft=tmux
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
# powerline_tmux_1.9_plus.conf
|
||||
# Version 1.9 introduces the foo-style options, applicable to version 1.9+
|
||||
set -qg status-style fg=colour231,bg=colour234
|
||||
set -qg window-status-last-style fg=colour31
|
||||
set-window-option -qg window-status-style fg=colour249
|
||||
set-window-option -qg window-status-activity-style fg=yellow,none
|
||||
set-window-option -qg window-status-bell-style fg=red,none
|
||||
set-option -qg status-style "$_POWERLINE_BACKGROUND_COLOR"
|
||||
set-option -qg window-status-last-style "$_POWERLINE_ACTIVE_WINDOW_STATUS_COLOR"
|
||||
set-window-option -qg window-status-style "$_POWERLINE_WINDOW_STATUS_COLOR"
|
||||
set-window-option -qg window-status-activity-style "$_POWERLINE_ACTIVITY_STATUS_COLOR"
|
||||
set-window-option -qg window-status-bell-style "$_POWERLINE_BELL_STATUS_COLOR"
|
||||
# vim: ft=tmux
|
||||
|
|
|
@ -20,6 +20,7 @@ class StrFunction(object):
|
|||
|
||||
TMUX_ACTIONS = {
|
||||
'source': StrFunction(config.source_tmux_files, 'source'),
|
||||
'setcolors': StrFunction(config.init_color_variables, 'setcolors'),
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
"black": 16,
|
||||
"white": 231,
|
||||
|
||||
"green": 2,
|
||||
"darkestgreen": 22,
|
||||
"darkgreen": 28,
|
||||
"mediumgreen": 70,
|
||||
|
@ -32,6 +33,7 @@
|
|||
"brightorange": 208,
|
||||
"brightestorange": 214,
|
||||
|
||||
"yellow": 11,
|
||||
"brightyellow": 220,
|
||||
|
||||
"gray0": 233,
|
||||
|
@ -46,6 +48,11 @@
|
|||
"gray9": 250,
|
||||
"gray10": 252,
|
||||
|
||||
"gray11": 234,
|
||||
"gray90": 254,
|
||||
|
||||
"gray70": [249, "b3b3b3"],
|
||||
|
||||
"lightyellowgreen": 106,
|
||||
"gold3": 178,
|
||||
"orangered": 202,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"name": "Default",
|
||||
"groups": {
|
||||
"background": { "fg": "white", "bg": "gray0", "attr": [] },
|
||||
"background:divider": { "fg": "gray5", "bg": "gray0", "attr": [] },
|
||||
"session": { "fg": "black", "bg": "gray10", "attr": ["bold"] },
|
||||
"date": { "fg": "gray8", "bg": "gray2", "attr": [] },
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"groups": {
|
||||
"active_window_status": {"fg": "darkblue", "bg": "gray0", "attr": []},
|
||||
"window_status": {"fg": "gray70", "bg": "gray0", "attr": []},
|
||||
"activity_status": {"fg": "yellow", "bg": "gray0", "attr": []},
|
||||
"bell_status": {"fg": "red", "bg": "gray0", "attr": []},
|
||||
"window": {"fg": "gray6", "bg": "gray11", "attr": []},
|
||||
"window:divider": {"fg": "gray4", "bg": "gray11", "attr": []},
|
||||
"window:current": {"fg": "mediumcyan", "bg": "darkblue", "attr": []},
|
||||
"window_name": {"fg": "white", "bg": "darkblue", "attr": ["bold"]},
|
||||
"session": {"fg": "black", "bg": "gray90", "attr": ["bold"]},
|
||||
"session:prefix": {"fg": "gray90", "bg": "darkblue", "attr": ["bold"]}
|
||||
}
|
||||
}
|
|
@ -5,6 +5,26 @@ from powerline.renderer import Renderer
|
|||
from powerline.colorscheme import ATTR_BOLD, ATTR_ITALIC, ATTR_UNDERLINE
|
||||
|
||||
|
||||
def attr_to_tmux_attr(attr):
|
||||
if attr is False:
|
||||
return ['nobold', 'noitalics', 'nounderscore']
|
||||
else:
|
||||
ret = []
|
||||
if attr & ATTR_BOLD:
|
||||
ret += ['bold']
|
||||
else:
|
||||
ret += ['nobold']
|
||||
if attr & ATTR_ITALIC:
|
||||
ret += ['italics']
|
||||
else:
|
||||
ret += ['noitalics']
|
||||
if attr & ATTR_UNDERLINE:
|
||||
ret += ['underscore']
|
||||
else:
|
||||
ret += ['nounderscore']
|
||||
return ret
|
||||
|
||||
|
||||
class TmuxRenderer(Renderer):
|
||||
'''Powerline tmux segment renderer.'''
|
||||
|
||||
|
@ -28,21 +48,7 @@ class TmuxRenderer(Renderer):
|
|||
else:
|
||||
tmux_attr += ['bg=colour' + str(bg[0])]
|
||||
if attr is not None:
|
||||
if attr is False:
|
||||
tmux_attr += ['nobold', 'noitalics', 'nounderscore']
|
||||
else:
|
||||
if attr & ATTR_BOLD:
|
||||
tmux_attr += ['bold']
|
||||
else:
|
||||
tmux_attr += ['nobold']
|
||||
if attr & ATTR_ITALIC:
|
||||
tmux_attr += ['italics']
|
||||
else:
|
||||
tmux_attr += ['noitalics']
|
||||
if attr & ATTR_UNDERLINE:
|
||||
tmux_attr += ['underscore']
|
||||
else:
|
||||
tmux_attr += ['nounderscore']
|
||||
tmux_attr += attr_to_tmux_attr(attr)
|
||||
return '#[' + ','.join(tmux_attr) + ']'
|
||||
|
||||
def get_segment_info(self, segment_info, mode):
|
||||
|
|
Loading…
Reference in New Issue