From 03350ca3a5854b7d0b1e646d0174b8ab19e76b89 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Fri, 11 Jul 2025 11:24:23 +0000 Subject: [PATCH] Add CTRL-C guidance message to aspire run command output (#10203) * Initial plan * Add CTRL-C guidance message to aspire run command output Co-authored-by: mitchdenny <513398+mitchdenny@users.noreply.github.com> * Update CTRL-C message * Fix CTRL-C message formatting and change "app host" to "apphost" Co-authored-by: maddymontaquila <12660687+maddymontaquila@users.noreply.github.com> * Move CTRL+C message to appear after endpoints in codespaces Co-authored-by: maddymontaquila <12660687+maddymontaquila@users.noreply.github.com> * Fix CTRL+C message positioning in codespaces by improving environment detection Co-authored-by: mitchdenny <513398+mitchdenny@users.noreply.github.com> * Fixes to implementation. * Fix formatting (bye bye pink) --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: mitchdenny <513398+mitchdenny@users.noreply.github.com> Co-authored-by: Mitch Denny Co-authored-by: maddymontaquila <12660687+maddymontaquila@users.noreply.github.com> --- src/Aspire.Cli/Commands/RunCommand.cs | 43 ++++++++++++++++++- .../Resources/RunCommandStrings.resx | 2 +- .../Resources/xlf/RunCommandStrings.cs.xlf | 4 +- .../Resources/xlf/RunCommandStrings.de.xlf | 4 +- .../Resources/xlf/RunCommandStrings.es.xlf | 4 +- .../Resources/xlf/RunCommandStrings.fr.xlf | 4 +- .../Resources/xlf/RunCommandStrings.it.xlf | 4 +- .../Resources/xlf/RunCommandStrings.ja.xlf | 4 +- .../Resources/xlf/RunCommandStrings.ko.xlf | 4 +- .../Resources/xlf/RunCommandStrings.pl.xlf | 4 +- .../Resources/xlf/RunCommandStrings.pt-BR.xlf | 4 +- .../Resources/xlf/RunCommandStrings.ru.xlf | 4 +- .../Resources/xlf/RunCommandStrings.tr.xlf | 4 +- .../xlf/RunCommandStrings.zh-Hans.xlf | 4 +- .../xlf/RunCommandStrings.zh-Hant.xlf | 4 +- 15 files changed, 69 insertions(+), 28 deletions(-) diff --git a/src/Aspire.Cli/Commands/RunCommand.cs b/src/Aspire.Cli/Commands/RunCommand.cs index 01579c72c16..8c542a782fc 100644 --- a/src/Aspire.Cli/Commands/RunCommand.cs +++ b/src/Aspire.Cli/Commands/RunCommand.cs @@ -188,9 +188,13 @@ protected override async Task ExecuteAsync(ParseResult parseResult, Cancell _ansiConsole.Write(topPadder); - var isCodespaces = _configuration.GetValue("CODESPACES", false); + // Use the presence of CodespacesUrlWithLoginToken to detect codespaces, as this is more reliable + // than environment variables since it comes from the same backend detection logic + var isCodespaces = dashboardUrls.CodespacesUrlWithLoginToken is not null; var isRemoteContainers = _configuration.GetValue("REMOTE_CONTAINERS", false); + AppendCtrlCMessage(longestLocalizedLength); + if (isCodespaces || isRemoteContainers) { bool firstEndpoint = true; @@ -202,6 +206,13 @@ protected override async Task ExecuteAsync(ParseResult parseResult, Cancell { ProcessResourceState(resourceState, (resource, endpoint) => { + // When we are appending endpoints we need + // to remove the CTRL-C message that was appended + // previously. So we can write the endpoint. + // We will append the CTRL-C message again after + // writing the endpoint. + ClearLines(2); + var endpointsGrid = new Grid(); endpointsGrid.AddColumn(); endpointsGrid.AddColumn(); @@ -220,6 +231,8 @@ protected override async Task ExecuteAsync(ParseResult parseResult, Cancell var endpointsPadder = new Padder(endpointsGrid, new Padding(3, 0)); _ansiConsole.Write(endpointsPadder); firstEndpoint = false; + + AppendCtrlCMessage(longestLocalizedLength); }); } } @@ -278,6 +291,34 @@ protected override async Task ExecuteAsync(ParseResult parseResult, Cancell } } + private void ClearLines(int lines) + { + if (lines <= 0) + { + return; + } + + for (var i = 0; i < lines; i++) + { + _ansiConsole.Write("\u001b[1A"); + _ansiConsole.Write("\u001b[2K"); // Clear the line + } + } + + private void AppendCtrlCMessage(int longestLocalizedLength) + { + + var ctrlCGrid = new Grid(); + ctrlCGrid.AddColumn(); + ctrlCGrid.AddColumn(); + ctrlCGrid.Columns[0].Width = longestLocalizedLength + 1; + ctrlCGrid.AddRow(Text.Empty, Text.Empty); + ctrlCGrid.AddRow(new Text(string.Empty), new Markup(RunCommandStrings.PressCtrlCToStopAppHost)); + + var ctrlCPadder = new Padder(ctrlCGrid, new Padding(3, 0)); + _ansiConsole.Write(ctrlCPadder); + } + private static FileInfo GetAppHostLogFile() { var homeDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); diff --git a/src/Aspire.Cli/Resources/RunCommandStrings.resx b/src/Aspire.Cli/Resources/RunCommandStrings.resx index 1b61af4795a..465f8cc111f 100644 --- a/src/Aspire.Cli/Resources/RunCommandStrings.resx +++ b/src/Aspire.Cli/Resources/RunCommandStrings.resx @@ -143,7 +143,7 @@ Endpoints - Press [bold]Ctrl+C[/] to stop the app host and exit. + Press [bold]CTRL+C[/] to stop the apphost and exit. [bold] should not be localized diff --git a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.cs.xlf b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.cs.xlf index 40af96bcd2e..eadc074616d 100644 --- a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.cs.xlf +++ b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.cs.xlf @@ -33,8 +33,8 @@ - Press [bold]Ctrl+C[/] to stop the app host and exit. - Stisknutím kláves [bold]Ctrl+C[/] zastavíte hostitele aplikací a ukončíte ho. + Press [bold]CTRL+C[/] to stop the apphost and exit. + Stisknutím kláves [bold]Ctrl+C[/] zastavíte hostitele aplikací a ukončíte ho. [bold] should not be localized diff --git a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.de.xlf b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.de.xlf index cb6308155b9..6b375fe3fa1 100644 --- a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.de.xlf +++ b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.de.xlf @@ -33,8 +33,8 @@ - Press [bold]Ctrl+C[/] to stop the app host and exit. - Drücken Sie [bold]STRG+C[/], um den App-Host zu beenden und zu verlassen. + Press [bold]CTRL+C[/] to stop the apphost and exit. + Drücken Sie [bold]STRG+C[/], um den App-Host zu beenden und zu verlassen. [bold] should not be localized diff --git a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.es.xlf b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.es.xlf index 7008966a62f..35c94344ab2 100644 --- a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.es.xlf +++ b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.es.xlf @@ -33,8 +33,8 @@ - Press [bold]Ctrl+C[/] to stop the app host and exit. - Presione [bold]Ctrl+C[/] para detener el host de la aplicación y salir. + Press [bold]CTRL+C[/] to stop the apphost and exit. + Presione [bold]Ctrl+C[/] para detener el host de la aplicación y salir. [bold] should not be localized diff --git a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.fr.xlf b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.fr.xlf index 744c7a9a1bc..877fa72ea65 100644 --- a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.fr.xlf +++ b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.fr.xlf @@ -33,8 +33,8 @@ - Press [bold]Ctrl+C[/] to stop the app host and exit. - Appuyez sur [bold]Ctrl+C[/] pour arrêter l'hôte de l'application et quitter. + Press [bold]CTRL+C[/] to stop the apphost and exit. + Appuyez sur [bold]Ctrl+C[/] pour arrêter l'hôte de l'application et quitter. [bold] should not be localized diff --git a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.it.xlf b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.it.xlf index d9c7af95650..91cb7230f36 100644 --- a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.it.xlf +++ b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.it.xlf @@ -33,8 +33,8 @@ - Press [bold]Ctrl+C[/] to stop the app host and exit. - Premi [bold]CTRL+C[/] per arrestare l'host dell'app e uscire. + Press [bold]CTRL+C[/] to stop the apphost and exit. + Premi [bold]CTRL+C[/] per arrestare l'host dell'app e uscire. [bold] should not be localized diff --git a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.ja.xlf b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.ja.xlf index cedcd0ae56e..faaf3687b0b 100644 --- a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.ja.xlf +++ b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.ja.xlf @@ -33,8 +33,8 @@ - Press [bold]Ctrl+C[/] to stop the app host and exit. - [bold]Ctrl+C[/] キーを押してアプリ ホスティング プロセスを停止し、終了します。 + Press [bold]CTRL+C[/] to stop the apphost and exit. + [bold]Ctrl+C[/] キーを押してアプリ ホスティング プロセスを停止し、終了します。 [bold] should not be localized diff --git a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.ko.xlf b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.ko.xlf index f1b05aae640..b818848425c 100644 --- a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.ko.xlf +++ b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.ko.xlf @@ -33,8 +33,8 @@ - Press [bold]Ctrl+C[/] to stop the app host and exit. - 앱 호스트를 중지하고 종료하려면 [bold]Ctrl+C[/]를 누르세요. + Press [bold]CTRL+C[/] to stop the apphost and exit. + 앱 호스트를 중지하고 종료하려면 [bold]Ctrl+C[/]를 누르세요. [bold] should not be localized diff --git a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.pl.xlf b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.pl.xlf index 5542bc7650f..9e0906eb916 100644 --- a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.pl.xlf +++ b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.pl.xlf @@ -33,8 +33,8 @@ - Press [bold]Ctrl+C[/] to stop the app host and exit. - Naciśnij [bold]Ctrl+C[/], aby zatrzymać hosta aplikacji i zakończyć działanie. + Press [bold]CTRL+C[/] to stop the apphost and exit. + Naciśnij [bold]Ctrl+C[/], aby zatrzymać hosta aplikacji i zakończyć działanie. [bold] should not be localized diff --git a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.pt-BR.xlf b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.pt-BR.xlf index b90f451b007..2aabfce8ea3 100644 --- a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.pt-BR.xlf +++ b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.pt-BR.xlf @@ -33,8 +33,8 @@ - Press [bold]Ctrl+C[/] to stop the app host and exit. - Pressione [bold]Ctrl+C[/] para interromper o host de aplicativo e sair. + Press [bold]CTRL+C[/] to stop the apphost and exit. + Pressione [bold]Ctrl+C[/] para interromper o host de aplicativo e sair. [bold] should not be localized diff --git a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.ru.xlf b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.ru.xlf index d301539fe27..816b4bc5de9 100644 --- a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.ru.xlf +++ b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.ru.xlf @@ -33,8 +33,8 @@ - Press [bold]Ctrl+C[/] to stop the app host and exit. - Нажмите [bold]Ctrl+C[/], чтобы остановить хост приложений и выйти. + Press [bold]CTRL+C[/] to stop the apphost and exit. + Нажмите [bold]Ctrl+C[/], чтобы остановить хост приложений и выйти. [bold] should not be localized diff --git a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.tr.xlf b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.tr.xlf index 5cbcf6be66d..958a67f6564 100644 --- a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.tr.xlf +++ b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.tr.xlf @@ -33,8 +33,8 @@ - Press [bold]Ctrl+C[/] to stop the app host and exit. - [bold]Ctrl+C[/] tuşlarına basarak uygulama ana işlemini durdurun ve çıkın. + Press [bold]CTRL+C[/] to stop the apphost and exit. + [bold]Ctrl+C[/] tuşlarına basarak uygulama ana işlemini durdurun ve çıkın. [bold] should not be localized diff --git a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.zh-Hans.xlf b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.zh-Hans.xlf index 0b8bb6ad3c8..fe36c91f092 100644 --- a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.zh-Hans.xlf +++ b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.zh-Hans.xlf @@ -33,8 +33,8 @@ - Press [bold]Ctrl+C[/] to stop the app host and exit. - 按 [bold]Ctrl+C[/] 以停止应用主机并退出。 + Press [bold]CTRL+C[/] to stop the apphost and exit. + 按 [bold]Ctrl+C[/] 以停止应用主机并退出。 [bold] should not be localized diff --git a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.zh-Hant.xlf b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.zh-Hant.xlf index ed2990d03fc..1af1f213dad 100644 --- a/src/Aspire.Cli/Resources/xlf/RunCommandStrings.zh-Hant.xlf +++ b/src/Aspire.Cli/Resources/xlf/RunCommandStrings.zh-Hant.xlf @@ -33,8 +33,8 @@ - Press [bold]Ctrl+C[/] to stop the app host and exit. - 按 [bold]Ctrl+C[/] 以停止應用程式主機並結束。 + Press [bold]CTRL+C[/] to stop the apphost and exit. + 按 [bold]Ctrl+C[/] 以停止應用程式主機並結束。 [bold] should not be localized