How to use the tmuxp.workspacebuilder.WorkspaceBuilder function in tmuxp

To help you get started, we’ve selected a few tmuxp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tmux-python / tmuxp / tests / test_workspacebuilder.py View on Github external
# test order of `panes` (and pane_index) above aganist pane_dirs
    pane_paths = [
        '/usr/bin',
        '/usr',
        '/usr/sbin',
        os.path.realpath(os.path.expanduser('~')),
    ]

    s = session
    sconfig = kaptan.Kaptan(handler='yaml')
    sconfig = sconfig.import_config(yaml_config).get()
    sconfig = config.expand(sconfig)
    sconfig = config.trickle(sconfig)

    builder = WorkspaceBuilder(sconf=sconfig)

    window_count = len(session._windows)  # current window count
    assert len(s._windows) == window_count
    for w, wconf in builder.iter_create_windows(s):
        for p in builder.iter_create_panes(w, wconf):
            w.select_layout('tiled')  # fix glitch with pane size
            p = p
            assert len(s._windows) == window_count

        assert isinstance(w, Window)

        assert len(s._windows) == window_count
        window_count += 1

    for w in session.windows:
        pane_base_index = w.show_window_option('pane-base-index', g=True)
github tmux-python / tmuxp / tests / test_workspacebuilder.py View on Github external
def test_focus_pane_index(session):
    yaml_config = loadfixture('workspacebuilder/focus_and_pane.yaml')

    sconfig = kaptan.Kaptan(handler='yaml')
    sconfig = sconfig.import_config(yaml_config).get()
    sconfig = config.expand(sconfig)
    sconfig = config.trickle(sconfig)

    builder = WorkspaceBuilder(sconf=sconfig)

    builder.build(session=session)

    assert session.attached_window.name == 'focused window'

    pane_base_index = int(
        session.attached_window.show_window_option('pane-base-index', g=True)
    )

    if not pane_base_index:
        pane_base_index = 0
    else:
        pane_base_index = int(pane_base_index)

    # get the pane index for each pane
    pane_base_indexes = []
github tmux-python / tmuxp / tests / test_workspacebuilder.py View on Github external
def test_environment_variables(session):
    yaml_config = loadfixture("workspacebuilder/environment_vars.yaml")
    sconfig = kaptan.Kaptan(handler='yaml')
    sconfig = sconfig.import_config(yaml_config).get()
    sconfig = config.expand(sconfig)

    builder = WorkspaceBuilder(sconf=sconfig)
    builder.build(session)

    assert session.show_environment('FOO') == 'BAR'
    assert session.show_environment('PATH') == '/tmp'
github tmux-python / tmuxp / tests / test_workspacebuilder.py View on Github external
def test_blank_pane_count(session):
    """:todo: Verify blank panes of various types build into workspaces."""
    yaml_config_file = os.path.join(example_dir, 'blank-panes.yaml')
    test_config = kaptan.Kaptan().import_config(yaml_config_file).get()
    test_config = config.expand(test_config)
    builder = WorkspaceBuilder(sconf=test_config)
    builder.build(session=session)

    assert session == builder.session

    window1 = session.find_where({'window_name': 'Blank pane test'})
    assert len(window1._panes) == 3

    window2 = session.find_where({'window_name': 'More blank panes'})
    assert len(window2._panes) == 3

    window3 = session.find_where({'window_name': 'Empty string (return)'})
    assert len(window3._panes) == 3

    window4 = session.find_where({'window_name': 'Blank with options'})
    assert len(window4._panes) == 2
github tmux-python / tmuxp / tests / test_workspacebuilder.py View on Github external
def test_window_index(session):
    yaml_config = loadfixture("workspacebuilder/window_index.yaml")
    proc = session.cmd('show-option', '-gv', 'base-index')
    base_index = int(proc.stdout[0])
    name_index_map = {'zero': 0 + base_index, 'one': 1 + base_index, 'five': 5}

    sconfig = kaptan.Kaptan(handler='yaml')
    sconfig = sconfig.import_config(yaml_config).get()
    sconfig = config.expand(sconfig)
    sconfig = config.trickle(sconfig)

    builder = WorkspaceBuilder(sconf=sconfig)

    for window, _ in builder.iter_create_windows(session):
        expected_index = name_index_map[window['window_name']]
        assert int(window['window_index']) == expected_index
