Skip to content

Add TerminateStragglers option (Windows) #3764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
10 changes: 10 additions & 0 deletions PSReadLine/Cmdlets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ public object ListPredictionTooltipColor
set => _listPredictionTooltipColor = VTColorUtils.AsEscapeSequence(value);
}

public bool TerminateOrphanedConsoleApps { get; set; }

internal string _defaultTokenColor;
internal string _commentColor;
internal string _keywordColor;
Expand Down Expand Up @@ -808,6 +810,14 @@ public PredictionViewStyle PredictionViewStyle
[Parameter]
public Hashtable Colors { get; set; }

[Parameter]
public SwitchParameter TerminateOrphanedConsoleApps
{
get => _terminateOrphanedConsoleApps.GetValueOrDefault();
set => _terminateOrphanedConsoleApps = value;
}
internal SwitchParameter? _terminateOrphanedConsoleApps;

[ExcludeFromCodeCoverage]
protected override void EndProcessing()
{
Expand Down
18 changes: 18 additions & 0 deletions PSReadLine/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Management.Automation;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.PowerShell.PSReadLine;

Expand Down Expand Up @@ -167,6 +169,22 @@ private void SetOptionsInternal(SetPSReadLineOption options)
}
}
}
if (options._terminateOrphanedConsoleApps.HasValue)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Options.TerminateOrphanedConsoleApps = options.TerminateOrphanedConsoleApps;
PlatformWindows.SetTerminateOrphanedConsoleApps(Options.TerminateOrphanedConsoleApps);
}
else
{
throw new PlatformNotSupportedException(
string.Format(
CultureInfo.CurrentUICulture,
PSReadLineResources.OptionNotSupportedOnNonWindows,
nameof(Options.TerminateOrphanedConsoleApps)));
}
}
}

private void SetKeyHandlerInternal(string[] keys, Action<ConsoleKeyInfo?, object> handler, string briefDescription, string longDescription, ScriptBlock scriptBlock)
Expand Down
3 changes: 3 additions & 0 deletions PSReadLine/PSReadLine.format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ $d = [Microsoft.PowerShell.KeyHandler]::GetGroupingDescription($_.Group)
<ListItem>
<PropertyName>PredictionViewStyle</PropertyName>
</ListItem>
<ListItem>
<PropertyName>TerminateOrphanedConsoleApps</PropertyName>
</ListItem>
<ListItem>
<Label>CommandColor</Label>
<ScriptBlock>[Microsoft.PowerShell.VTColorUtils]::FormatColor($_.CommandColor)</ScriptBlock>
Expand Down
11 changes: 11 additions & 0 deletions PSReadLine/PSReadLineResources.Designer.cs

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

3 changes: 3 additions & 0 deletions PSReadLine/PSReadLineResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -873,4 +873,7 @@ Or not saving history with:
<data name="UpcaseWordDescription" xml:space="preserve">
<value>Find the next word starting from the current position and then make it upper case.</value>
</data>
<data name="OptionNotSupportedOnNonWindows" xml:space="preserve">
<value>The '{0}' option is not supported on non-Windows platforms.</value>
</data>
</root>
Loading