Skip to content

Commit 1d61c09

Browse files
committed
Merge pull request #6 from tony/docs-powerup
Refactor handbook
2 parents 15cf306 + 8a27812 commit 1d61c09

File tree

18 files changed

+428
-43
lines changed

18 files changed

+428
-43
lines changed

Makefile

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1+
WATCH_FILES= find . -type f -not -path '*/\.*' | grep -i '.*[.]py$$' 2> /dev/null
2+
3+
14
test:
2-
py.test
5+
py.test $(test)
6+
7+
entr_warn:
8+
@echo "----------------------------------------------------------"
9+
@echo " ! File watching functionality non-operational ! "
10+
@echo ""
11+
@echo "Install entr(1) to automatically run tasks on file change."
12+
@echo "See http://entrproject.org/"
13+
@echo "----------------------------------------------------------"
14+
315

416
watch_test:
5-
if command -v entr > /dev/null; then find . -type f -not -path '*/\.*' | grep -i '.*[.]py' | entr -c make test; else make test; echo "\nInstall entr(1) to automatically run tests on file change.\n See http://entrproject.org/"; fi
17+
if command -v entr > /dev/null; then ${WATCH_FILES} | entr -c $(MAKE) test; else $(MAKE) test entr_warn; fi
618

719
build_docs:
820
cd doc && $(MAKE) html
@@ -14,6 +26,4 @@ flake8:
1426
flake8 libtmux tests
1527

1628
watch_flake8:
17-
if command -v entr > /dev/null; then find . -type f -not -path '*/\.*' | grep -i '.*[.][py]' | entr -c make flake8; else make flake8; echo "\nInstall entr(1) to automatically run tests on file change.\n See http://entrproject.org/"; fi
18-
19-
.PHONY: flake8
29+
if command -v entr > /dev/null; then ${WATCH_FILES} | entr -c $(MAKE) flake8; else $(MAKE) flake8 entr_warn; fi

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pilot your tmux session via python
3737
$ pip install ptpython
3838
$ ptpython
3939
40+
connect to a live tmux session:
41+
4042
.. code-block:: python
4143
4244
>>> import libtmux

TODO

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22
TODO
33
====
44

5+
- Remove duplicate between ``_list_panes``, ``_panes``, etc.
6+
- Retrieve active windows and window count from formatter command
7+
- tmux PR to get count of sessions in a server
8+
59
.. # vim: set filetype=rst:

doc/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,10 @@ checkbuild:
156156
rm -rf $(BUILDDIR)
157157
$(SPHINXBUILD) -n -q ./ $(BUILDDIR)
158158

159+
WATCH_FILES= find .. -type f -not -path '*/\.*' | grep -i '.*[.]rst\|CHANGES\|TODO\|.*conf\.py' 2> /dev/null
160+
159161
watch:
160-
if command -v entr > /dev/null; then find .. -type f -not -path '*/\.*' | grep -i '.*[.]rst\|CHANGES\|TODO\|conf.py' | entr -c make html; else make html; echo "\nInstall entr(1) to automatically run tests on file change.\n See http://entrproject.org/"; fi
162+
if command -v entr > /dev/null; then ${WATCH_FILES} | entr -c $(MAKE) html; else $(MAKE) html; fi
161163

162164
serve:
163165
echo 'docs built to <http://0.0.0.0:8023/_build/html>'; python -m SimpleHTTPServer 8023

doc/about.rst

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ About
99

1010
.. module:: libtmux
1111

12-
libtmux is an *abstraction layer* against tmux' command line arguments.
12+
libtmux is an `abstraction layer`_ for tmux.
13+
14+
It builds upon the concept of targets ``-t``, to direct commands against
15+
individual session, windows and panes and ``FORMATS``, template variables
16+
exposed by tmux to describe their properties.
1317

1418
:class:`common.TmuxRelationalObject` acts as a container to connect the
1519
relations of :class:`Server`, :class:`Session`, :class:`Window` and
@@ -25,8 +29,10 @@ Object Child Parent
2529
======================== ======================= =========================
2630

