Permalink
Browse files

Add compatibility notes across the board. Use *_name as *_id for sess…

…ion and window since *id doesn't exist until 1.8
  • Loading branch information...
1 parent 1e689ce commit 3bdf75bdefba6dad0df8f9c2d96505423b75a74b @tony committed Oct 19, 2013
Showing with 137 additions and 18 deletions.
  1. +88 −0 manual/NOTES.rst
  2. +17 −6 tmuxp/server.py
  3. +7 −3 tmuxp/session.py
  4. +2 −1 tmuxp/testsuite/test_server.py
  5. +23 −8 tmuxp/window.py
View
@@ -0,0 +1,88 @@
+===================
+Compatibility notes
+===================
+
+master
+------
+
+src: http://sourceforge.net/p/tmux/tmux-code/ci/master/tree/
+
+1.8
+---
+
+src: http://sourceforge.net/p/tmux/tmux-code/ci/1.8/tree/
+
+1.7
+---
+
+src: http://sourceforge.net/p/tmux/tmux-code/ci/1.7/tree/
+
+1.6
+---
+
+src: http://sourceforge.net/p/tmux/tmux-code/ci/1.6/tree/
+
+new-window
+""""""""""
+
+src: http://sourceforge.net/p/tmux/tmux-code/ci/1.6/tree/cmd-new-window.c
+
+.. code-block:: c
+
+ if (args_has(args, 'P'))
+ ctx->print(ctx, "%s:%u", s->name, wl->idx);
+ return (0);
+
+split-window
+""""""""""""
+
+src: http://sourceforge.net/p/tmux/tmux-code/ci/1.6/tree/cmd-split-window.c
+
+.. code-block:: c
+
+ if (args_has(args, 'P')) {
+ if (window_pane_index(new_wp, &paneidx) != 0)
+ fatalx("index not found");
+ ctx->print(ctx, "%s:%u.%u", s->name, wl->idx, paneidx);
+ }
+ return (0);
+
+list-sessions
+"""""""""""""
+
+src: http://sourceforge.net/p/tmux/tmux-code/ci/1.6/tree/cmd-list-sessions.c
+
+.. code-block:: c
+
+ template = "#{session_name}: #{session_windows} windows "
+ "(created #{session_created_string}) [#{session_width}x"
+ "#{session_height}]#{?session_grouped, (group ,}"
+ "#{session_group}#{?session_grouped,),}"
+ "#{?session_attached, (attached),}";
+
+list-windows
+""""""""""""
+
+src: http://sourceforge.net/p/tmux/tmux-code/ci/1.6/tree/cmd-list-windows.c
+
+.. code-block:: c
+
+ template = "#{session_name}:#{window_index}: "
+ "#{window_name} "
+ "[#{window_width}x#{window_height}] "
+ "[layout #{window_layout}]"
+ "#{?window_active, (active),}";
+
+
+list-panes
+""""""""""
+
+src: http://sourceforge.net/p/tmux/tmux-code/ci/1.6/tree/cmd-list-panes.c
+
+.. code-block:: c
+
+ template = "#{session_name}:#{window_index}.#{pane_index}: "
+ "[#{pane_width}x#{pane_height}] [history "
+ "#{history_size}/#{history_limit}, "
+ "#{history_bytes} bytes] #{pane_id}"
+ "#{?pane_active, (active),}#{?pane_dead, (dead),}";
View
@@ -120,11 +120,11 @@ def _list_sessions(self):
sformats, session.split('\t'))) for session in sessions]
# clear up empty dict
- new_sessions = [
+ sessions = [
dict((k, v) for k, v in session.items() if v) for session in sessions
]
- return new_sessions
+ return sessions
@property
def _sessions(self):
@@ -139,11 +139,11 @@ def list_sessions(self):
return [
Session(server=self, **s) for s in self._sessions
]
- children = list_sessions
@property
def sessions(self):
return self.list_sessions()
+ children = sessions
def __list_windows(self):
'''
@@ -181,6 +181,11 @@ def _list_windows(self):
dict((k, v) for k, v in window.items() if v) for window in windows
]
+ # tmux < 1.8 doesn't have window_id, use window_name
+ for w in windows:
+ if not 'window_id' in w:
+ w['window_id'] = w['window_name']
+
if self._windows:
# http://stackoverflow.com/a/14465359
self._windows[:] = []
@@ -199,7 +204,7 @@ def __list_panes(self):
:rtype: list of :class:`Pane`
'''
pformats = ['session_name', 'session_id',
- 'window_index', 'window_id'] + formats.PANE_FORMATS
+ 'window_index', 'window_id', 'window_name'] + formats.PANE_FORMATS
tmux_formats = ['#{%s}\t' % f for f in pformats]
panes = self.tmux(
@@ -219,7 +224,7 @@ def _list_panes(self):
a list of dicts'''
pformats = ['session_name', 'session_id',
- 'window_index', 'window_id'] + formats.PANE_FORMATS
+ 'window_index', 'window_id', 'window_name'] + formats.PANE_FORMATS
panes = self.__list_panes()
@@ -232,6 +237,12 @@ def _list_panes(self):
dict((k, v) for k, v in window.items() if v) for window in panes
]
+ # tmux < 1.8 doesn't have window_id, use window_name
+ for p in panes:
+ if not 'window_id' in p:
+ p['window_id'] = p['window_name']
+
+
if self._panes:
# http://stackoverflow.com/a/14465359
self._panes[:] = []
@@ -489,7 +500,7 @@ def new_session(self,
if proc.stderr:
raise Exception(proc.stderr)
else:
- self.findWhere({
+ return self.findWhere({
'session_name': session_name
})
else:
View
@@ -33,9 +33,9 @@ def __init__(self, server=None, **kwargs):
self.server = server
- if not 'session_id' in kwargs:
- raise ValueError('Session requires a `session_id`')
- self._session_id = kwargs['session_id']
+ # if not 'session_id' in kwargs:
+ # raise ValueError('Session requires a `session_id`')
+ # self._session_id = kwargs['session_id']
if not 'session_name' in kwargs:
raise ValueError('Session requires a `session_name`')
@@ -134,6 +134,10 @@ def new_window(self,
if not attach:
window_args += ('-d',)
+ # compat: -F will not work in less than 1.8
+ # tmux < 1.8. This is added in 1.8.
+ # todo, this needs code to find the newest window created
+
window = self.tmux('new-window', *window_args)
window = window.stdout[0]
@@ -14,13 +14,14 @@
logger = logging.getLogger(__name__)
-#class NewServerTest(unittest.TestCase):
+# class NewServerTest(unittest.TestCase):
class NewServerTest(TmuxTestCase):
def test_hi(self):
self.assertEqual(2, 2)
sessions = t._sessions
+
class ServerTest(TmuxTestCase):
def test_has_session(self):
View
@@ -293,17 +293,32 @@ def split_window(self, attach=True):
*tmux_args
)
+ # tmux < 1.7. This is added in 1.7.
if pane.stderr:
- raise Exception(pane.stderr)
-
- pane = pane.stdout[0]
+ if 'unknown option -- F' in pane.stderr[0]:
+ tmux_args = (
+ '-t%s' % self.panes[0].get('pane_id'),
+ )
+ if not attach:
+ tmux_args += ('-d',)
+ pane = self.tmux(
+ 'split-window',
+ *tmux_args
+ )
+ if pane.stderr:
+ raise Exception(pane.stderr)
+ # todo, this needs code to find the newest pane created
+ else:
+ raise Exception(pane.stderr)
+ else:
+ pane = pane.stdout[0]
- pane = dict(zip(pformats, pane.split('\t')))
+ pane = dict(zip(pformats, pane.split('\t')))
- # clear up empty dict
- pane = dict((k, v) for k, v in pane.items() if v)
+ # clear up empty dict
+ pane = dict((k, v) for k, v in pane.items() if v)
- return Pane(window=self, **pane)
+ return Pane(window=self, **pane)
def attached_pane(self):
'''
@@ -324,7 +339,7 @@ def _list_panes(self):
panes = self.server._update_panes()._panes
panes = [
- p for p in panes if p['session_id'] == self.get('session_id')
+ p for p in panes if p['session_name'] == self.get('session_name')
]
panes = [
p for p in panes if p['window_id'] == self.get('window_id')

0 comments on commit 3bdf75b

Please sign in to comment.