github tmux-python / tmuxp / tests / test_workspacebuilder.py View on Github external
def test_automatic_rename_option(session):
    """With option automatic-rename: on."""
    yaml_config = loadfixture("workspacebuilder/window_automatic_rename.yaml")
    s = session
    sconfig = kaptan.Kaptan(handler='yaml')
    sconfig = sconfig.import_config(yaml_config).get()

    builder = WorkspaceBuilder(sconf=sconfig)

    window_count = len(session._windows)  # current window count
    assert len(s._windows) == window_count
    for w, wconf in builder.iter_create_windows(s):

        for p in builder.iter_create_panes(w, wconf):
            w.select_layout('tiled')  # fix glitch with pane size
            p = p
            assert len(s._windows), window_count
        assert isinstance(w, Window)
        assert w.show_window_option('automatic-rename') == 'on'

        assert len(s._windows) == window_count

        window_count += 1
        w.select_layout(wconf['layout'])
github tmux-python / tmuxp / tests / test_workspacebuilder.py View on Github external
def test_session_options(session):
    yaml_config = loadfixture("workspacebuilder/session_options.yaml")
    s = session
    sconfig = kaptan.Kaptan(handler='yaml')
    sconfig = sconfig.import_config(yaml_config).get()
    sconfig = config.expand(sconfig)

    builder = WorkspaceBuilder(sconf=sconfig)
    builder.build(session=session)

    assert "/bin/sh" in s.show_option('default-shell')
    assert "/bin/sh" in s.show_option('default-command')
github tmux-python / tmuxp / tests / test_workspacebuilder.py View on Github external
config_script_completes = loadfixture(
        "workspacebuilder/config_script_completes.yaml"
    )

    assert os.path.exists(os.path.join(fixtures_dir, 'script_complete.sh'))
    sconfig = kaptan.Kaptan(handler='yaml')
    yaml = config_script_completes.format(
        fixtures_dir=fixtures_dir,
        script_complete=os.path.join(fixtures_dir, 'script_complete.sh') + ' -v',
    )

    sconfig = sconfig.import_config(yaml).get()
    sconfig = config.expand(sconfig)
    sconfig = config.trickle(sconfig)

    builder = WorkspaceBuilder(sconf=sconfig)

    with temp_session(server) as session:
        builder.build(session=session)
github tmux-python / tmuxp / tests / test_workspacebuilder.py View on Github external
def test_start_directory(session, tmpdir):
    yaml_config = loadfixture("workspacebuilder/start_directory.yaml")
    test_dir = str(tmpdir.mkdir('foo bar'))
    test_config = yaml_config.format(TMP_DIR=str(tmpdir), TEST_DIR=test_dir)

    sconfig = kaptan.Kaptan(handler='yaml')
    sconfig = sconfig.import_config(test_config).get()
    sconfig = config.expand(sconfig)
    sconfig = config.trickle(sconfig)

    builder = WorkspaceBuilder(sconf=sconfig)
    builder.build(session=session)

    assert session == builder.session
    dirs = ['/usr/bin', '/dev', test_dir, '/usr', '/usr']

    for path, window in zip(dirs, session.windows):
        for p in window.panes:
            while retry():
                p.server._update_panes()
                pane_path = p.current_path
                if pane_path is None:
                    pass
                elif path in pane_path or pane_path == path:
                    result = path == pane_path or path in pane_path
                    break
github tmux-python / tmuxp / tests / test_workspacebuilder.py View on Github external
def test_before_load_throw_error_if_retcode_error(server):
    config_script_fails = loadfixture("workspacebuilder/config_script_fails.yaml")
    sconfig = kaptan.Kaptan(handler='yaml')
    yaml = config_script_fails.format(
        fixtures_dir=fixtures_dir,
        script_failed=os.path.join(fixtures_dir, 'script_failed.sh'),
    )

    sconfig = sconfig.import_config(yaml).get()
    sconfig = config.expand(sconfig)
    sconfig = config.trickle(sconfig)

    builder = WorkspaceBuilder(sconf=sconfig)

    with temp_session(server) as sess:
        session_name = sess.name

        with pytest.raises(exc.BeforeLoadScriptError):
            builder.build(session=sess)

        result = server.has_session(session_name)
        assert not result, "Kills session if before_script exits with errcode"