Skip to content

Commit 33ec775

Browse files
committed
tests(WorkspaceBuilder): Basic example
1 parent 5c8b39a commit 33ec775

File tree

1 file changed

+68
-1
lines changed

1 file changed

+68
-1
lines changed

tmuxp/workspacebuilder.py

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,79 @@
2121

2222
class WorkspaceBuilder:
2323

24-
"""
24+
r"""
2525
Load workspace from session :py:obj:`dict`.
2626
2727
Build tmux workspace from a configuration. Creates and names windows, sets
2828
options, splits windows into panes.
2929
30+
Examples
31+
--------
32+
33+
>>> import yaml
34+
35+
>>> session_config = yaml.load('''
36+
... session_name: sampleconfig
37+
... start_directory: '~'
38+
... windows:
39+
... - window_name: editor
40+
... layout: main-vertical
41+
... panes:
42+
... - shell_command:
43+
... - cmd: vim
44+
... - shell_command:
45+
... - cmd: echo "hey"
46+
...
47+
... - window_name: logging
48+
... panes:
49+
... - shell_command:
50+
... - cmd: tail | echo 'hi'
51+
...
52+
... - window_name: test
53+
... panes:
54+
... - shell_command:
55+
... - cmd: htop
56+
... ''', Loader=yaml.Loader)
57+
58+
>>> builder = WorkspaceBuilder(sconf=session_config, server=server)
59+
60+
61+
***New session:**
62+
63+
>>> builder.build()
64+
65+
>>> new_session = builder.session
66+
67+
>>> new_session.name == 'sampleconfig'
68+
True
69+
70+
>>> len(new_session._windows)
71+
3
72+
73+
>>> sorted([window.name for window in new_session.windows])
74+
['editor', 'logging', 'test']
75+
76+
**Existing session**
77+
78+
>>> session.name == 'sampleconfig'
79+
False
80+
81+
>>> len(session._windows)
82+
1
83+
84+
>>> builder.build(session=session)
85+
86+
_Caveat:_ Preserves old session name:
87+
88+
>>> session.name == 'sampleconfig'
89+
False
90+
91+
>>> len(session._windows)
92+
3
93+
94+
>>> sorted([window.name for window in session.windows])
95+
['editor', 'logging', 'test']
96+
3097
The normal phase of loading is:
3198
3299
1. :term:`kaptan` imports json/yaml/ini. ``.get()`` returns python

0 commit comments

Comments
 (0)