Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion src/Aspire.Cli/Commands/RunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,13 @@ protected override async Task<int> ExecuteAsync(ParseResult parseResult, Cancell

_ansiConsole.Write(topPadder);

var isCodespaces = _configuration.GetValue<bool>("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<bool>("REMOTE_CONTAINERS", false);

AppendCtrlCMessage(longestLocalizedLength);

if (isCodespaces || isRemoteContainers)
{
bool firstEndpoint = true;
Expand All @@ -202,6 +206,13 @@ protected override async Task<int> 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();
Expand All @@ -220,6 +231,8 @@ protected override async Task<int> ExecuteAsync(ParseResult parseResult, Cancell
var endpointsPadder = new Padder(endpointsGrid, new Padding(3, 0));
_ansiConsole.Write(endpointsPadder);
firstEndpoint = false;

AppendCtrlCMessage(longestLocalizedLength);
});
}
}
Expand Down Expand Up @@ -278,6 +291,34 @@ protected override async Task<int> 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);
Expand Down
2 changes: 1 addition & 1 deletion src/Aspire.Cli/Resources/RunCommandStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
<value>Endpoints</value>
</data>
<data name="PressCtrlCToStopAppHost" xml:space="preserve">
<value>Press [bold]Ctrl+C[/] to stop the app host and exit.</value>
<value>Press [bold]CTRL+C[/] to stop the apphost and exit.</value>
<comment>[bold] should not be localized</comment>
</data>
<data name="ProjectCouldNotBeRun" xml:space="preserve">
Expand Down
4 changes: 2 additions & 2 deletions src/Aspire.Cli/Resources/xlf/RunCommandStrings.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Aspire.Cli/Resources/xlf/RunCommandStrings.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Aspire.Cli/Resources/xlf/RunCommandStrings.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Aspire.Cli/Resources/xlf/RunCommandStrings.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Aspire.Cli/Resources/xlf/RunCommandStrings.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Aspire.Cli/Resources/xlf/RunCommandStrings.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Aspire.Cli/Resources/xlf/RunCommandStrings.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Aspire.Cli/Resources/xlf/RunCommandStrings.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Aspire.Cli/Resources/xlf/RunCommandStrings.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Aspire.Cli/Resources/xlf/RunCommandStrings.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Aspire.Cli/Resources/xlf/RunCommandStrings.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Aspire.Cli/Resources/xlf/RunCommandStrings.zh-Hans.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Aspire.Cli/Resources/xlf/RunCommandStrings.zh-Hant.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.