Skip to content

Commit 8124d94

Browse files
committed
tests(doctest): Basic Workspace example
1 parent 5c8b39a commit 8124d94

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

tmuxp/workspacebuilder.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,69 @@ class WorkspaceBuilder:
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+
***New session:**
61+
62+
>>> builder.build()
63+
64+
>>> new_session = builder.session
65+
66+
>>> new_session.name == 'sampleconfig'
67+
True
68+
69+
>>> len(new_session._windows)
70+
3
71+
72+
>>> sorted([window.name for window in new_session.windows])
73+
['editor', 'logging', 'test']
74+
75+
**Existing session**
76+
77+
>>> len(session._windows)
78+
1
79+
80+
>>> builder.build(session=session)
81+
82+
_Caveat:_ Preserves old session name:
83+
84+
>>> session.name == 'sampleconfig'
85+
False
86+
87+
>>> len(session._windows)
88+
3
89+
90+
>>> sorted([window.name for window in session.windows])
91+
['editor', 'logging', 'test']
92+
3093
The normal phase of loading is:
3194
3295
1. :term:`kaptan` imports json/yaml/ini. ``.get()`` returns python

0 commit comments

Comments
 (0)