|
21 | 21 |
|
22 | 22 | class WorkspaceBuilder: |
23 | 23 |
|
24 | | - """ |
| 24 | + r""" |
25 | 25 | Load workspace from session :py:obj:`dict`. |
26 | 26 |
|
27 | 27 | Build tmux workspace from a configuration. Creates and names windows, sets |
28 | 28 | options, splits windows into panes. |
29 | 29 |
|
| 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 | +
|
30 | 97 | The normal phase of loading is: |
31 | 98 |
|
32 | 99 | 1. :term:`kaptan` imports json/yaml/ini. ``.get()`` returns python |
|
0 commit comments