Skip to content

Commit 3c4443b

Browse files
committed
AsyncTmuxCmd: Updates for TmuxCmd
1 parent 8399016 commit 3c4443b

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

Diff for: src/libtmux/common.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -361,16 +361,17 @@ async def run(cls, *args: t.Any) -> AsyncTmuxCmd:
361361
msg,
362362
)
363363

364-
# Convert all arguments to strings, accounting for Python 3.7+ strings
365-
cmd: list[str] = [tmux_bin] + [str_from_console(a) for a in args]
364+
cmd: list[str] = [tmux_bin] + [str(c) for c in args]
366365

367366
try:
368367
process: asyncio.subprocess.Process = await asyncio.create_subprocess_exec(
369368
*cmd,
370369
stdout=asyncio.subprocess.PIPE,
371370
stderr=asyncio.subprocess.PIPE,
371+
text=True,
372+
errors="backslashreplace",
372373
)
373-
raw_stdout, raw_stderr = await process.communicate()
374+
stdout, stderr = await process.communicate()
374375
returncode: int = (
375376
process.returncode if process.returncode is not None else -1
376377
)
@@ -382,12 +383,14 @@ async def run(cls, *args: t.Any) -> AsyncTmuxCmd:
382383
msg,
383384
) from e
384385

385-
stdout_str: str = console_to_str(raw_stdout)
386-
stderr_str: str = console_to_str(raw_stderr)
386+
# Split on newlines and filter empty lines
387+
stdout_split: list[str] = stdout.split("\n")
388+
# remove trailing newlines from stdout
389+
while stdout_split and stdout_split[-1] == "":
390+
stdout_split.pop()
387391

388-
# Split on newlines, filtering out any trailing empty lines
389-
stdout_split: list[str] = [line for line in stdout_str.split("\n") if line]
390-
stderr_split: list[str] = [line for line in stderr_str.split("\n") if line]
392+
stderr_split = stderr.split("\n")
393+
stderr_split = list(filter(None, stderr_split)) # filter empty values
391394

392395
# Workaround for tmux "has-session" command behavior
393396
if "has-session" in cmd and stderr_split and not stdout_split:

0 commit comments

Comments
 (0)