Skip to content

Commit 6239370

Browse files
committed
Fix #25. Selecting panes on load.
1 parent 177735f commit 6239370

File tree

5 files changed

+53
-11
lines changed

5 files changed

+53
-11
lines changed

CHANGES

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ Changelog
44

55
Here you can find the recent changes to tmuxp.
66

7+
0.1-rc3
8+
-------
9+
10+
- [bug] [tests] `Issue #25`_ - ``focus: true`` not working in panes. Add
11+
tests for focusing panes in config.
12+
- [internal] :meth:`Pane.select_pane()`.
13+
714
0.1-rc2
815
-------
916

TODO

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ TODO
77
Milestone 0.1
88
-------------
99

10-
- `Issue #25`_ - ``focus: true`` not working in panes.
11-
1210
Done
1311
""""
1412

13+
- `Issue #25`_ - ``focus: true`` not working in panes.
1514
- `Issue #15`_ - Pane ordering
1615
- `Issue #21`_ - Python 2.6 errors with directories in unit tests
1716
- ``shell_command_before`` for `teamocil`_.

tmuxp/pane.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,18 @@ def enter(self):
157157
"""
158158
self.tmux('send-keys', 'Enter')
159159

160+
def select_pane(self):
161+
"""Select pane. Return ``self``.
162+
163+
To select a window object asynchrously. If a ``pane`` object exists
164+
and is no longer longer the current window, ``w.select_pane()``
165+
will make ``p`` the current pane.
166+
167+
:rtype: :class:`pane`
168+
169+
"""
170+
return self.window.select_pane(self.get('pane_id'))
171+
160172
def __repr__(self):
161173
return "%s(%s %s)" % (
162174
self.__class__.__name__,

tmuxp/testsuite/test_workspacebuilder.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,19 @@ class FocusAndPaneIndexTest(TmuxTestCase):
121121
focus: true
122122
panes:
123123
- shell_command:
124-
- vim
124+
- cd ~
125125
- shell_command:
126-
- echo "hey"
126+
- cd /var
127+
focus: true
127128
- shell_command:
129+
- cd ~
128130
- echo "moo"
129131
- top
130-
focus: true
131132
- window_name: window 2
132133
panes:
133134
- shell_command:
134-
- vim
135-
rocus: true
135+
- top
136+
1ocus: true
136137
- shell_command:
137138
- echo "hey"
138139
- shell_command:
@@ -171,6 +172,20 @@ def test_split_windows(self):
171172
pane_indexes_should_be = [pane_base_index + x for x in range(0, 3)]
172173
self.assertListEqual(pane_indexes_should_be, pane_base_indexes)
173174

175+
w = self.session.attached_window()
176+
177+
self.assertNotEqual(w.get('window_name'), 'man')
178+
179+
pane_path = '/var'
180+
for i in range(30):
181+
p = w.attached_pane()
182+
p.server._update_panes()
183+
if p.get('pane_current_path') == pane_path:
184+
break
185+
time.sleep(.2)
186+
187+
self.assertEqual(p.get('pane_current_path'), pane_path)
188+
174189

175190
class WindowOptions(TmuxTestCase):
176191

tmuxp/workspacebuilder.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,27 @@ def build(self, session=None):
133133
assert(isinstance(session, Session))
134134

135135
focus = None
136+
136137
for w, wconf in self.iter_create_windows(session):
137138
assert(isinstance(w, Window))
138-
for p in self.iter_create_panes(w, wconf):
139+
140+
focus_pane = None
141+
for p, pconf in self.iter_create_panes(w, wconf):
139142
assert(isinstance(p, Pane))
140143
p = p
141144

142145
if 'layout' in wconf:
143146
w.select_layout(wconf['layout'])
144147

148+
if 'focus' in pconf and pconf['focus']:
149+
focus_pane = p
150+
145151
if 'focus' in wconf and wconf['focus']:
146152
focus = w
147153

154+
if focus_pane:
155+
focus_pane.select_pane()
156+
148157
if focus:
149158
focus.select_window()
150159

@@ -157,7 +166,7 @@ def iter_create_windows(self, s):
157166
Applies ``window_options`` to window.
158167
159168
:param session: :class:`Session` from the config
160-
:rtype: :class:`Window`
169+
:rtype: tuple(:class:`Window`, ``wconf``)
161170
162171
"""
163172
for i, wconf in enumerate(self.sconf['windows'], start=1):
@@ -202,7 +211,7 @@ def iter_create_panes(self, w, wconf):
202211
:type w: :class:`Window`
203212
:param wconf: config section for window
204213
:type wconf: :py:obj:`dict`
205-
:rtype: :class:`Pane`
214+
:rtype: tuple(:class:`Pane`, ``pconf``)
206215
207216
"""
208217
assert(isinstance(w, Window))
@@ -233,7 +242,7 @@ def iter_create_panes(self, w, wconf):
233242

234243
w.server._update_panes()
235244

236-
yield p
245+
yield p, pconf
237246

238247

239248
def freeze(session):

0 commit comments

Comments
 (0)