Skip to content

Commit 5117b23

Browse files
committed
Merge pull request #251 from PowerShell/master
Merge changes to match PSReadline that ships in Win10
2 parents 3c6ea48 + 7ccac6c commit 5117b23

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+749
-552
lines changed

CheckHelp.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Import-Module -Name PSReadline
22

33
$about_topic = Get-Help -Name about_PSReadline
44

5-
$methods = [PSConsoleUtilities.PSConsoleReadLine].GetMethods('public,static') |
5+
$methods = [Microsoft.PowerShell.PSConsoleReadLine].GetMethods('public,static') |
66
Where-Object {
77
$method = $_
88
$parameters = $method.GetParameters()
@@ -59,4 +59,4 @@ Get-PSReadlineKeyHandler |
5959
Where-Object { $_.Function -eq $_.Description } |
6060
ForEach-Object {
6161
"Function missing description: $($_.Function)"
62-
}
62+
}

MakeRelease.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $files = @('PSReadline\Changes.txt',
2525
'PSReadline\PSReadline.psd1',
2626
'PSReadline\PSReadline.psm1',
2727
'PSReadline\PSReadline.format.ps1xml',
28-
'PSReadline\bin\Release\PSReadline.dll')
28+
'PSReadline\bin\Release\Microsoft.PowerShell.PSReadline.dll')
2929

3030
foreach ($file in $files)
3131
{
@@ -40,7 +40,7 @@ foreach ($file in $files)
4040
copy $PSScriptRoot\$file $targetDir\en-us
4141
}
4242

43-
$version = (Get-ChildItem -Path $targetDir\PSReadline.dll).VersionInfo.FileVersion
43+
$version = (Get-ChildItem -Path $targetDir\Microsoft.PowerShell.PSReadline.dll).VersionInfo.FileVersion
4444

4545
& $PSScriptRoot\Update-ModuleManifest.ps1 $targetDir\PSReadline.psd1 $version
4646

PSReadLine/AssemblyInfo.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
using System.Reflection;
1+
/********************************************************************++
2+
Copyright (c) Microsoft Corporation. All rights reserved.
3+
--********************************************************************/
4+
5+
using System.Reflection;
26
using System.Runtime.InteropServices;
37

48
// General Information about an assembly is controlled through the following

PSReadLine/BasicEditing.cs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
using System;
1+
/********************************************************************++
2+
Copyright (c) Microsoft Corporation. All rights reserved.
3+
--********************************************************************/
4+
5+
using System;
6+
using System.Diagnostics.CodeAnalysis;
7+
using System.Globalization;
28
using System.Linq;
39
using System.Management.Automation;
410
using System.Management.Automation.Language;
11+
using System.Management.Automation.Runspaces;
512

