Exemple #1
0
def output_lister(pl, segment_info):
    '''List all outputs in segment_info format
	'''

    return ((updated(segment_info, output=output['name']), {
        'draw_inner_divider': None
    }) for output in get_connected_xrandr_outputs(pl))
Exemple #2
0
def workspace_lister(pl, segment_info, only_show=None, output=None):
    '''List all workspaces in segment_info format

	Sets the segment info values of ``workspace`` and ``output`` to the name of 
	the i3 workspace and the ``xrandr`` output respectively and the keys
	``"visible"``, ``"urgent"`` and ``"focused"`` to a boolean indicating these
	states.

	:param list only_show:
		Specifies which workspaces to list. Valid entries are ``"visible"``, 
		``"urgent"`` and ``"focused"``. If omitted or ``null`` all workspaces 
		are listed.

	:param str output:
		May be set to the name of an X output. If specified, only workspaces 
		on that output are listed. Overrides automatic output detection by 
		the lemonbar renderer and bindings. Set to ``false`` to force 
		all workspaces to be shown.
	'''

    if output == None:
        output = output or segment_info.get('output')

    return ((updated(
        segment_info,
        output=w.output,
        workspace=w,
    ), {
        'draw_inner_divider': None
    }) for w in get_i3_connection().get_workspaces()
            if (((not only_show or any(getattr(w, typ)
                                       for typ in only_show)) and (
                                           not output or w.output == output))))
Exemple #3
0
def output_lister(pl, segment_info):
	'''List all outputs in segment_info format
	'''

	return (
		(
			updated(segment_info, output=output['name']),
			{
				'draw_inner_divider': None
			}
		)
		for output in get_connected_xrandr_outputs(pl)
	)
Exemple #4
0
def workspace_lister(pl, segment_info, only_show=None, output=None):
	'''List all workspaces in segment_info format

	Sets the segment info values of ``workspace`` and ``output`` to the name of 
	the i3 workspace and the ``xrandr`` output respectively and the keys
	``"visible"``, ``"urgent"`` and ``"focused"`` to a boolean indicating these
	states.

	:param list only_show:
		Specifies which workspaces to list. Valid entries are ``"visible"``, 
		``"urgent"`` and ``"focused"``. If omitted or ``null`` all workspaces 
		are listed.

	:param str output:
		May be set to the name of an X output. If specified, only workspaces 
		on that output are listed. Overrides automatic output detection by 
		the lemonbar renderer and bindings. Set to ``false`` to force 
		all workspaces to be shown.
	'''

	if output == None:
		output = output or segment_info.get('output')

	return (
		(
			updated(
				segment_info,
				output=w['output'],
				workspace={
					'name': w['name'],
					'visible': w['visible'],
					'urgent': w['urgent'],
					'focused': w['focused'],
				},
			),
			{
				'draw_inner_divider': None
			}
		)
		for w in get_i3_connection().get_workspaces()
		if (((not only_show or any(w[typ] for typ in only_show))
		    and (not output or w['output'] == output)))
	)
