Skip to content

Commit 53e865e

Browse files
committed
fix(tmux_cmd): remove only trailing new lines in stdout
1 parent 83a9f9c commit 53e865e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

libtmux/common.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -270,16 +270,21 @@ def __init__(self, *args: t.Any, **kwargs: t.Any) -> None:
270270

271271
stdout_str = console_to_str(stdout)
272272
stdout_split = stdout_str.split("\n")
273-
stdout_filtered = list(filter(None, stdout_split)) # filter empty values
273+
# remove trailing newlines from stdout
274+
for i in range(len(stdout_split)-1, -1, -1):
275+
if stdout_split[i] == '':
276+
stdout_split.pop(i)
277+
else:
278+
break
274279

275280
stderr_str = console_to_str(stderr)
276281
stderr_split = stderr_str.split("\n")
277282
self.stderr = list(filter(None, stderr_split)) # filter empty values
278283

279-
if "has-session" in cmd and len(self.stderr) and not stdout_filtered:
284+
if "has-session" in cmd and len(self.stderr) and not stdout_split:
280285
self.stdout = [self.stderr[0]]
281286
else:
282-
self.stdout = stdout_filtered
287+
self.stdout = stdout_split
283288

284289
logger.debug("self.stdout for {}: \n{}".format(" ".join(cmd), self.stdout))
285290

0 commit comments

Comments
 (0)