Skip to content

Commit 5dc959c

Browse files
committed
Fix #15 pane ordering
1 parent 7e9b868 commit 5dc959c

File tree

5 files changed

+90
-20
lines changed

5 files changed

+90
-20
lines changed

CHANGES

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ Here you can find the recent changes to tmuxp.
1111

1212
- [internal] :meth:`Window.show_window_options`,
1313
:meth:`Window.show_window_option` now accept ``g`` to pass in ``-g``.
14+
- [internal] Behavioral changes in the WorkspaceBuilder to fix pane
15+
ordering `Issue #15`_.
16+
- [tests] WorkspaceBuilder tests have been improved to use async better.
17+
18+
.. _Issue #15: https://github.com/tony/tmuxp/issues/15
19+
1420

1521
2013-11-17
1622
''''''''''

TODO

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ Done
3838
Milestone 0.2
3939
-------------
4040

41+
Major
42+
"""""
43+
44+
- Fix inconsistencies / syncing with ``.get`` on Windows and panes. Always
45+
get freshest data.
46+
- Validate the data types passed back and forth between options and pane,
47+
window, session proprties. (Create a util method that maps key values to
48+
a type).
49+
- Unit test the above.
50+
4151
- ``tmuxp freeze`` add autogenerated command to yaml configs (won't work w/ json)
4252
- `pep8`_, `pep257`_ for tests. (ongoing)
4353
- if no ``window_name`` in config, option ``automatic_rename: on`` by

tmuxp/testsuite/test_workspacebuilder.py

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
from __future__ import absolute_import, division, print_function, with_statement
33

44
import os
5+
import sys
56
import logging
67
import time
78
import kaptan
8-
from .. import Window, config, exc
9+
from .. import Window, config, exc, util
910
from ..workspacebuilder import WorkspaceBuilder
1011
from .helpers import TmuxTestCase
1112

@@ -132,7 +133,6 @@ def test_split_windows(self):
132133
s = self.session
133134
sconfig = kaptan.Kaptan(handler='yaml')
134135
sconfig = sconfig.import_config(self.yaml_config).get()
135-
import sys
136136

137137
builder = WorkspaceBuilder(sconf=sconfig)
138138

@@ -247,24 +247,34 @@ def test_automatic_rename_option(self):
247247
window_count += 1
248248
w.select_layout(wconf['layout'])
249249

250-
w = s.attached_window()
250+
self.assertNotEqual(s.get('session_name'), 'tmuxp')
251+
w = s.windows[0]
251252

252253
for i in range(30):
253-
w = s.attached_window()
254-
if w['window_name'] == 'man':
254+
if w.get('window_name') != 'man':
255255
break
256256
time.sleep(.2)
257257

258-
self.assertEqual(w.get('window_name'), 'man')
258+
self.assertNotEqual(w.get('window_name'), 'man')
259+
260+
pane_base_index = w.show_window_option('pane-base-index', g=True)
261+
w.select_pane(pane_base_index)
262+
263+
for i in range(30):
264+
self.session.server._update_windows()
265+
if w.get('window_name') == 'man':
266+
break
267+
time.sleep(.2)
268+
269+
self.assertEqual(w.get('window_name'), unicode('man'))
259270

260271
w.select_pane('-D')
261272
for i in range(30):
262-
w = s.attached_window()
263273
if w['window_name'] != 'man':
264274
break
265275
time.sleep(.2)
266276

267-
self.assertNotEqual(w.get('window_name'), 'man')
277+
self.assertEqual(w.get('window_name'), unicode('man'))
268278

269279

270280
class BlankPaneTest(TmuxTestCase):
@@ -342,8 +352,6 @@ def test_start_directory(self):
342352
sconfig = config.expand(sconfig)
343353
sconfig = config.trickle(sconfig)
344354

345-
logger.error(sconfig)
346-
347355
builder = WorkspaceBuilder(sconf=sconfig)
348356
builder.build(session=self.session)
349357

@@ -376,6 +384,14 @@ class PaneOrderingTest(TmuxTestCase):
376384
"""
377385

378386
def test_pane_order(self):
387+
388+
# test order of `panes` (and pane_index) above aganist pane_dirs
389+
pane_paths = [
390+
'/var/log',
391+
'/sys',
392+
'/sbin',
393+
'/tmp'
394+
]
379395
s = self.session
380396
sconfig = kaptan.Kaptan(handler='yaml')
381397
sconfig = sconfig.import_config(self.yaml_config).get()
@@ -399,11 +415,19 @@ def test_pane_order(self):
399415

400416
for w in self.session.windows:
401417
import time
402-
time.sleep(.5)
403-
for p_index, p in enumerate(w.list_panes(), start=w.show_window_option('pane-base-index', g=True)):
404-
#for p in w.list_panes():
405-
logger.error(p.get('pane_current_path'))
418+
time.sleep(1)
419+
pane_base_index = w.show_window_option('pane-base-index', g=True)
420+
for p_index, p in enumerate(w.list_panes(), start=pane_base_index):
406421
self.assertEqual(int(p_index), int(p.get('pane_index')))
407-
logger.error('pane-base-index: %s, p_index: %s, pane_index: %s' % (
408-
w.show_window_option('pane-base-index', g=True), p_index, p.get('pane_index')
409-
))
422+
423+
# pane-base-index start at base-index, pane_paths always start
424+
# at 0 since python list.
425+
pane_path = pane_paths[p_index - pane_base_index]
426+
427+
for i in range(30):
428+
p.server._update_panes()
429+
if p.get('pane_current_path') == pane_path:
430+
break
431+
time.sleep(.2)
432+
433+
self.assertEqual(p.get('pane_current_path'), pane_path)

tmuxp/window.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,18 @@ def move_window(self, destination):
287287

288288
self.server._update_windows()
289289

290+
def select_window(self):
291+
"""Select window. Return ``self``.
292+
293+
To select a window object asynchrously. If a ``window`` object exists
294+
and is no longer longer the current window, ``w.select_window()``
295+
will make ``w`` the current window.
296+
297+
:rtype: :class:`Window`
298+
299+
"""
300+
return self.session.select_window(self.get('window_id'))
301+
290302
def select_pane(self, target_pane):
291303
"""Return selected :class:`Pane` through ``$ tmux select-pane``.
292304
@@ -307,6 +319,10 @@ def select_pane(self, target_pane):
307319

308320
return self.attached_pane()
309321

322+
def last_pane(self):
323+
"""Return last pane."""
324+
return self.select_pane('-l')
325+
310326
def split_window(self, target=None, attach=True):
311327
"""Split window and return the created :class:`Pane`.
312328

tmuxp/workspacebuilder.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def build(self, session=None):
132132

133133
assert(isinstance(session, Session))
134134

135+
focus = None
135136
for w, wconf in self.iter_create_windows(session):
136137
assert(isinstance(w, Window))
137138
for p in self.iter_create_panes(w, wconf):
@@ -141,6 +142,12 @@ def build(self, session=None):
141142
if 'layout' in wconf:
142143
w.select_layout(wconf['layout'])
143144

145+
if 'focus' in wconf and wconf['focus']:
146+
focus = w
147+
148+
if focus:
149+
focus.select_window()
150+
144151
def iter_create_windows(self, s):
145152
"""Return :class:`Window` iterating through session config dict.
146153
@@ -200,13 +207,20 @@ def iter_create_panes(self, w, wconf):
200207
"""
201208
assert(isinstance(w, Window))
202209

203-
for pindex, pconf in enumerate(wconf['panes'], start=1):
204-
if pindex != int(1):
205-
p = w.split_window(attach=False)
210+
pane_base_index = int(w.show_window_option('pane-base-index', g=True))
211+
212+
for pindex, pconf in enumerate(wconf['panes'], start=pane_base_index):
213+
if pindex != int(pane_base_index):
214+
p = w.split_window(
215+
attach=True,
216+
#target=w.list_panes()[-1].get('pane_index')
217+
)
206218
assert(isinstance(p, Pane))
219+
assert(p.get('pane_index'), pane_base_index)
207220
else:
208221
p = w.attached_pane()
209222
assert(isinstance(p, Pane))
223+
assert(p.get('pane_index'), pindex)
210224

211225
if 'layout' in wconf:
212226
w.select_layout(wconf['layout'])

0 commit comments

Comments
 (0)