Exemple #5
0
def main(attempts=3):
	vterm_path = os.path.join(TEST_ROOT, 'path')

	tmux_exe = os.path.join(vterm_path, 'tmux')

	socket_path = os.path.abspath('tmux-socket-{0}'.format(attempts))
	if os.path.exists(socket_path):
		os.unlink(socket_path)

	env = get_env(vterm_path, TEST_ROOT, {
		'POWERLINE_THEME_OVERRIDES': ';'.join((
			key + '=' + json.dumps(val)
			for key, val in (
				('default.segments.right', [{
					'type': 'string',
					'name': 's1',
					'highlight_groups': ['cwd'],
					'priority':50,
				}]),
				('default.segments.left', [{
					'type': 'string',
					'name': 's2',
					'highlight_groups': ['background'],
					'priority':20,
				}]),
				('default.segment_data.s1.contents', 'S1 string here'),
				('default.segment_data.s2.contents', 'S2 string here'),
			)
		)),
		'POWERLINE_TMUX_SOCKET_PATH': socket_path,
	})

	conf_path = os.path.abspath('powerline/bindings/tmux/powerline.conf')
	conf_line = 'source "' + (
		conf_path.replace('\\', '\\\\').replace('"', '\\"')) + '"\n'
	conf_file = os.path.realpath(os.path.join(TEST_ROOT, 'tmux.conf'))
	with open(conf_file, 'w') as cf_fd:
		cf_fd.write(conf_line)

	tmux_version = get_tmux_version(get_fallback_logger())

	dim = MutableDimensions(rows=50, cols=200)

	def prepare_test_1(p):
		sleep(5)

	def prepare_test_2(p):
		dim.cols = 40
		p.resize(dim)
		sleep(5)

	base_attrs = {
		((0, 0, 0), (243, 243, 243), 1, 0, 0): 'lead',
		((243, 243, 243), (11, 11, 11), 0, 0, 0): 'leadsep',
		((255, 255, 255), (11, 11, 11), 0, 0, 0): 'bg',
		((199, 199, 199), (88, 88, 88), 0, 0, 0): 'cwd',
		((88, 88, 88), (11, 11, 11), 0, 0, 0): 'cwdhsep',
		((0, 0, 0), (0, 224, 0), 0, 0, 0): 'defstl',
	}
	tests = (
		{
			'expected_result': get_expected_result(
				tmux_version,
				expected_result_old=(
					'{lead: 0 }{leadsep: }{bg: S2 string here  }'
					'{4: 0  }{cwdhsep:| }{6:bash  }'
					'{bg: }{4: 1- }{cwdhsep:| }{6:bash  }'
					'{bg: }{7: }{8:2* | }{9:bash }{10: }'
					'{bg:' + (' ' * 124) + '}'
					'{cwdhsep: }{cwd: S1 string here }', updated(base_attrs, {
						((133, 133, 133), (11, 11, 11), 0, 0, 0): 4,
						((188, 188, 188), (11, 11, 11), 0, 0, 0): 6,
						((11, 11, 11), (0, 102, 153), 0, 0, 0): 7,
						((102, 204, 255), (0, 102, 153), 0, 0, 0): 8,
						((255, 255, 255), (0, 102, 153), 1, 0, 0): 9,
						((0, 102, 153), (11, 11, 11), 0, 0, 0): 10,
					})),
				expected_result_1_8=(
					'{lead: 0 }{leadsep: }{bg: S2 string here  }'
					'{4: 0  }{cwdhsep:| }{6:bash  }'
					'{bg: }{4: 1- }{cwdhsep:| }{7:bash  }'
					'{bg: }{8: }{9:2* | }{10:bash }{7: }'
					'{bg:' + (' ' * 124) + '}'
					'{cwdhsep: }{cwd: S1 string here }', updated(base_attrs, {
						((133, 133, 133), (11, 11, 11), 0, 0, 0): 4,
						((188, 188, 188), (11, 11, 11), 0, 0, 0): 6,
						((0, 102, 153), (11, 11, 11), 0, 0, 0): 7,
						((11, 11, 11), (0, 102, 153), 0, 0, 0): 8,
						((102, 204, 255), (0, 102, 153), 0, 0, 0): 9,
						((255, 255, 255), (0, 102, 153), 1, 0, 0): 10,
					})),
				expected_result_2_0=(
					'{lead: 0 }{leadsep: }{bg: S2 string here }'
					'{4: 0  }{cwdhsep:| }{6:bash  }'
					'{bg: }{4: 1- }{cwdhsep:| }{7:bash  }'
					'{bg: }{8: }{9:2* | }{10:bash }{7: }'
					'{bg:' + (' ' * 125) + '}'
					'{cwdhsep: }{cwd: S1 string here }', updated(base_attrs, {
						((133, 133, 133), (11, 11, 11), 0, 0, 0): 4,
						((188, 188, 188), (11, 11, 11), 0, 0, 0): 6,
						((0, 102, 153), (11, 11, 11), 0, 0, 0): 7,
						((11, 11, 11), (0, 102, 153), 0, 0, 0): 8,
						((102, 204, 255), (0, 102, 153), 0, 0, 0): 9,
						((255, 255, 255), (0, 102, 153), 1, 0, 0): 10,
					})),
			),
			'prep_cb': prepare_test_1,
			'row': dim.rows - 1,
		}, {
			'expected_result': get_expected_result(
				tmux_version,
				expected_result_old=('{bg:' + (' ' * 40) + '}', base_attrs),
				expected_result_1_7=(
					'{lead: 0 }'
					'{leadsep: }{bg: <}{4:h  }{bg: }{5: }'
					'{6:2* | }{7:bash }{8: }{bg: }{cwdhsep: }'
					'{cwd: S1 string here }', updated(base_attrs, {
						((188, 188, 188), (11, 11, 11), 0, 0, 0): 4,
						((11, 11, 11), (0, 102, 153), 0, 0, 0): 5,
						((102, 204, 255), (0, 102, 153), 0, 0, 0): 6,
						((255, 255, 255), (0, 102, 153), 1, 0, 0): 7,
						((0, 102, 153), (11, 11, 11), 0, 0, 0): 8,
					})),
				expected_result_1_8=(
					'{lead: 0 }'
					'{leadsep: }{bg: <}{4:h  }{bg: }{5: }'
					'{6:2* | }{7:bash }{4: }{bg: }{cwdhsep: }'
					'{cwd: S1 string here }', updated(base_attrs, {
						((0, 102, 153), (11, 11, 11), 0, 0, 0): 4,
						((11, 11, 11), (0, 102, 153), 0, 0, 0): 5,
						((102, 204, 255), (0, 102, 153), 0, 0, 0): 6,
						((255, 255, 255), (0, 102, 153), 1, 0, 0): 7,
					})),
				expected_result_2_0=(
					'{lead: 0 }'
					'{leadsep: }{bg:<}{4:ash  }{bg: }{5: }'
					'{6:2* | }{7:bash }{4: }{cwdhsep: }'
					'{cwd: S1 string here }', updated(base_attrs, {
						((0, 102, 153), (11, 11, 11), 0, 0, 0): 4,
						((11, 11, 11), (0, 102, 153), 0, 0, 0): 5,
						((102, 204, 255), (0, 102, 153), 0, 0, 0): 6,
						((255, 255, 255), (0, 102, 153), 1, 0, 0): 7,
					})),
			),
			'prep_cb': prepare_test_2,
			'row': dim.rows - 1,
		}
	)

	args = [
		# Specify full path to tmux socket (testing tmux instance must not 
		# interfere with user one)
		'-S', socket_path,
		# Force 256-color mode
		'-2',
		# Request verbose logging just in case
		'-v',
		# Specify configuration file
		'-f', conf_file,
		# Run bash three times
		'new-session', 'bash --norc --noprofile -i', ';',
		'new-window', 'bash --norc --noprofile -i', ';',
		'new-window', 'bash --norc --noprofile -i', ';',
	]

	with PowerlineTestSuite('tmux') as suite:
		return do_terminal_tests(
			tests=tests,
			cmd=tmux_exe,
			dim=dim,
			args=args,
			env=env,
			cwd=TEST_ROOT,
			fin_cb=tmux_fin_cb,
			last_attempt_cb=print_tmux_logs,
			suite=suite,
		)