6-
namespace PSConsoleUtilities
13+
namespace Microsoft.PowerShell
714
{
815
public partial class PSConsoleReadLine
916
{
1017
/// <summary>
1118
/// Insert the key
1219
/// </summary>
20+
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
1321
public static void SelfInsert(ConsoleKeyInfo? key = null, object arg = null)
1422
{
1523
if (!key.HasValue)
@@ -55,6 +63,7 @@ public static void SelfInsert(ConsoleKeyInfo? key = null, object arg = null)
5563
/// <summary>
5664
/// Reverts all of the input to the current input.
5765
/// </summary>
66+
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
5867
public static void RevertLine(ConsoleKeyInfo? key = null, object arg = null)
5968
{
6069
if (_singleton._statusIsErrorMessage)
@@ -75,6 +84,7 @@ public static void RevertLine(ConsoleKeyInfo? key = null, object arg = null)
7584
/// Cancel the current input, leaving the input on the screen,
7685
/// but returns back to the host so the prompt is evaluated again.
7786
/// </summary>
87+
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
7888
public static void CancelLine(ConsoleKeyInfo? key = null, object arg = null)
7989
{
8090
_singleton.ClearStatusMessage(false);
@@ -109,6 +119,7 @@ public static void CancelLine(ConsoleKeyInfo? key = null, object arg = null)
109119
/// Like ForwardKillLine - deletes text from the point to the end of the line,
110120
/// but does not put the deleted text in the kill ring.
111121
/// </summary>
122+
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
112123
public static void ForwardDeleteLine(ConsoleKeyInfo? key = null, object arg = null)
113124
{
114125
var current = _singleton._current;
@@ -127,6 +138,7 @@ public static void ForwardDeleteLine(ConsoleKeyInfo? key = null, object arg = nu
127138
/// Like BackwardKillLine - deletes text from the point to the start of the line,
128139
/// but does not put the deleted text in the kill ring.
129140
/// </summary>
141+
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
130142
public static void BackwardDeleteLine(ConsoleKeyInfo? key = null, object arg = null)
131143
{
132144
if (_singleton._current > 0)
@@ -142,6 +154,7 @@ public static void BackwardDeleteLine(ConsoleKeyInfo? key = null, object arg = n
142154
/// <summary>
143155
/// Delete the character before the cursor.
144156
/// </summary>
157+
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
145158
public static void BackwardDeleteChar(ConsoleKeyInfo? key = null, object arg = null)
146159
{
147160
if (_singleton._visualSelectionCommandCount > 0)
@@ -191,6 +204,7 @@ private void DeleteCharImpl(bool orExit)
191204
/// <summary>
192205
/// Delete the character under the cursor.
193206
/// </summary>
207+
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
194208
public static void DeleteChar(ConsoleKeyInfo? key = null, object arg = null)
195209
{
196210
_singleton.DeleteCharImpl(orExit: false);
@@ -199,6 +213,7 @@ public static void DeleteChar(ConsoleKeyInfo? key = null, object arg = null)
199213
/// <summary>
200214
/// Delete the character under the cursor, or if the line is empty, exit the process
201215
/// </summary>
216+
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
202217
public static void DeleteCharOrExit(ConsoleKeyInfo? key = null, object arg = null)
203218
{
204219
_singleton.DeleteCharImpl(orExit: true);
@@ -223,6 +238,7 @@ private bool AcceptLineImpl(bool validate)
223238
_emphasisStart = -1;
224239
_emphasisLength = 0;
225240

241+
var insertionPoint = _current;
226242
// Make sure cursor is at the end before writing the line
227243
_current = _buffer.Length;
228244

@@ -239,6 +255,17 @@ private bool AcceptLineImpl(bool validate)
239255
var errorMessage = Validate(_ast);
240256
if (!string.IsNullOrWhiteSpace(errorMessage))
241257
{
258+
// If there are more keys, assume the user pasted with a right click and
259+
// we should insert a newline even though validation failed.
260+
if (_queuedKeys.Count > 0)
261+
{
262+
// Validation may have moved the cursor. Because there are queued
263+
// keys, we need to move the cursor back to the correct place, and
264+
// ignore where validation put the cursor because the queued keys
265+
// will be inserted in the wrong place.
266+
SetCursorPosition(insertionPoint);
267+
Insert('\n');
268+
}
242269
_statusLinePrompt = "";
243270
_statusBuffer.Append(errorMessage);
244271
_statusIsErrorMessage = true;
@@ -280,7 +307,7 @@ public override AstVisitAction VisitCommand(CommandAst commandAst)
280307
if (commandInfo == null && !_singleton.UnresolvedCommandCouldSucceed(commandName, _rootAst))
281308
{
282309
_singleton._current = commandAst.CommandElements[0].Extent.EndOffset;
283-
detectedError = string.Format(PSReadLineResources.CommandNotFoundError, commandName);
310+
detectedError = string.Format(CultureInfo.CurrentCulture, PSReadLineResources.CommandNotFoundError, commandName);
284311
return AstVisitAction.StopVisit;
285312
}
286313
}
@@ -415,6 +442,7 @@ static bool StaticParameterBindingSupported(CommandInfo commandInfo)
415442
/// continuation prompt is displayed on the next line and PSReadline waits for
416443
/// keys to edit the current input.
417444
/// </summary>
445+
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
418446
public static void AcceptLine(ConsoleKeyInfo? key = null, object arg = null)
419447
{
420448
_singleton.AcceptLineImpl(false);
@@ -426,6 +454,7 @@ public static void AcceptLine(ConsoleKeyInfo? key = null, object arg = null)
426454
/// continuation prompt is displayed on the next line and PSReadline waits for
427455
/// keys to edit the current input.
428456
/// </summary>
457+
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
429458
public static void ValidateAndAcceptLine(ConsoleKeyInfo? key = null, object arg = null)
430459
{
431460
_singleton.AcceptLineImpl(true);
@@ -435,6 +464,7 @@ public static void ValidateAndAcceptLine(ConsoleKeyInfo? key = null, object arg
435464
/// Attempt to execute the current input. If it can be executed (like AcceptLine),
436465
/// then recall the next item from history the next time Readline is called.
437466
/// </summary>
467+
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
438468
public static void AcceptAndGetNext(ConsoleKeyInfo? key = null, object arg = null)
439469
{
440470
if (_singleton.AcceptLineImpl(false))
@@ -455,6 +485,7 @@ public static void AcceptAndGetNext(ConsoleKeyInfo? key = null, object arg = nul
455485
/// keys to edit the current input. This is useful to enter multi-line input as
456486
/// a single command even when a single line is complete input by itself.
457487
/// </summary>
488+
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
458489
public static void AddLine(ConsoleKeyInfo? key = null, object arg = null)
459490
{
460491
Insert('\n');

PSReadLine/Changes.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
### Version 1.0.0.14
1+
### Version 1.1.0
2+
3+
Breaking change:
4+
* Namespace PSConsoleUtilities has been renamed to Microsoft.PowerShell
25

36
### Version 1.0.0.13
47

PSReadLine/Cmdlets.cs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
using System;
1+
/********************************************************************++
2+
Copyright (c) Microsoft Corporation. All rights reserved.
3+
--********************************************************************/
4+
5+
using System;
26
using System.Collections.Generic;
37
using System.Collections.ObjectModel;
48
using System.Diagnostics.CodeAnalysis;
@@ -7,8 +11,11 @@
711
using System.Reflection;
812
using System.Linq;
913

10-
namespace PSConsoleUtilities
14+
namespace Microsoft.PowerShell
1115
{
16+
17+
#pragma warning disable 1591
18+
1219
public enum TokenClassification
1320
{
1421
None,
@@ -64,7 +71,7 @@ public class PSConsoleReadlineOptions
6471

6572
public const EditMode DefaultEditMode = EditMode.Windows;
6673

67-
public const string DefaultContinuationPrompt = ">>> ";
74+
public const string DefaultContinuationPrompt = ">> ";
6875

6976
/// <summary>
7077
/// The maximum number of commands to store in the history.
@@ -132,7 +139,7 @@ public PSConsoleReadlineOptions(string hostName)
132139
HistorySearchCaseSensitive = DefaultHistorySearchCaseSensitive;
133140
HistorySaveStyle = DefaultHistorySaveStyle;
134141
HistorySavePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
135-
+ @"\PSReadline\" + hostName + "_history.txt";
142+
+ @"\Microsoft\Windows\PowerShell\PSReadline\" + hostName + "_history.txt";
136143
CommandValidationHandler = null;
137144
CommandsToValidateScriptBlockArguments = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
138145
{
@@ -189,6 +196,7 @@ public PSConsoleReadlineOptions(string hostName)
189196
/// odd things with script blocks, we create a white-list of commands
190197
/// that do invoke the script block - this covers the most useful cases.
191198
/// </summary>
199+
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
192200
public HashSet<string> CommandsToValidateScriptBlockArguments { get; set; }
193201

194202
/// <summary>
@@ -317,7 +325,7 @@ internal void SetBackgroundColor(TokenClassification tokenKind, ConsoleColor col
317325
}
318326
}
319327

320-
[Cmdlet("Get", "PSReadlineOption")]
328+
[Cmdlet("Get", "PSReadlineOption", HelpUri = "http://go.microsoft.com/fwlink/?LinkId=528808")]
321329
[OutputType(typeof(PSConsoleReadlineOptions))]
322330
public class GetPSReadlineOption : PSCmdlet
323331
{
@@ -328,7 +336,7 @@ protected override void EndProcessing()
328336
}
329337
}
330338

331-
[Cmdlet("Set", "PSReadlineOption")]
339+
[Cmdlet("Set", "PSReadlineOption", HelpUri = "http://go.microsoft.com/fwlink/?LinkId=528811")]
332340
public class SetPSReadlineOption : PSCmdlet
333341
{
334342
[Parameter(ParameterSetName = "OptionsSet")]
@@ -561,12 +569,13 @@ protected override void EndProcessing()
561569
}
562570
}
563571

564-
[Cmdlet("Set", "PSReadlineKeyHandler")]
572+
[Cmdlet("Set", "PSReadlineKeyHandler", HelpUri = "http://go.microsoft.com/fwlink/?LinkId=528810")]
565573
public class SetPSReadlineKeyHandlerCommand : PSCmdlet, IDynamicParameters
566574
{
567575
[Parameter(Position = 0, Mandatory = true)]
568576
[Alias("Key")]
569577
[ValidateNotNullOrEmpty]
578+
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
570579
public string[] Chord { get; set; }
571580

572581
[Parameter(Position = 1, Mandatory = true, ParameterSetName = "ScriptBlock")]
@@ -638,7 +647,7 @@ public object GetDynamicParameters()
638647
}
639648
}
640649

641-
[Cmdlet("Get", "PSReadlineKeyHandler")]
650+
[Cmdlet("Get", "PSReadlineKeyHandler", HelpUri = "http://go.microsoft.com/fwlink/?LinkId=528807")]
642651
[OutputType(typeof(KeyHandler))]
643652
public class GetKeyHandlerCommand : PSCmdlet
644653
{
@@ -682,12 +691,13 @@ protected override void EndProcessing()
682691
}
683692
}
684693

685-
[Cmdlet("Remove", "PSReadlineKeyHandler")]
694+
[Cmdlet("Remove", "PSReadlineKeyHandler", HelpUri = "http://go.microsoft.com/fwlink/?LinkId=528809")]
686695
public class RemoveKeyHandlerCommand : PSCmdlet
687696
{
688697
[Parameter(Position = 0, Mandatory = true)]
689698
[Alias("Key")]
690699
[ValidateNotNullOrEmpty]
700+
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
691701
public string[] Chord { get; set; }
692702

693703
[ExcludeFromCodeCoverage]
@@ -696,4 +706,7 @@ protected override void EndProcessing()
696706
PSConsoleReadLine.RemoveKeyHandler(Chord);
697707
}
698708
}
709+
710+
#pragma warning restore 1591
711+
699712
}

0 commit comments

Comments
 (0)