2731
Internally, tmux allows multiple servers to be ran on a system. Each one
28-
uses a socket. Most users worry since tmux will communicate to a default
29-
server automatically. If one doesn't exist, tmux does it for you.
32+
uses a socket. The server-client architecture is executed so cleanly,
33+
many users don't think about it. tmux automatically connects to a default
34+
socket name and location for you if none (``-L``, ``-S``) is specified.
35+
A server will be created automatically upon starting if none exists.
3036

3137
A server can have multiple sessions. ``Ctrl-a s`` can be used to switch
3238
between sessions running on the server.
@@ -49,7 +55,7 @@ Object Prefix Example
4955
Similarities to Tmux and Pythonics
5056
----------------------------------
5157

52-
libtmux is was built in the spirit of understanding how tmux operates
58+
libtmux was built in the spirit of understanding how tmux operates
5359
and how python objects and tools can abstract the API's in a pleasant way.
5460

5561
libtmux uses ``FORMATTERS`` in tmux to give identity attributes to
@@ -82,8 +88,8 @@ To assert pane, window and session data, libtmux will use
8288
:meth:`Server.list_sessions()`, :meth:`Session.list_windows()`,
8389
:meth:`Window.list_panes()` to update objects.
8490

85-
Idiosyncrasies
86-
--------------
91+
Naming conventions
92+
------------------
8793

8894
Because this is a python abstraction and commands like ``new-window``
8995
have dashes (-) replaced with underscores (_).
@@ -95,4 +101,3 @@ Reference
95101
- tmux source code http://sourceforge.net/p/tmux/tmux-code/ci/master/tree/
96102

97103
.. _abstraction layer: http://en.wikipedia.org/wiki/Abstraction_layer
98-
.. _ORM: http://en.wikipedia.org/wiki/Object-relational_mapping

doc/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ Explore:
1515

1616
quickstart
1717
about
18+
properties
19+
traversing
20+
servers
21+
sessions
22+
windows
23+
panes
1824
api
1925
glossary
2026
developing

doc/panes.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.. _Panes:
2+
3+
=====
4+
Panes
5+
=====
6+
7+
- hold `pseudoterminal`_'s (`pty(4)`_)
8+
- exist inside :ref:`Windows`
9+
- identified by ``%``, e.g. ``%313``
10+
11+
.. _pseudoterminal: https://en.wikipedia.org/wiki/Pseudoterminal
12+
.. _pty(4): https://www.freebsd.org/cgi/man.cgi?query=pty&sektion=4
13+
14+
.. autoclass:: libtmux.Pane
15+
:noindex:
16+
:members:
17+
:inherited-members:
18+
:private-members:
19+
:show-inheritance:
20+
:member-order: bysource