Exemple #6
0
def main(attempts=3):
	vterm_path = os.path.join(VTERM_TEST_DIR, 'path')

	tmux_exe = os.path.join(vterm_path, 'tmux')

	socket_path = os.path.abspath('tmux-socket-{0}'.format(attempts))
	if os.path.exists(socket_path):
		os.unlink(socket_path)

	env = get_env(vterm_path, VTERM_TEST_DIR, {
		'POWERLINE_THEME_OVERRIDES': ';'.join((
			key + '=' + json.dumps(val)
			for key, val in (
				('default.segments.right', [{
					'type': 'string',
					'name': 's1',
					'highlight_groups': ['cwd'],
					'priority':50,
				}]),
				('default.segments.left', [{
					'type': 'string',
					'name': 's2',
					'highlight_groups': ['background'],
					'priority':20,
				}]),
				('default.segment_data.s1.contents', 'S1 string here'),
				('default.segment_data.s2.contents', 'S2 string here'),
			)
		)),
		'POWERLINE_TMUX_SOCKET_PATH': socket_path,
	})

	conf_path = os.path.abspath('powerline/bindings/tmux/powerline.conf')
	conf_line = 'source "' + (
		conf_path.replace('\\', '\\\\').replace('"', '\\"')) + '"\n'
	conf_file = os.path.realpath(os.path.join(VTERM_TEST_DIR, 'tmux.conf'))
	with open(conf_file, 'w') as cf_fd:
		cf_fd.write(conf_line)

	tmux_version = get_tmux_version(get_fallback_logger())

	dim = MutableDimensions(rows=50, cols=200)

	def prepare_test_1(p):
		sleep(5)

	def prepare_test_2(p):
		dim.cols = 40
		p.resize(dim)
		sleep(5)

	base_attrs = {
		((0, 0, 0), (243, 243, 243), 1, 0, 0): 'lead',
		((243, 243, 243), (11, 11, 11), 0, 0, 0): 'leadsep',
		((255, 255, 255), (11, 11, 11), 0, 0, 0): 'bg',
		((199, 199, 199), (88, 88, 88), 0, 0, 0): 'cwd',
		((88, 88, 88), (11, 11, 11), 0, 0, 0): 'cwdhsep',
		((0, 0, 0), (0, 224, 0), 0, 0, 0): 'defstl',
	}
	tests = (
		{
			'expected_result': get_expected_result(
				tmux_version,
				expected_result_old=(
					'{lead: 0 }{leadsep: }{bg: S2 string here  }'
					'{4: 0  }{cwdhsep:| }{6:bash  }'
					'{bg: }{4: 1- }{cwdhsep:| }{6:bash  }'
					'{bg: }{7: }{8:2* | }{9:bash }{10: }'
					'{bg:' + (' ' * 124) + '}'
					'{cwdhsep: }{cwd: S1 string here }', updated(base_attrs, {
						((133, 133, 133), (11, 11, 11), 0, 0, 0): 4,
						((188, 188, 188), (11, 11, 11), 0, 0, 0): 6,
						((11, 11, 11), (0, 102, 153), 0, 0, 0): 7,
						((102, 204, 255), (0, 102, 153), 0, 0, 0): 8,
						((255, 255, 255), (0, 102, 153), 1, 0, 0): 9,
						((0, 102, 153), (11, 11, 11), 0, 0, 0): 10,
					})),
				expected_result_1_8=(
					'{lead: 0 }{leadsep: }{bg: S2 string here  }'
					'{4: 0  }{cwdhsep:| }{6:bash  }'
					'{bg: }{4: 1- }{cwdhsep:| }{7:bash  }'
					'{bg: }{8: }{9:2* | }{10:bash }{7: }'
					'{bg:' + (' ' * 124) + '}'
					'{cwdhsep: }{cwd: S1 string here }', updated(base_attrs, {
						((133, 133, 133), (11, 11, 11), 0, 0, 0): 4,
						((188, 188, 188), (11, 11, 11), 0, 0, 0): 6,
						((0, 102, 153), (11, 11, 11), 0, 0, 0): 7,
						((11, 11, 11), (0, 102, 153), 0, 0, 0): 8,
						((102, 204, 255), (0, 102, 153), 0, 0, 0): 9,
						((255, 255, 255), (0, 102, 153), 1, 0, 0): 10,
					})),
				expected_result_2_0=(
					'{lead: 0 }{leadsep: }{bg: S2 string here }'
					'{4: 0  }{cwdhsep:| }{6:bash  }'
					'{bg: }{4: 1- }{cwdhsep:| }{7:bash  }'
					'{bg: }{8: }{9:2* | }{10:bash }{7: }'
					'{bg:' + (' ' * 125) + '}'
					'{cwdhsep: }{cwd: S1 string here }', updated(base_attrs, {
						((133, 133, 133), (11, 11, 11), 0, 0, 0): 4,
						((188, 188, 188), (11, 11, 11), 0, 0, 0): 6,
						((0, 102, 153), (11, 11, 11), 0, 0, 0): 7,
						((11, 11, 11), (0, 102, 153), 0, 0, 0): 8,
						((102, 204, 255), (0, 102, 153), 0, 0, 0): 9,
						((255, 255, 255), (0, 102, 153), 1, 0, 0): 10,
					})),
			),
			'prep_cb': prepare_test_1,
			'row': dim.rows - 1,
		}, {
			'expected_result': get_expected_result(
				tmux_version,
				expected_result_old=('{bg:' + (' ' * 40) + '}', base_attrs),
				expected_result_1_7=(
					'{lead: 0 }'
					'{leadsep: }{bg: <}{4:h  }{bg: }{5: }'
					'{6:2* | }{7:bash }{8: }{bg: }{cwdhsep: }'
					'{cwd: S1 string here }', updated(base_attrs, {
						((188, 188, 188), (11, 11, 11), 0, 0, 0): 4,
						((11, 11, 11), (0, 102, 153), 0, 0, 0): 5,
						((102, 204, 255), (0, 102, 153), 0, 0, 0): 6,
						((255, 255, 255), (0, 102, 153), 1, 0, 0): 7,
						((0, 102, 153), (11, 11, 11), 0, 0, 0): 8,
					})),
				expected_result_1_8=(
					'{lead: 0 }'
					'{leadsep: }{bg: <}{4:h  }{bg: }{5: }'
					'{6:2* | }{7:bash }{4: }{bg: }{cwdhsep: }'
					'{cwd: S1 string here }', updated(base_attrs, {
						((0, 102, 153), (11, 11, 11), 0, 0, 0): 4,
						((11, 11, 11), (0, 102, 153), 0, 0, 0): 5,
						((102, 204, 255), (0, 102, 153), 0, 0, 0): 6,
						((255, 255, 255), (0, 102, 153), 1, 0, 0): 7,
					})),
				expected_result_2_0=(
					'{lead: 0 }'
					'{leadsep: }{bg:<}{4:ash  }{bg: }{5: }'
					'{6:2* | }{7:bash }{4: }{cwdhsep: }'
					'{cwd: S1 string here }', updated(base_attrs, {
						((0, 102, 153), (11, 11, 11), 0, 0, 0): 4,
						((11, 11, 11), (0, 102, 153), 0, 0, 0): 5,
						((102, 204, 255), (0, 102, 153), 0, 0, 0): 6,
						((255, 255, 255), (0, 102, 153), 1, 0, 0): 7,
					})),
			),
			'prep_cb': prepare_test_2,
			'row': dim.rows - 1,
		}
	)

	args = [
		# Specify full path to tmux socket (testing tmux instance must not 
		# interfere with user one)
		'-S', socket_path,
		# Force 256-color mode
		'-2',
		# Request verbose logging just in case
		'-v',
		# Specify configuration file
		'-f', conf_file,
		# Run bash three times
		'new-session', 'bash --norc --noprofile -i', ';',
		'new-window', 'bash --norc --noprofile -i', ';',
		'new-window', 'bash --norc --noprofile -i', ';',
	]

	return do_terminal_tests(
		tests=tests,
		cmd=tmux_exe,
		dim=dim,
		args=args,
		env=env,
		cwd=VTERM_TEST_DIR,
		fin_cb=tmux_fin_cb,
		last_attempt_cb=print_tmux_logs,
	)