Skip to content

Commit 843a19e

Browse files
committed
New tests and examples for blank panes
1 parent e55bd99 commit 843a19e

File tree

7 files changed

+299
-42
lines changed

7 files changed

+299
-42
lines changed

doc/examples.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,26 @@ JSON
3535
.. literalinclude:: ../examples/shorthands.json
3636
:language: json
3737

38+
Blank panes
39+
-----------
40+
41+
.. important::
42+
43+
In Development Version, see :ref:`Developing`. This will be released
44+
soon.
45+
46+
YAML
47+
""""
48+
49+
.. literalinclude:: ../examples/blank-panes.yaml
50+
:language: yaml
51+
52+
JSON
53+
""""
54+
55+
.. literalinclude:: ../examples/blank-panes.json
56+
:language: json
57+
3858
2 split panes
3959
-------------
4060

examples/blank-panes.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"windows": [
3+
{
4+
"panes": [
5+
null,
6+
"pane",
7+
"blank",
8+
null,
9+
{
10+
"shell_command": null
11+
},
12+
{
13+
"shell_command": [
14+
null
15+
]
16+
}
17+
],
18+
"window_name": "Blank pane test"
19+
},
20+
{
21+
"panes": [
22+
"",
23+
{
24+
"shell_command": ""
25+
},
26+
{
27+
"shell_command": [
28+
""
29+
]
30+
}
31+
],
32+
"window_name": "Empty string (return)"
33+
}
34+
],
35+
"session_name": "Blank pane test"
36+
}

examples/blank-panes.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
session_name: Blank pane test
2+
windows:
3+
# Emptiness will simply open a blank pane, if no shell_command_before.
4+
# All these are equivalent
5+
- window_name: Blank pane test
6+
panes:
7+
-
8+
- pane
9+
- blank
10+
- null
11+
- shell_command:
12+
- shell_command:
13+
-
14+
# an empty string will be treated as a carriage return
15+
- window_name: Empty string (return)
16+
panes:
17+
- ''
18+
- shell_command: ''
19+
- shell_command:
20+
- ''

tmuxp/config.py

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def expand(sconf, cwd=None):
151151
if not cwd:
152152
cwd = os.getcwd()
153153

154+
154155
# Any config section, session, window, pane that can contain the
155156
# 'shell_command' value
156157
if 'start_directory' in sconf:
@@ -161,8 +162,9 @@ def expand(sconf, cwd=None):
161162

162163
if ('shell_command' in sconf and isinstance(sconf['shell_command'], basestring)):
163164
sconf['shell_command'] = [sconf['shell_command']]
164-
elif not 'windows' in sconf and not 'panes' in sconf and isinstance(sconf, basestring):
165-
sconf = {'shell_command': [sconf]}
165+
# elif not 'windows' in sconf and not 'panes' in sconf and isinstance(sconf, basestring): # probable pane
166+
# logger.error(sconf)
167+
# sconf = {'shell_command': [sconf]}
166168

167169
if ('shell_command_before' in sconf and isinstance(sconf['shell_command_before'], basestring)):
168170
sconf['shell_command_before'] = [sconf['shell_command_before']]
@@ -173,12 +175,56 @@ def expand(sconf, cwd=None):
173175
expand(window) for window in sconf['windows']
174176
]
175177
elif 'panes' in sconf:
178+
176179
for p in sconf['panes']:
180+
p_index = sconf['panes'].index(p)
181+
182+
if not isinstance(p, dict) and not isinstance(p, list): # probable pane
183+
p = sconf['panes'][p_index] = {
184+
'shell_command': [p]
185+
}
186+
187+
if isinstance (p, dict) and not len(p):
188+
p = sconf['panes'][p_index] = {
189+
'shell_command': []
190+
}
191+
192+
193+
# if not p:
194+
# p = sconf['panes'][p_index] = {
195+
# 'shell_command': []
196+
# }
197+
177198
if isinstance(p, basestring):
178-
p_index = sconf['panes'].index(p)
179-
sconf['panes'][p_index] = {
199+
200+
p = sconf['panes'][p_index] = {
180201
'shell_command': [p]
181202
}
203+
204+
if 'shell_command' in p:
205+
206+
if isinstance(p['shell_command'], basestring):
207+
p = sconf['panes'][p_index] = {
208+
'shell_command': [p['shell_command']]
209+
}
210+
211+
if p['shell_command'] is None:
212+
p = sconf['panes'][p_index] = {
213+
'shell_command': []
214+
}
215+
elif isinstance(p['shell_command'], list) and \
216+
len(p['shell_command']) == int(1) and (
217+
any(a in p['shell_command'] for a in [None, 'blank', 'pane']) or \
218+
p['shell_command'][0] is None
219+
):
220+
p = sconf['panes'][p_index] = {
221+
'shell_command': []
222+
}
223+
224+
#elif any(a in p['shell_command'] for a in ['blank', 'pane']):
225+
226+
227+
182228
sconf['panes'] = [expand(pane) for pane in sconf['panes']]
183229

184230
return sconf

0 commit comments

Comments
 (0)