Skip to content

Commit 6b4e8ca

Browse files
committed
fix(run): preserve interactive prompt output in passthrough mode
2 parents bd03e0f + 60644e2 commit 6b4e8ca

1 file changed

Lines changed: 36 additions & 10 deletions

File tree

src/commands/run/RunProcess.cpp

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,20 +1033,26 @@ namespace vix::commands::RunCommand::detail
10331033
return;
10341034

10351035
if (useSan)
1036-
{
10371036
return;
1038-
}
10391037

1040-
printable = sanitizer.filter_for_print(printable);
1038+
std::string filtered;
10411039

1042-
if (!printable.empty())
1043-
printable = uncaught.filter_for_print(printable);
1040+
if (passthroughRuntime)
1041+
{
1042+
filtered = printable;
1043+
}
1044+
else
1045+
{
1046+
printable = sanitizer.filter_for_print(printable);
10441047

1045-
if (printable.empty())
1046-
return;
1048+
if (!printable.empty())
1049+
printable = uncaught.filter_for_print(printable);
10471050

1048-
std::string filtered =
1049-
passthroughRuntime ? printable : runtimeFilter.process(printable);
1051+
if (printable.empty())
1052+
return;
1053+
1054+
filtered = runtimeFilter.process(printable);
1055+
}
10501056

10511057
if (filtered.empty())
10521058
return;
@@ -1102,6 +1108,9 @@ namespace vix::commands::RunCommand::detail
11021108
::setpgid(pid, pid);
11031109

11041110
const bool captureOnly = false;
1111+
const bool forwardStdin =
1112+
passthroughRuntime && (::isatty(STDIN_FILENO) != 0);
1113+
11051114
bool spinnerActive = false;
11061115
std::size_t frameIndex = 0;
11071116

@@ -1192,12 +1201,20 @@ namespace vix::commands::RunCommand::detail
11921201
FD_ZERO(&fds);
11931202

11941203
int maxfd = -1;
1204+
11951205
if (pty.masterFd >= 0)
11961206
{
11971207
FD_SET(pty.masterFd, &fds);
11981208
maxfd = pty.masterFd;
11991209
}
12001210

1211+
if (forwardStdin)
1212+
{
1213+
FD_SET(STDIN_FILENO, &fds);
1214+
if (STDIN_FILENO > maxfd)
1215+
maxfd = STDIN_FILENO;
1216+
}
1217+
12011218
if (maxfd < 0)
12021219
{
12031220
int status = 0;
@@ -1243,6 +1260,16 @@ namespace vix::commands::RunCommand::detail
12431260
spinnerActive = false;
12441261
}
12451262

1263+
if (forwardStdin && FD_ISSET(STDIN_FILENO, &fds) && pty.masterFd >= 0)
1264+
{
1265+
char inbuf[4096];
1266+
const ssize_t n = ::read(STDIN_FILENO, inbuf, sizeof(inbuf));
1267+
if (n > 0)
1268+
{
1269+
write_all(pty.masterFd, inbuf, static_cast<std::size_t>(n));
1270+
}
1271+
}
1272+
12461273
if (pty.masterFd >= 0 && FD_ISSET(pty.masterFd, &fds))
12471274
{
12481275
std::string chunk;
@@ -1340,7 +1367,6 @@ namespace vix::commands::RunCommand::detail
13401367

13411368
return result;
13421369
}
1343-
13441370
#endif
13451371

13461372
int run_cmd_live_filtered(

0 commit comments

Comments
 (0)