Skip to content

Commit 0df566a

Browse files
Copilotmitchdennymaddymontaquila
authored
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 <[email protected]> * Update CTRL-C message * Fix CTRL-C message formatting and change "app host" to "apphost" Co-authored-by: maddymontaquila <[email protected]> * Move CTRL+C message to appear after endpoints in codespaces Co-authored-by: maddymontaquila <[email protected]> * Fix CTRL+C message positioning in codespaces by improving environment detection Co-authored-by: mitchdenny <[email protected]> * Fixes to implementation. * Fix formatting (bye bye pink) --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: mitchdenny <[email protected]> Co-authored-by: Mitch Denny <[email protected]> Co-authored-by: maddymontaquila <[email protected]>
1 parent da81496 commit 0df566a

15 files changed

+69
-28
lines changed

src/Aspire.Cli/Commands/RunCommand.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,13 @@ protected override async Task<int> ExecuteAsync(ParseResult parseResult, Cancell
188188

189189
_ansiConsole.Write(topPadder);
190190

191-
var isCodespaces = _configuration.GetValue<bool>("CODESPACES", false);
191+
// Use the presence of CodespacesUrlWithLoginToken to detect codespaces, as this is more reliable
192+
// than environment variables since it comes from the same backend detection logic
193+
var isCodespaces = dashboardUrls.CodespacesUrlWithLoginToken is not null;
192194
var isRemoteContainers = _configuration.GetValue<bool>("REMOTE_CONTAINERS", false);
193195

196+
AppendCtrlCMessage(longestLocalizedLength);
197+
194198
if (isCodespaces || isRemoteContainers)
195199
{
196200
bool firstEndpoint = true;
@@ -202,6 +206,13 @@ protected override async Task<int> ExecuteAsync(ParseResult parseResult, Cancell
202206
{
203207
ProcessResourceState(resourceState, (resource, endpoint) =>
204208
{
209+
// When we are appending endpoints we need
210+
// to remove the CTRL-C message that was appended
211+
// previously. So we can write the endpoint.
212+
// We will append the CTRL-C message again after
213+
// writing the endpoint.
214+
ClearLines(2);
215+
205216
var endpointsGrid = new Grid();
206217
endpointsGrid.AddColumn();
207218
endpointsGrid.AddColumn();
@@ -220,6 +231,8 @@ protected override async Task<int> ExecuteAsync(ParseResult parseResult, Cancell
220231
var endpointsPadder = new Padder(endpointsGrid, new Padding(3, 0));
221232
_ansiConsole.Write(endpointsPadder);
222233
firstEndpoint = false;
234+
235+
AppendCtrlCMessage(longestLocalizedLength);
223236
});
224237
}
225238
}
@@ -278,6 +291,34 @@ protected override async Task<int> ExecuteAsync(ParseResult parseResult, Cancell
278291
}
279292
}
280293

294+
private void ClearLines(int lines)
295+
{
296+
if (lines <= 0)
297+
{
298+
return;
299+
}
300+
301+
for (var i = 0; i < lines; i++)
302+
{
303+
_ansiConsole.Write("\u001b[1A");
304+
_ansiConsole.Write("\u001b[2K"); // Clear the line
305+
}
306+
}
307+
308+
private void AppendCtrlCMessage(int longestLocalizedLength)
309+
{
310+
311+
var ctrlCGrid = new Grid();
312+
ctrlCGrid.AddColumn();
313+
ctrlCGrid.AddColumn();
314+
ctrlCGrid.Columns[0].Width = longestLocalizedLength + 1;
315+
ctrlCGrid.AddRow(Text.Empty, Text.Empty);
316+
ctrlCGrid.AddRow(new Text(string.Empty), new Markup(RunCommandStrings.PressCtrlCToStopAppHost));
317+
318+
var ctrlCPadder = new Padder(ctrlCGrid, new Padding(3, 0));
319+
_ansiConsole.Write(ctrlCPadder);
320+
}
321+
281322
private static FileInfo GetAppHostLogFile()
282323
{
283324
var homeDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

src/Aspire.Cli/Resources/RunCommandStrings.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
<value>Endpoints</value>
144144
</data>
145145
<data name="PressCtrlCToStopAppHost" xml:space="preserve">
146-
<value>Press [bold]Ctrl+C[/] to stop the app host and exit.</value>
146+
<value>Press [bold]CTRL+C[/] to stop the apphost and exit.</value>
147147
<comment>[bold] should not be localized</comment>
148148
</data>
149149
<data name="ProjectCouldNotBeRun" xml:space="preserve">

src/Aspire.Cli/Resources/xlf/RunCommandStrings.cs.xlf

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Aspire.Cli/Resources/xlf/RunCommandStrings.de.xlf

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Aspire.Cli/Resources/xlf/RunCommandStrings.es.xlf

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Aspire.Cli/Resources/xlf/RunCommandStrings.fr.xlf

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Aspire.Cli/Resources/xlf/RunCommandStrings.it.xlf

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Aspire.Cli/Resources/xlf/RunCommandStrings.ja.xlf

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Aspire.Cli/Resources/xlf/RunCommandStrings.ko.xlf

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Aspire.Cli/Resources/xlf/RunCommandStrings.pl.xlf

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)