Skip to content

WIP. Empty window titles cause errors. #183 #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/fixtures/workspacebuilder/window_title_empty.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
session_name: Window index example
windows:
- window_name: ''
panes:
- echo "This window has an empty title"
- window_name: ""
panes:
- echo "So is this."
window_index: 5
- window_name:
panes:
- echo "And this one too."
30 changes: 30 additions & 0 deletions tests/test_workspacebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,3 +673,33 @@ def test_before_load_true_if_test_passes_with_args(server):

with temp_session(server) as session:
builder.build(session=session)

def test_window_title(session):
yaml_config = loadfixture("workspacebuilder/window_title_empty.yaml")
s = session
sconfig = kaptan.Kaptan(handler='yaml')
sconfig = sconfig.import_config(yaml_config).get()
sconfig = config.expand(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):
if w['window_name'] == '':
assert True
else:
print("Wname: ", w['window_name'])
assert False
'''
for w, wconf in builder.iter_create_windows(s):
for p in builder.iter_create_panes(w, wconf):
p = p
assert len(s._windows) == window_count
assert isinstance(w, Window)
assert w.show_window_option('main-pane-height') == 5

assert len(s._windows) == window_count
window_count += 1
w.select_layout(wconf['layout'])
'''
5 changes: 4 additions & 1 deletion tmuxp/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ def expand(sconf, cwd=None, parent=None):
if 'session_name' in sconf:
sconf['session_name'] = expandshell(sconf['session_name'])
if 'window_name' in sconf:
sconf['window_name'] = expandshell(sconf['window_name'])
if not (sconf['window_name'] is None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not (sconf['window_name'] is None):
if sconf['window_name'] is not None:

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not change the outcome of the test_window_title. As expected. The if statements - before and after the suggested changes - are equivalent. Were you expecting something different?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found something. window_name is being set to tmux. Hence the failing assertion. Now, need to dig where this is happening.

sconf['window_name'] = expandshell(sconf['window_name'])
else:
sconf['shell_command'] = 'tmux rename-session \'\''
if 'environment' in sconf:
for key in sconf['environment']:
val = sconf['environment'][key]
Expand Down
5 changes: 5 additions & 0 deletions tmuxp/workspacebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ def pane_has_same_path(p):
if all(pane_has_same_path(p) for p in w.panes):
wconf['start_directory'] = w.panes[0].current_path

if w.name == '':
empty_window_title = True
Comment on lines +387 to +388
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if w.name == '':
empty_window_title = True
empty_window_title = w.name == ''

Assures the variable is always declared

Should fix https://github.com/tmux-python/tmuxp/pull/189/checks?check_run_id=991200510#step:15:372:

                wconf['panes'].append(pconf)
>               if empty_window_title:
E               UnboundLocalError: local variable 'empty_window_title' referenced before assignment

tmuxp/workspacebuilder.py:416: UnboundLocalError

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That resolves the unbound variable. I am adding that change.


for p in w.panes:
pconf = {'shell_command': []}

Expand All @@ -410,6 +413,8 @@ def filter_interpretters_and_shells():
pconf = 'pane'

wconf['panes'].append(pconf)
if empty_window_title:
pconf['shell_command'].append('tmux rename-session \'\'')

sconf['windows'].append(wconf)

Expand Down