Example #1
0
def init_tmux_environment(pl, args, set_tmux_environment=set_tmux_environment):
	'''Initialize tmux environment from tmux configuration
	'''
	powerline = ShellPowerline(finish_args(os.environ, EmptyArgs('tmux', args.config_path)))
	# 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)
		set_tmux_environment(varname, powerline.renderer.hlstyle(**highlight)[2:-1])
	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)
		set_tmux_environment(
			varname,
			powerline.renderer.hlstyle(
				fg=prev_highlight['bg'],
				bg=next_highlight['bg'],
				attrs=0,
			)[2:-1]
		)
	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', 'attrs', 'activity_status'),
		('_POWERLINE_BELL_STATUS_FG', 'fg', 'bell_status'),
		('_POWERLINE_BELL_STATUS_ATTR', 'attrs', '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', 'attrs', 'session'),
		('_POWERLINE_SESSION_PREFIX_FG', 'fg', 'session:prefix'),
		('_POWERLINE_SESSION_PREFIX_BG', 'bg', 'session:prefix'),
		('_POWERLINE_SESSION_PREFIX_ATTR', 'attrs', 'session:prefix'),
	):
		if attr == 'attrs':
			attrs = attrs_to_tmux_attrs(get_highlighting(group)[attr])
			set_tmux_environment(varname, ']#['.join(attrs))
			set_tmux_environment(varname + '_LEGACY', (','.join(
				# Tmux-1.6 does not accept no… attributes in 
				# window-status-…-attr options.
				(attr for attr in attrs if not attr.startswith('no')))
				# But it does not support empty attributes as well.
				or 'none'))
		else:
			set_tmux_environment(varname, 'colour' + str(get_highlighting(group)[attr][0]))

	left_dividers = powerline.renderer.theme.dividers['left']
	set_tmux_environment('_POWERLINE_LEFT_HARD_DIVIDER', left_dividers['hard'])
	set_tmux_environment('_POWERLINE_LEFT_SOFT_DIVIDER', left_dividers['soft'])
	set_tmux_environment('_POWERLINE_LEFT_HARD_DIVIDER_SPACES', (
		' ' * powerline.renderer.strwidth(left_dividers['hard'])))
Example #2
0
def init_tmux_environment(pl, args, set_tmux_environment=set_tmux_environment):
    '''Initialize tmux environment from tmux configuration
    '''
    powerline = ShellPowerline(
        finish_args(None, os.environ, EmptyArgs('tmux', args.config_path)))
    # 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)
        set_tmux_environment(varname,
                             powerline.renderer.hlstyle(**highlight)[2:-1])
    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)
        set_tmux_environment(
            varname,
            powerline.renderer.hlstyle(
                fg=prev_highlight['bg'],
                bg=next_highlight['bg'],
                attrs=0,
            )[2:-1])
    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', 'attrs', 'activity_status'),
        ('_POWERLINE_BELL_STATUS_FG', 'fg', 'bell_status'),
        ('_POWERLINE_BELL_STATUS_ATTR', 'attrs', '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', 'attrs', 'session'),
        ('_POWERLINE_SESSION_PREFIX_FG', 'fg', 'session:prefix'),
        ('_POWERLINE_SESSION_PREFIX_BG', 'bg', 'session:prefix'),
        ('_POWERLINE_SESSION_PREFIX_ATTR', 'attrs', 'session:prefix'),
    ):
        if attr == 'attrs':
            attrs = attrs_to_tmux_attrs(get_highlighting(group)[attr])
            set_tmux_environment(varname, ']#['.join(attrs))
            set_tmux_environment(
                varname + '_LEGACY',
                (
                    ','.join(
                        # Tmux-1.6 does not accept no… attributes in
                        # window-status-…-attr options.
                        (attr for attr in attrs if not attr.startswith('no')))
                    # But it does not support empty attributes as well.
                    or 'none'))
        else:
            if powerline.common_config['term_truecolor']:
                set_tmux_environment(
                    varname,
                    '#{0:06x}'.format(get_highlighting(group)[attr][1]))
            else:
                set_tmux_environment(
                    varname, 'colour' + str(get_highlighting(group)[attr][0]))

    left_dividers = powerline.renderer.theme.dividers['left']
    set_tmux_environment('_POWERLINE_LEFT_HARD_DIVIDER', left_dividers['hard'])
    set_tmux_environment('_POWERLINE_LEFT_SOFT_DIVIDER', left_dividers['soft'])
    set_tmux_environment(
        '_POWERLINE_LEFT_HARD_DIVIDER_SPACES',
        (' ' * powerline.renderer.strwidth(left_dividers['hard'])))
