Skip to content

Commit a2fcf04

Browse files
committed
fix(cli): preserve interactive prompts in passthrough runtime
2 parents ce50c5e + e477b20 commit a2fcf04

2 files changed

Lines changed: 64 additions & 6 deletions

File tree

src/commands/RunCommand.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ namespace
577577

578578
if (testExit == 130)
579579
{
580-
hint("Stopped (SIGINT).");
580+
hint("ℹ Program interrupted by user (SIGINT).");
581581
return 0;
582582
}
583583

@@ -608,7 +608,7 @@ namespace
608608

609609
if (testExit == 130)
610610
{
611-
hint("Stopped (SIGINT).");
611+
hint("ℹ Program interrupted by user (SIGINT).");
612612
return 0;
613613
}
614614

@@ -665,7 +665,7 @@ namespace
665665

666666
if (runExit == 130)
667667
{
668-
hint("Stopped (SIGINT).");
668+
hint("ℹ Program interrupted by user (SIGINT).");
669669
return 0;
670670
}
671671

@@ -696,7 +696,7 @@ namespace
696696

697697
if (runExit == 130)
698698
{
699-
hint("Stopped (SIGINT).");
699+
hint("ℹ Program interrupted by user (SIGINT).");
700700
return 0;
701701
}
702702

@@ -860,7 +860,7 @@ namespace
860860
const int buildExit = normalize_exit_code(buildCode);
861861
if (buildExit == 130)
862862
{
863-
hint("Stopped (SIGINT).");
863+
hint("ℹ Program interrupted by user (SIGINT).");
864864
return 0;
865865
}
866866

@@ -902,7 +902,7 @@ namespace
902902

903903
if (buildExit == 130)
904904
{
905-
hint("Stopped (SIGINT).");
905+
hint("ℹ Program interrupted by user (SIGINT).");
906906
return 0;
907907
}
908908

src/commands/run/RunProcess.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,37 @@ namespace vix::commands::RunCommand::detail
592592
}
593593
};
594594

595+
std::string rtrim_copy(std::string s)
596+
{
597+
while (!s.empty() &&
598+
(s.back() == ' ' || s.back() == '\t' ||
599+
s.back() == '\n' || s.back() == '\r'))
600+
{
601+
s.pop_back();
602+
}
603+
return s;
604+
}
605+
606+
bool looks_like_prompt_fragment(const std::string &chunk)
607+
{
608+
if (chunk.empty())
609+
return false;
610+
611+
if (chunk.find('\n') != std::string::npos ||
612+
chunk.find('\r') != std::string::npos)
613+
{
614+
return false;
615+
}
616+
617+
const std::string trimmed = rtrim_copy(chunk);
618+
619+
return trimmed == ">" ||
620+
trimmed == "$" ||
621+
trimmed == "#" ||
622+
trimmed == ">>>" ||
623+
trimmed == "...";
624+
}
625+
595626
struct CMakeNoiseFilter
596627
{
597628
std::string carry;
@@ -763,6 +794,13 @@ namespace vix::commands::RunCommand::detail
763794
if (nl == std::string::npos)
764795
{
765796
carry = data.substr(start);
797+
798+
if (!inReport && looks_like_prompt_fragment(carry))
799+
{
800+
out += carry;
801+
carry.clear();
802+
}
803+
766804
break;
767805
}
768806

@@ -854,6 +892,13 @@ namespace vix::commands::RunCommand::detail
854892
if (nl == std::string::npos)
855893
{
856894
carry = data.substr(start);
895+
896+
if (looks_like_prompt_fragment(carry))
897+
{
898+
out += carry;
899+
carry.clear();
900+
}
901+
857902
break;
858903
}
859904

@@ -1054,6 +1099,19 @@ namespace vix::commands::RunCommand::detail
10541099
if (useSan)
10551100
return;
10561101

1102+
if (passthroughRuntime && looks_like_prompt_fragment(printable))
1103+
{
1104+
if (!captureOnly)
1105+
{
1106+
write_all(STDOUT_FILENO, printable.data(), printable.size());
1107+
printedSomething = true;
1108+
printedRealOutput = true;
1109+
result.printed_live = true;
1110+
lastPrintedChar = printable.back();
1111+
}
1112+
return;
1113+
}
1114+
10571115
std::string filtered;
10581116

10591117
printable = sanitizer.filter_for_print(printable);

0 commit comments

Comments
 (0)