Skip to content

Commit b3214ee

Browse files
committed
Refactor _info, change behavior of mapping
What used to be _TMUX (_attr in an earlier commit) now has raw information from tmux's FORMATS (see the official tmux(1) manual for more details). Instead of using the tmux object as a dictionary, the object will set attributes for formats w/o the namespace. So what used to be ``s.get('session_name')`` can now be retrieved as ``s.name``. Window and pane still have to be switched.
1 parent 9a1686e commit b3214ee

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

libtmux/common.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,31 +198,37 @@ class TmuxMappingObject(collections.MutableMapping):
198198
:class:`Session` and :class:`Server`.
199199
200200
Instance attributes for useful information :term:`tmux(1)` uses for
201-
Session, Window, Pane, stored :attr:`self._attr`. For example, a
201+
Session, Window, Pane, stored :attr:`self._info`. For example, a
202202
:class:`Window` will have a ``window_id`` and ``window_name``.
203203
204204
"""
205205

206206
def __getitem__(self, key):
207-
return self._attr[key]
207+
return self._info[key]
208208

209209
def __setitem__(self, key, value):
210-
self._attr[key] = value
210+
self._info[key] = value
211211
self.dirty = True
212212

213213
def __delitem__(self, key):
214-
del self._attr[key]
214+
del self._info[key]
215215
self.dirty = True
216216

217217
def keys(self):
218218
"""Return list of keys."""
219-
return self._attr.keys()
219+
return self._info.keys()
220220

221221
def __iter__(self):
222-
return self._attr.__iter__()
222+
return self._info.__iter__()
223223

224224
def __len__(self):
225-
return len(self._attr.keys())
225+
return len(self._info.keys())
226+
227+
# def __getattr__(self, key):
228+
# try:
229+
# return self[key]
230+
# except KeyError:
231+
# return super(self, TmuxMappingObject).__getattr__(key)
226232

227233

228234
class TmuxRelationalObject(object):

libtmux/pane.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self, window=None, **kwargs):
4141
self.server._update_panes()
4242

4343
@property
44-
def _attr(self, *args):
44+
def _info(self, *args):
4545

4646
attrs = {
4747
'pane_id': self._pane_id

libtmux/session.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,14 @@ def __init__(self, server=None, **kwargs):
4040
self._session_id = kwargs['session_id']
4141
self.server._update_windows()
4242

43+
for f in formats.SESSION_FORMATS:
44+
try:
45+
setattr(self, f.replace('session_', ''), self.get(f, None))
46+
except:
47+
pass
48+
4349
@property
44-
def _attr(self, *args):
50+
def _info(self, *args):
4551

4652
attrs = {
4753
'session_id': str(self._session_id)

libtmux/window.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __repr__(self):
4646
)
4747

4848
@property
49-
def _attr(self, *args):
49+
def _info(self, *args):
5050

5151
attrs = {
5252
'window_id': self._window_id
@@ -403,7 +403,7 @@ def split_window(
403403
if 'pane too small' in pane.stderr:
404404
pass
405405

406-
raise exc.LibTmuxException(pane.stderr, self._attr, self.panes)
406+
raise exc.LibTmuxException(pane.stderr, self._info, self.panes)
407407
else:
408408
pane = pane.stdout[0]
409409

tests/test_tmuxobject.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_find_where_None(server, session):
5858
}) is None
5959

6060

61-
def test_find_where_multiple_attrs(server, session):
61+
def test_find_where_multiple_infos(server, session):
6262
""".find_where returns objects with multiple attributes."""
6363

6464
for session in server.sessions:

0 commit comments

Comments
 (0)