Example #3
0
 def test_main_normal(self):
     parser = get_argparser()
     out = StrIO()
     err = StrIO()
     with replace_attr(sys, 'stdout', out, 'stderr', err):
         for argv, expargs in [
             (['shell'], {
                 'ext': ['shell']
             }),
             (['shell', '-r', '.zsh'], {
                 'ext': ['shell'],
                 'renderer_module': '.zsh'
             }),
             ([
                 'shell',
                 'left',
                 '-r',
                 '.zsh',
                 '--last-exit-code',
                 '10',
                 '--last-pipe-status',
                 '10 20 30',
                 '--jobnum=10',
                 '-w',
                 '100',
                 '-c',
                 'common.term_truecolor=true',
                 '-c',
                 'common.spaces=4',
                 '-t',
                 'default.segment_data.hostname.before=H:',
                 '-p',
                 '.',
                 '-p',
                 '..',
                 '-R',
                 'smth={"abc":"def"}',
             ], {
                 'ext': ['shell'],
                 'side': 'left',
                 'renderer_module': '.zsh',
                 'last_exit_code': 10,
                 'last_pipe_status': [10, 20, 30],
                 'jobnum': 10,
                 'width': 100,
                 'config_override': {
                     'common': {
                         'term_truecolor': True,
                         'spaces': 4
                     }
                 },
                 'theme_override': {
                     'default': {
                         'segment_data': {
                             'hostname': {
                                 'before': 'H:'
                             }
                         }
                     }
                 },
                 'config_path': ['.', '..'],
                 'renderer_arg': {
                     'smth': {
                         'abc': 'def'
                     }
                 },
             }),
             (['shell', '-R', 'arg=true'], {
                 'ext': ['shell'],
                 'renderer_arg': {
                     'arg': True
                 }
             }),
             (['shell', '-R', 'arg=true', '-R', 'arg='], {
                 'ext': ['shell'],
                 'renderer_arg': {}
             }),
             (['shell', '-R', 'arg='], {
                 'ext': ['shell'],
                 'renderer_arg': {}
             }),
             (['shell', '-t', 'default.segment_info={"hostname": {}}'], {
                 'ext': ['shell'],
                 'theme_override': {
                     'default': {
                         'segment_info': {
                             'hostname': {}
                         }
                     }
                 },
             }),
             (['shell', '-c', 'common={ }'], {
                 'ext': ['shell'],
                 'config_override': {
                     'common': {}
                 }
             }),
         ]:
             args = parser.parse_args(argv)
             finish_args({}, args)
             for key, val in expargs.items():
                 self.assertEqual(getattr(args, key), val)
             for key, val in args.__dict__.items():
                 if key not in expargs:
                     self.assertFalse(
                         val,
                         msg=
                         'key {0} is {1} while it should be something false'
                         .format(key, val))
             self.assertFalse(err.getvalue() + out.getvalue(),
                              msg='unexpected output: {0!r} {1!r}'.format(
                                  err.getvalue(),
                                  out.getvalue(),
                              ))
Example #4
0
	def test_main_normal(self):
		parser = get_argparser()
		out = StrIO()
		err = StrIO()
		with replace_attr(sys, 'stdout', out, 'stderr', err):
			for argv, expargs in [
				(['shell'],               {'ext': ['shell']}),
				(['shell', '-r', '.zsh'], {'ext': ['shell'], 'renderer_module': '.zsh'}),
				([
					'shell',
					'left',
					'-r', '.zsh',
					'--last_exit_code', '10',
					'--last_pipe_status', '10 20 30',
					'--jobnum=10',
					'-w', '100',
					'-c', 'common.term_truecolor=true',
					'-c', 'common.spaces=4',
					'-t', 'default.segment_data.hostname.before=H:',
					'-p', '.',
					'-p', '..',
					'-R', 'smth={"abc":"def"}',
				], {
					'ext': ['shell'],
					'side': 'left',
					'renderer_module': '.zsh',
					'last_exit_code': 10,
					'last_pipe_status': [10, 20, 30],
					'jobnum': 10,
					'width': 100,
					'config': {'common': {'term_truecolor': True, 'spaces': 4}},
					'theme_option': {
						'default': {
							'segment_data': {
								'hostname': {
									'before': 'H:'
								}
							}
						}
					},
					'config_path': ['.', '..'],
					'renderer_arg': {'smth': {'abc': 'def'}},
				}),
				(['shell', '-R', 'arg=true'], {'ext': ['shell'], 'renderer_arg': {'arg': True}}),
				(['shell', '-R', 'arg=true', '-R', 'arg='], {'ext': ['shell'], 'renderer_arg': {}}),
				(['shell', '-R', 'arg='], {'ext': ['shell'], 'renderer_arg': {}}),
				(['shell', '-t', 'default.segment_info={"hostname": {}}'], {
					'ext': ['shell'],
					'theme_option': {
						'default': {
							'segment_info': {
								'hostname': {}
							}
						}
					},
				}),
				(['shell', '-c', 'common={ }'], {'ext': ['shell'], 'config': {'common': {}}}),
			]:
				args = parser.parse_args(argv)
				finish_args(args)
				for key, val in expargs.items():
					self.assertEqual(getattr(args, key), val)
				for key, val in args.__dict__.items():
					if key not in expargs:
						self.assertFalse(val, msg='key {0} is {1} while it should be something false'.format(key, val))
				self.assertFalse(err.getvalue() + out.getvalue(), msg='unexpected output: {0!r} {1!r}'.format(
					err.getvalue(),
					out.getvalue(),
				))