doc/properties.rst

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
.. _Properties:
2+
3+
==========
4+
Properties
5+
==========
6+
7+
Get access to the data attributions behind tmux sessions, windows and panes.
8+
9+
This is done through accessing the `formats`_ available in ``list-sessions``,
10+
``list-windows`` and ``list-panes``.
11+
12+
open two terminals:
13+
14+
terminal one: start tmux in a seperate terminal::
15+
16+
$ tmux
17+
18+
.. NOTE::
19+
20+
Make sure you have :ref:`libtmux installed <installation>`::
21+
22+
pip install libtmux
23+
24+
To upgrade:
25+
26+
pip install -U libtmux
27+
28+
terminal two, ``python`` or ``ptpython`` if you have it::
29+
30+
$ python
31+
32+
import tmux::
33+
34+
import tmux
35+
36+
attach default tmux :class:`libtmux.Server` to ``t``::
37+
38+
>>> t = libtmux.Server();
39+
>>> t
40+
<libtmux.server.Server object at 0x10edd31d0>
41+
42+
Session
43+
-------
44+
45+
get our ``session`` object::
46+
47+
>>> session = t.sessions[0]
48+
49+
>>> session
50+
Session($0 libtmux)
51+
52+
quick access to basic attributes::
53+
54+
>>> session.name
55+
u'libtmux'
56+
57+
>>> session.id
58+
u'$0'
59+
60+
>>> session.width
61+
u'213'
62+
63+
>>> session.height
64+
u'114'
65+
66+
to see all attributes for a session::
67+
68+
>>> session._info.keys()
69+
[u'session_height', u'session_windows', u'session_width', u'session_id', u'session_created', u'session_attached', u'session_grouped', u'session_name']
70+
71+
>>> session._info
72+
{u'session_height': u'114', u'session_windows': u'3', u'session_width': u'213', u'session_id': u'$0', u'session_created': u'1464905357', u'session_attached': u'1', u'session_grouped': u'0', u'session_name': u'libtmux'}
73+
74+
75+
some may conflict with python API, to access them, you can use ``.get()``, to get the count
76+
of sessions in a window::
77+
78+
>>> session.get('session_windows')
79+
u'3'
80+
81+
Windows
82+
-------
83+
84+
The same concepts apply for window::
85+
86+
>>> window = session.attached_window
87+
88+
>>> window
89+
Window(@2 2:docs, Session($0 libtmux))
90+
91+
basics::
92+
93+
>>> window.name
94+
u'docs'
95+
96+
>>> window.id
97+
u'@2'
98+
99+
>>> window.height
100+
u'114'
101+
102+
>>> window.width
103+
u'213'
104+
105+
everything available::
106+
107+
>>> window._info
108+
{u'window_panes': u'4', u'window_active': u'1', u'window_height': u'114', u'window_activity_flag': u'0', u'window_width': u'213', u'session_id': u'$0', u'window_id': u'@2', u'window_layout': u'dad5,213x114,0,0[213x60,0,0,4,213x53,0,61{70x53,0,61,5,70x53,71,61,6,71x53,142,61,7}]', u'window_silence_flag': u'0', u'window_index': u'2', u'window_bell_flag': u'0', u'session_name': u'libtmux', u'window_flags': u'*', u'window_name': u'docs'}
109+
110+
>>> window.keys()
111+
[u'window_panes', u'window_active', u'window_height', u'window_activity_flag', u'window_width', u'session_id', u'window_id', u'window_layout', u'window_silence_flag', u'window_index', u'window_bell_flag', u'session_name', u'window_flags', u'window_name']
112+
113+
use ``get()`` for details not accessible via properties::
114+
115+
>>> pane.get('window_panes')
116+
u'4'
117+
118+
Panes
119+
-----
120+
121+
get our pane::
122+
123+
>>> pane = window.attached_pane
124+
125+
>>> pane
126+
Pane(%5 Window(@2 2:docs, Session($0 libtmux)))
127+
128+
basics::
129+
130+
>>> pane.current_command
131+
u'python'
132+
133+
>>> pane.height
134+
u'53'
135+
136+
>>> pane.width
137+
u'70'
138+
139+
>>> pane.index
140+
u'1'
141+
142+
everything::
143+
144+
>>> pane._info
145+
{u'alternate_saved_x': u'0', u'alternate_saved_y': u'0', u'cursor_y': u'47', u'cursor_x': u'0', u'pane_in_mode': u'0', u'insert_flag': u'0', u'keypad_flag': u'0', u'cursor_flag': u'1', u'pane_current_command': u'python', u'window_index': u'2', u'history_size': u'216', u'scroll_region_lower': u'52', u'keypad_cursor_flag': u'0', u'history_bytes': u'38778', u'pane_active': u'1', u'pane_dead': u'0', u'pane_synchronized': u'0', u'window_id': u'@2', u'pane_index': u'1', u'pane_width': u'70', u'mouse_any_flag': u'0', u'mouse_button_flag': u'0', u'window_name': u'docs', u'pane_current_path': u'/Users/me/work/python/libtmux/doc', u'pane_tty': u'/dev/ttys007', u'pane_title': u'Python REPL (ptpython)', u'session_id': u'$0', u'alternate_on': u'0', u'mouse_standard_flag': u'0', u'wrap_flag': u'1', u'history_limit': u'2000', u'pane_pid': u'37172', u'pane_height': u'53', u'session_name': u'libtmux', u'scroll_region_upper': u'0', u'pane_id': u'%5'}
146+
147+
>>> pane._info.keys()
148+
[u'alternate_saved_x', u'alternate_saved_y', u'cursor_y', u'cursor_x', u'pane_in_mode', u'insert_flag', u'keypad_flag', u'cursor_flag', u'pane_current_command', u'window_index', u'history_size', u'scroll_region_lower', u'keypad_cursor_flag', u'history_bytes', u'pane_active', u'pane_dead', u'pane_synchronized', u'window_id', u'pane_index', u'pane_width', u'mouse_any_flag', u'mouse_button_flag', u'window_name', u'pane_current_path', u'pane_tty', u'pane_title', u'session_id', u'alternate_on', u'mouse_standard_flag', u'wrap_flag', u'history_limit', u'pane_pid', u'pane_height', u'session_name', u'scroll_region_upper', u'pane_id']
149+
150+
use ``get()`` for details keys::
151+
152+
>>> pane.get('pane_width')
153+
u'70'
154+
155+
.. _formats: http://man.openbsd.org/OpenBSD-5.9/man1/tmux.1#FORMAT

doc/quickstart.rst

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,49 @@ sessions using python code.
1010
In this example, we will launch a tmux session and control the windows
1111
from inside a live tmux session.
1212

13-
Control tmux via python
14-
-----------------------
13+
.. _requirements:
1514

16-
.. seealso:: :ref:`api`
15+
Requirements
16+
------------
1717

18-
.. todo:: Do a version of this with `sliderepl`_
18+
- `tmux`_
19+
- `pip`_ - for this handbook's examples
1920

20-
To begin, ensure the ``tmux`` program is installed.
21+
.. _pip: https://pip.pypa.io/en/stable/installing/
22+
.. _tmux: https://tmux.github.io/
2123

22-
Next, ensure ``libtmux`` (note the p!) is installed:
24+
.. _installation:
25+
26+
Installation
27+
------------
28+
29+
Next, ensure ``libtmux`` is installed:
2330

2431
.. code-block:: bash
2532
2633
$ [sudo] pip install libtmux
2734
35+
Start a tmux session
36+
--------------------
37+
2838
Now, let's open a tmux session.
2939

3040
.. code-block:: bash
3141
3242
$ tmux new-session -n bar -s foo
3343
34-
Why not just ``$ tmux``? We will assume you want to see the tmux changes
35-
in the current tmux session. So we will use:
44+
This tutorial will be using the session and window name in the example.
45+
46+
Window name ``-n``: ``bar``
47+
Session name ``-s``: ``foo``
48+
49+
Control tmux via python
50+
-----------------------
51+
52+
.. seealso:: :ref:`api`
53+
54+
.. todo:: Do a version of this with `sliderepl`_
3655

37-
Window name: ``bar``
38-
Session name: ``foo``
3956

4057
.. code-block:: bash
4158

doc/servers.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.. _Servers:
2+
3+
=======
4+
Servers
5+
=======
6+
7+
- identified by *socket path* and *socket name*
8+
- may have >1 servers running of tmux at the same time.
9+
- hold :ref:`Sessions` (which hold :ref:`Windows`, which hold
10+
:ref:`Panes`)
11+
12+
In tmux, a server is automatically started on your behalf
13+
when you first run tmux.
14+
15+
.. autoclass:: libtmux.Server
16+
:noindex:
17+
:members:
18+
:inherited-members:
19+
:private-members:
20+
:show-inheritance:
21+
:member-order: bysource

0 commit comments

Comments
 (0)