From b6209a92d96ab8818147b97fe6de51d9a5d4e286 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 27 Apr 2016 10:56:14 -0700 Subject: [PATCH 01/58] Add PSReadLine project.json --- PSReadLine/project.json | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 PSReadLine/project.json diff --git a/PSReadLine/project.json b/PSReadLine/project.json new file mode 100644 index 000000000..809c0b397 --- /dev/null +++ b/PSReadLine/project.json @@ -0,0 +1,22 @@ +{ + "name": "Microsoft.PowerShell.PSReadLine", + "version": "1.0.0-*", + "authors": [ "andschwa" ], + + "compilationOptions": { + "warningsAsErrors": true + }, + + "dependencies": { + "System.Management.Automation": "1.0.0-*" + }, + + "frameworks": { + "netstandard1.5": { + "compilationOptions": { + "define": [ "CORECLR" ] + }, + "imports": [ "dnxcore50", "portable-net45+win8" ] + } + } +} From 8bd472ac5da3ee0b5d8faf1de8e4920df73a3650 Mon Sep 17 00:00:00 2001 From: George Fleming Date: Wed, 13 Apr 2016 11:33:45 -0700 Subject: [PATCH 02/58] PSReadLine for Linux --- PSReadLine/Cmdlets.cs | 39 ++++++++++ PSReadLine/Completion.cs | 2 + PSReadLine/ConsoleLib.cs | 83 +++++++++++++++++++++- PSReadLine/HistoryQueue.cs | 6 +- PSReadLine/KeyBindings.cs | 4 ++ PSReadLine/KeyBindings.vi.cs | 4 ++ PSReadLine/Keys.cs | 23 +++++- PSReadLine/KillYank.cs | 8 ++- PSReadLine/Options.cs | 2 +- PSReadLine/PSReadLineResources.Designer.cs | 4 +- PSReadLine/ReadLine.cs | 77 ++++++++++++++++++-- PSReadLine/Render.cs | 10 +++ PSReadLine/ScreenCapture.cs | 4 +- PSReadLine/VisualEditing.vi.cs | 12 +++- 14 files changed, 262 insertions(+), 16 deletions(-) diff --git a/PSReadLine/Cmdlets.cs b/PSReadLine/Cmdlets.cs index 8bad00ca0..6055b079f 100644 --- a/PSReadLine/Cmdlets.cs +++ b/PSReadLine/Cmdlets.cs @@ -10,6 +10,9 @@ using System.Management.Automation.Language; using System.Reflection; using System.Linq; +#if CORECLR +using System.Runtime.InteropServices; +#endif namespace Microsoft.PowerShell { @@ -82,6 +85,7 @@ public class PSConsoleReadlineOptions public const ConsoleColor DefaultEmphasisForegroundColor = ConsoleColor.Cyan; public const ConsoleColor DefaultErrorForegroundColor = ConsoleColor.Red; + public const EditMode DefaultEditMode = EditMode.Windows; public const string DefaultContinuationPrompt = ">> "; @@ -151,8 +155,24 @@ public PSConsoleReadlineOptions(string hostName) WordDelimiters = DefaultWordDelimiters; HistorySearchCaseSensitive = DefaultHistorySearchCaseSensitive; HistorySaveStyle = DefaultHistorySaveStyle; +#if CORECLR + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) // MS Windows + { + HistorySavePath = System.IO.Path.Combine(Environment.ExpandEnvironmentVariables("%AppData%"), + @"\Microsoft\Windows\PowerShell\PSReadline\", + hostName + "_history.txt"); + } + else + { + HistorySavePath = System.IO.Path.Combine( + Environment.GetEnvironmentVariable("HOME"), + ".psreadline", + hostName + "_history.txt"); + } +#else HistorySavePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Microsoft\Windows\PowerShell\PSReadline\" + hostName + "_history.txt"; +#endif CommandValidationHandler = null; CommandsToValidateScriptBlockArguments = new HashSet(StringComparer.OrdinalIgnoreCase) { @@ -346,7 +366,9 @@ internal void SetBackgroundColor(TokenClassification tokenKind, ConsoleColor col [OutputType(typeof(PSConsoleReadlineOptions))] public class GetPSReadlineOption : PSCmdlet { +#if !CORECLR [ExcludeFromCodeCoverage] +#endif protected override void EndProcessing() { WriteObject(PSConsoleReadLine.GetOptions()); @@ -589,7 +611,9 @@ public ConsoleColor BackgroundColor } internal ConsoleColor? _backgroundColor; +#if !CORECLR [ExcludeFromCodeCoverage] +#endif protected override void EndProcessing() { PSConsoleReadLine.SetOptions(this); @@ -607,7 +631,9 @@ public class ChangePSReadlineKeyHandlerCommandBase : PSCmdlet [Parameter] public ViMode ViMode { get; set; } +#if !CORECLR [ExcludeFromCodeCoverage] +#endif protected IDisposable UseRequestedDispatchTables() { bool inViMode = PSConsoleReadLine.GetOptions().EditMode == EditMode.Vi; @@ -650,7 +676,9 @@ public class SetPSReadlineKeyHandlerCommand : ChangePSReadlineKeyHandlerCommandB private const string FunctionParameter = "Function"; private const string FunctionParameterSet = "Function"; +#if !CORECLR [ExcludeFromCodeCoverage] +#endif protected override void EndProcessing() { using (UseRequestedDispatchTables()) @@ -658,9 +686,16 @@ protected override void EndProcessing() if (ParameterSetName.Equals(FunctionParameterSet)) { var function = (string)_dynamicParameters.Value[FunctionParameter].Value; +#if CORECLR + MethodInfo mi = typeof (PSConsoleReadLine).GetMethod(function); + var keyHandler = (Action) + mi.CreateDelegate(typeof (Action)); + +#else var keyHandler = (Action) Delegate.CreateDelegate(typeof (Action), typeof (PSConsoleReadLine).GetMethod(function)); +#endif BriefDescription = function; PSConsoleReadLine.SetKeyHandler(Chord, keyHandler, BriefDescription, Description); } @@ -728,7 +763,9 @@ public SwitchParameter Unbound } private SwitchParameter? _unbound; +#if !CORECLR [ExcludeFromCodeCoverage] +#endif protected override void EndProcessing() { bool bound = true; @@ -755,7 +792,9 @@ protected override void EndProcessing() [Cmdlet("Remove", "PSReadlineKeyHandler", HelpUri = "http://go.microsoft.com/fwlink/?LinkId=528809")] public class RemoveKeyHandlerCommand : ChangePSReadlineKeyHandlerCommandBase { +#if !CORECLR [ExcludeFromCodeCoverage] +#endif protected override void EndProcessing() { using (UseRequestedDispatchTables()) diff --git a/PSReadLine/Completion.cs b/PSReadLine/Completion.cs index 402013386..b2d801f7f 100644 --- a/PSReadLine/Completion.cs +++ b/PSReadLine/Completion.cs @@ -24,7 +24,9 @@ public partial class PSConsoleReadLine private Runspace _runspace; // Stub helper method so completion can be mocked +#if !CORECLR [ExcludeFromCodeCoverage] +#endif CommandCompletion IPSConsoleReadLineMockableMethods.CompleteInput(string input, int cursorIndex, Hashtable options, System.Management.Automation.PowerShell powershell) { return CalloutUsingDefaultConsoleMode( diff --git a/PSReadLine/ConsoleLib.cs b/PSReadLine/ConsoleLib.cs index bea090828..7656a83a9 100644 --- a/PSReadLine/ConsoleLib.cs +++ b/PSReadLine/ConsoleLib.cs @@ -227,7 +227,9 @@ public struct SMALL_RECT public short Right; public short Bottom; +#if !CORECLR [ExcludeFromCodeCoverage] +#endif public override string ToString() { return String.Format(CultureInfo.InvariantCulture, "{0},{1},{2},{3}", Left, Top, Right, Bottom); @@ -239,7 +241,9 @@ internal struct COORD public short X; public short Y; +#if !CORECLR [ExcludeFromCodeCoverage] +#endif public override string ToString() { return String.Format(CultureInfo.InvariantCulture, "{0},{1}", X, Y); @@ -320,21 +324,27 @@ public CHAR_INFO(char c, ConsoleColor foreground, ConsoleColor background) Attributes = (ushort)(((int)background << 4) | (int)foreground); } +#if !CORECLR [ExcludeFromCodeCoverage] +#endif public ConsoleColor ForegroundColor { get { return (ConsoleColor)(Attributes & 0xf); } set { Attributes = (ushort)((Attributes & 0xfff0) | ((int)value & 0xf)); } } +#if !CORECLR [ExcludeFromCodeCoverage] +#endif public ConsoleColor BackgroundColor { get { return (ConsoleColor)((Attributes & 0xf0) >> 4); } set { Attributes = (ushort)((Attributes & 0xff0f) | (((int)value & 0xf) << 4)); } } +#if !CORECLR [ExcludeFromCodeCoverage] +#endif public override string ToString() { var sb = new StringBuilder(); @@ -346,7 +356,9 @@ public override string ToString() return sb.ToString(); } +#if !CORECLR [ExcludeFromCodeCoverage] +#endif public override bool Equals(object obj) { if (!(obj is CHAR_INFO)) @@ -358,7 +370,9 @@ public override bool Equals(object obj) return this.UnicodeChar == other.UnicodeChar && this.Attributes == other.Attributes; } +#if !CORECLR [ExcludeFromCodeCoverage] +#endif public override int GetHashCode() { return UnicodeChar.GetHashCode() + Attributes.GetHashCode(); @@ -384,6 +398,23 @@ public static string ToGestureString(this ConsoleKeyInfo key) sb.Append("Alt"); } +#if CORECLR + if (sb.Length > 0) + sb.Append("+"); + if ((key.Key >= ConsoleKey.D0 && key.Key <= ConsoleKey.D9) + || (key.Key >= ConsoleKey.Oem1 && key.Key <= ConsoleKey.Oem8)) + { + sb.Append(key.KeyChar); + } + else + { + if (key.Modifiers.HasFlag(ConsoleModifiers.Shift)) + { + sb.Append("Shift+"); + } + sb.Append(key.Key); + } +#else char c = ConsoleKeyChordConverter.GetCharFromConsoleKey(key.Key, (mods & ConsoleModifiers.Shift) != 0 ? ConsoleModifiers.Shift : 0); if (char.IsControl(c) || char.IsWhiteSpace(c)) @@ -404,6 +435,7 @@ public static string ToGestureString(this ConsoleKeyInfo key) sb.Append("+"); sb.Append(c); } +#endif return sb.ToString(); } } @@ -575,8 +607,9 @@ public void WriteBufferLines(CHAR_INFO[] buffer, ref int top) public void WriteBufferLines(CHAR_INFO[] buffer, ref int top, bool ensureBottomLineVisible) { +#if !CORECLR var handle = NativeMethods.GetStdHandle((uint) StandardHandleId.Output); - +#endif int bufferWidth = Console.BufferWidth; int bufferLineCount = buffer.Length / bufferWidth; if ((top + bufferLineCount) > Console.BufferHeight) @@ -585,6 +618,34 @@ public void WriteBufferLines(CHAR_INFO[] buffer, ref int top, bool ensureBottomL ScrollBuffer(scrollCount); top -= scrollCount; } +#if CORECLR + ConsoleColor foregroundColor = Console.ForegroundColor; + ConsoleColor backgroundColor = Console.BackgroundColor; + + Console.SetCursorPosition(0, (top>=0) ? top : 0); + + for (int i = 0; i < buffer.Length; ++i) + { + /* For some reasons, the default color comes out white on white */ + /* + if (buffer[i].ForegroundColor == ConsoleColor.White + && buffer[i].BackgroundColor == ConsoleColor.White) + { + Console.ForegroundColor = foregroundColor; + Console.BackgroundColor = backgroundColor; + } + else + { + Console.ForegroundColor = buffer[i].ForegroundColor; + Console.BackgroundColor = backgroundColor; + } + */ + Console.Write((char)buffer[i].UnicodeChar); + } + + Console.BackgroundColor = backgroundColor; + Console.ForegroundColor = foregroundColor; +#else var bufferSize = new COORD { X = (short) bufferWidth, @@ -608,10 +669,20 @@ public void WriteBufferLines(CHAR_INFO[] buffer, ref int top, bool ensureBottomL { Console.CursorTop = bottom; } +#endif } public void ScrollBuffer(int lines) { +#if CORECLR +// Console.MoveBufferArea(lines, 0, Console.BufferWidth, Console.BufferHeight - lines, 0, 0, ' ', +// Console.ForegroundColor, Console.BackgroundColor); + for (int i=0; i { private readonly HistoryQueue _queue; @@ -114,7 +116,9 @@ public T[] ToArray() return result; } +#if !CORECLR [ExcludeFromCodeCoverage] +#endif public T this[int index] { get diff --git a/PSReadLine/KeyBindings.cs b/PSReadLine/KeyBindings.cs index 293d6a9c5..5216933c0 100644 --- a/PSReadLine/KeyBindings.cs +++ b/PSReadLine/KeyBindings.cs @@ -133,9 +133,11 @@ void SetDefaultWindowsBindings() { Keys.CtrlSpace, MakeKeyHandler(MenuComplete, "MenuComplete") }, { Keys.Tab, MakeKeyHandler(TabCompleteNext, "TabCompleteNext") }, { Keys.ShiftTab, MakeKeyHandler(TabCompletePrevious, "TabCompletePrevious") }, +#if !CORECLR { Keys.VolumeDown, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeUp, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeMute, MakeKeyHandler(Ignore, "Ignore") }, +#endif { Keys.CtrlA, MakeKeyHandler(SelectAll, "SelectAll") }, { Keys.CtrlC, MakeKeyHandler(CopyOrCancelLine, "CopyOrCancelLine") }, { Keys.CtrlShiftC, MakeKeyHandler(Copy, "Copy") }, @@ -252,9 +254,11 @@ void SetDefaultEmacsBindings() { Keys.AltPeriod, MakeKeyHandler(YankLastArg, "YankLastArg") }, { Keys.AltUnderbar, MakeKeyHandler(YankLastArg, "YankLastArg") }, { Keys.AltCtrlY, MakeKeyHandler(YankNthArg, "YankNthArg") }, +#if !CORECLR { Keys.VolumeDown, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeUp, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeMute, MakeKeyHandler(Ignore, "Ignore") }, +#endif { Keys.PageUp, MakeKeyHandler(ScrollDisplayUp, "ScrollDisplayUp") }, { Keys.CtrlPageUp, MakeKeyHandler(ScrollDisplayUpLine, "ScrollDisplayUpLine") }, { Keys.PageDown, MakeKeyHandler(ScrollDisplayDown, "ScrollDisplayDown") }, diff --git a/PSReadLine/KeyBindings.vi.cs b/PSReadLine/KeyBindings.vi.cs index 0c6529a5b..d31cba72d 100644 --- a/PSReadLine/KeyBindings.vi.cs +++ b/PSReadLine/KeyBindings.vi.cs @@ -70,9 +70,11 @@ private void SetDefaultViBindings() { Keys.Tab, MakeKeyHandler(ViTabCompleteNext, "ViTabCompleteNext") }, { Keys.ShiftTab, MakeKeyHandler(ViTabCompletePrevious, "ViTabCompletePrevious") }, { Keys.CtrlV, MakeKeyHandler(Paste, "Paste") }, +#if !CORECLR { Keys.VolumeDown, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeUp, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeMute, MakeKeyHandler(Ignore, "Ignore") }, +#endif { Keys.CtrlC, MakeKeyHandler(CancelLine, "CancelLine") }, { Keys.CtrlL, MakeKeyHandler(ClearScreen, "ClearScreen") }, { Keys.CtrlY, MakeKeyHandler(Redo, "Redo") }, @@ -107,9 +109,11 @@ private void SetDefaultViBindings() { Keys.Tab, MakeKeyHandler(TabCompleteNext, "TabCompleteNext") }, { Keys.ShiftTab, MakeKeyHandler(TabCompletePrevious, "TabCompletePrevious") }, { Keys.CtrlV, MakeKeyHandler(Paste, "Paste") }, +#if !CORECLR { Keys.VolumeDown, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeUp, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeMute, MakeKeyHandler(Ignore, "Ignore") }, +#endif { Keys.CtrlC, MakeKeyHandler(CancelLine, "CancelLine") }, { Keys.CtrlL, MakeKeyHandler(ClearScreen, "ClearScreen") }, { Keys.CtrlT, MakeKeyHandler(SwapCharacters, "SwapCharacters") }, diff --git a/PSReadLine/Keys.cs b/PSReadLine/Keys.cs index 57f2248f3..dbd138991 100644 --- a/PSReadLine/Keys.cs +++ b/PSReadLine/Keys.cs @@ -3,11 +3,30 @@ --********************************************************************/ using System; +#if CORECLR +using System.Runtime.InteropServices; +#endif namespace Microsoft.PowerShell { internal static class Keys { + static Keys() + { +#if CORECLR + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + Enter = new ConsoleKeyInfo((char)10, ConsoleKey.Enter, false, false, false); + } + else + { + Enter = new ConsoleKeyInfo((char)13, ConsoleKey.Enter, false, false, false); + } +#else + Enter = new ConsoleKeyInfo((char)13, ConsoleKey.Enter, false, false, false); +#endif + } + public static ConsoleKeyInfo A = new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false); public static ConsoleKeyInfo B = new ConsoleKeyInfo('b', ConsoleKey.B, false, false, false); public static ConsoleKeyInfo C = new ConsoleKeyInfo('c', ConsoleKey.C, false, false, false); @@ -205,7 +224,7 @@ internal static class Keys public static ConsoleKeyInfo End = new ConsoleKeyInfo((char)0, ConsoleKey.End, false, false, false); public static ConsoleKeyInfo CtrlEnd = new ConsoleKeyInfo((char)0, ConsoleKey.End, false, false, true); public static ConsoleKeyInfo ShiftEnd = new ConsoleKeyInfo((char)0, ConsoleKey.End, true, false, false); - public static ConsoleKeyInfo Enter = new ConsoleKeyInfo((char)13, ConsoleKey.Enter, false, false, false); + public static ConsoleKeyInfo Enter; public static ConsoleKeyInfo Escape = new ConsoleKeyInfo((char)27, ConsoleKey.Escape, false, false, false); public static ConsoleKeyInfo Home = new ConsoleKeyInfo((char)0, ConsoleKey.Home, false, false, false); public static ConsoleKeyInfo CtrlHome = new ConsoleKeyInfo((char)0, ConsoleKey.Home, false, false, true); @@ -290,8 +309,10 @@ internal static class Keys public static ConsoleKeyInfo ShiftF8 = new ConsoleKeyInfo((char)0, ConsoleKey.F8, true, false, false); // Keys to ignore +#if !CORECLR public static ConsoleKeyInfo VolumeUp = new ConsoleKeyInfo((char)0, ConsoleKey.VolumeUp, false, false, false); public static ConsoleKeyInfo VolumeDown = new ConsoleKeyInfo((char)0, ConsoleKey.VolumeDown, false, false, false); public static ConsoleKeyInfo VolumeMute = new ConsoleKeyInfo((char)0, ConsoleKey.VolumeMute, false, false, false); +#endif } } diff --git a/PSReadLine/KillYank.cs b/PSReadLine/KillYank.cs index 86de83a7f..ba94cbdbd 100644 --- a/PSReadLine/KillYank.cs +++ b/PSReadLine/KillYank.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Management.Automation.Language; -using System.Windows.Forms; +//using System.Windows.Forms; namespace Microsoft.PowerShell { @@ -476,6 +476,7 @@ public static void SelectBackwardsLine(ConsoleKeyInfo? key = null, object arg = [SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")] public static void Paste(ConsoleKeyInfo? key = null, object arg = null) { +#if !CORECLR string textToPaste = null; ExecuteOnSTAThread(() => { if (Clipboard.ContainsText()) @@ -498,6 +499,7 @@ public static void Paste(ConsoleKeyInfo? key = null, object arg = null) Insert(textToPaste); } } +#endif } /// @@ -506,6 +508,7 @@ public static void Paste(ConsoleKeyInfo? key = null, object arg = null) [SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")] public static void Copy(ConsoleKeyInfo? key = null, object arg = null) { +#if !CORECLR string textToSet; if (_singleton._visualSelectionCommandCount > 0) { @@ -521,6 +524,7 @@ public static void Copy(ConsoleKeyInfo? key = null, object arg = null) { ExecuteOnSTAThread(() => Clipboard.SetText(textToSet)); } +#endif } /// @@ -545,6 +549,7 @@ public static void CopyOrCancelLine(ConsoleKeyInfo? key = null, object arg = nul [SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")] public static void Cut(ConsoleKeyInfo? key = null, object arg = null) { +#if !CORECLR if (_singleton._visualSelectionCommandCount > 0) { int start, length; @@ -552,6 +557,7 @@ public static void Cut(ConsoleKeyInfo? key = null, object arg = null) ExecuteOnSTAThread(() => Clipboard.SetText(_singleton._buffer.ToString(start, length))); Delete(start, length); } +#endif } } } diff --git a/PSReadLine/Options.cs b/PSReadLine/Options.cs index f200d735e..d8162b743 100644 --- a/PSReadLine/Options.cs +++ b/PSReadLine/Options.cs @@ -297,7 +297,7 @@ public static void RemoveKeyHandler(string[] key) public static IEnumerable GetKeyHandlers(bool includeBound = true, bool includeUnbound = false) { var boundFunctions = new HashSet(StringComparer.OrdinalIgnoreCase); - + foreach (var entry in _singleton._dispatchTable) { if (entry.Value.BriefDescription == "Ignore" diff --git a/PSReadLine/PSReadLineResources.Designer.cs b/PSReadLine/PSReadLineResources.Designer.cs index 1470cd00f..ee9503221 100644 --- a/PSReadLine/PSReadLineResources.Designer.cs +++ b/PSReadLine/PSReadLineResources.Designer.cs @@ -10,7 +10,7 @@ namespace Microsoft.PowerShell { using System; - + using System.Reflection; /// /// A strongly-typed resource class, for looking up localized strings, etc. @@ -39,7 +39,7 @@ internal PSReadLineResources() { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.PowerShell.PSReadLineResources", typeof(PSReadLineResources).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PSReadLine.PSReadLineResources", typeof(PSReadLineResources).GetTypeInfo().Assembly); resourceMan = temp; } return resourceMan; diff --git a/PSReadLine/ReadLine.cs b/PSReadLine/ReadLine.cs index d8e0c2657..54384e438 100644 --- a/PSReadLine/ReadLine.cs +++ b/PSReadLine/ReadLine.cs @@ -34,14 +34,20 @@ public partial class PSConsoleReadLine : IPSConsoleReadLineMockableMethods private IConsole _console; private EngineIntrinsics _engineIntrinsics; +#if !CORECLR private static GCHandle _breakHandlerGcHandle; +#endif private Thread _readKeyThread; private AutoResetEvent _readKeyWaitHandle; private AutoResetEvent _keyReadWaitHandle; private ManualResetEvent _closingWaitHandle; private WaitHandle[] _threadProcWaitHandles; private WaitHandle[] _requestKeyWaitHandles; +#if CORECLR + private bool _prePSReadlineControlCMode; +#else private uint _prePSReadlineConsoleMode; +#endif private readonly StringBuilder _buffer; private readonly StringBuilder _statusBuffer; @@ -252,12 +258,19 @@ private bool BreakHandler(ConsoleBreakSignal signal) public static string ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics) { var console = _singleton._console; +#if CORECLR + _singleton._prePSReadlineControlCMode = Console.TreatControlCAsInput; +#else _singleton._prePSReadlineConsoleMode = console.GetConsoleInputMode(); +#endif bool firstTime = true; while (true) { try { +#if CORECLR + Console.TreatControlCAsInput = true; +#else // Clear a couple flags so we can actually receive certain keys: // ENABLE_PROCESSED_INPUT - enables Ctrl+C // ENABLE_LINE_INPUT - enables Ctrl+S @@ -270,6 +283,7 @@ public static string ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsi NativeMethods.ENABLE_WINDOW_INPUT | NativeMethods.ENABLE_MOUSE_INPUT); console.SetConsoleInputMode(mode); +#endif if (firstTime) { @@ -340,7 +354,11 @@ public static string ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsi } finally { +#if CORECLR + Console.TreatControlCAsInput = _singleton._prePSReadlineControlCMode; +#else console.SetConsoleInputMode(_singleton._prePSReadlineConsoleMode); +#endif } } } @@ -428,6 +446,18 @@ private string InputLoop() T CalloutUsingDefaultConsoleMode(Func func) { +#if CORECLR + bool psReadlineControlCMode = Console.TreatControlCAsInput; + try + { + Console.TreatControlCAsInput = _prePSReadlineControlCMode; + return func(); + } + finally + { + Console.TreatControlCAsInput = psReadlineControlCMode; + } +#else uint psReadlineConsoleMode = _console.GetConsoleInputMode(); try { @@ -438,6 +468,7 @@ T CalloutUsingDefaultConsoleMode(Func func) { _console.SetConsoleInputMode(psReadlineConsoleMode); } +#endif } void CalloutUsingDefaultConsoleMode(Action action) @@ -448,6 +479,7 @@ void CalloutUsingDefaultConsoleMode(Action action) void ProcessOneKey(ConsoleKeyInfo key, Dictionary dispatchTable, bool ignoreIfNoAction, object arg) { KeyHandler handler; + if (!dispatchTable.TryGetValue(key, out handler)) { // If we see a control character where Ctrl wasn't used but shift was, treat that like @@ -549,6 +581,13 @@ private void Initialize(Runspace runspace, EngineIntrinsics engineIntrinsics) _statusIsErrorMessage = false; _consoleBuffer = ReadBufferLines(_initialY, 1 + Options.ExtraPromptLineCount); +#if CORECLR + string newPrompt = GetPrompt(); + for (int i=0; i(Options.MaximumHistoryCount); _currentHistoryIndex = 0; @@ -629,8 +672,10 @@ private void DelayedOneTimeInitialize() _killIndex = -1; // So first add indexes 0. _killRing = new List(Options.MaximumKillRingCount); +#if !CORECLR _breakHandlerGcHandle = GCHandle.Alloc(new BreakHandler(_singleton.BreakHandler)); NativeMethods.SetConsoleCtrlHandler((BreakHandler)_breakHandlerGcHandle.Target, true); +#endif _singleton._readKeyWaitHandle = new AutoResetEvent(false); _singleton._keyReadWaitHandle = new AutoResetEvent(false); _singleton._closingWaitHandle = new ManualResetEvent(false); @@ -641,6 +686,7 @@ private void DelayedOneTimeInitialize() // DomainUnload event is not raised for the default appdomain). It allows us // to exit cleanly when the appdomain is unloaded but the process is not going // away. +#if !CORECLR if (!AppDomain.CurrentDomain.IsDefaultAppDomain()) { AppDomain.CurrentDomain.DomainUnload += (x, y) => @@ -649,6 +695,7 @@ private void DelayedOneTimeInitialize() _singleton._readKeyThread.Join(); // may need to wait for history to be written }; } +#endif _singleton._readKeyThread = new Thread(_singleton.ReadKeyThreadProc) {IsBackground = true}; _singleton._readKeyThread.Start(); @@ -677,11 +724,13 @@ private static void Ignore(ConsoleKeyInfo? key = null, object arg = null) private static void ExecuteOnSTAThread(Action action) { +#if !CORECLR if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA) { action(); return; } +#endif Exception exception = null; var thread = new Thread(() => @@ -696,7 +745,9 @@ private static void ExecuteOnSTAThread(Action action) } }); +#if !CORECLR thread.SetApartmentState(ApartmentState.STA); +#endif thread.Start(); thread.Join(); @@ -834,6 +885,24 @@ public static void InvokePrompt(ConsoleKeyInfo? key = null, object arg = null) _singleton._console.CursorLeft = 0; _singleton._console.CursorTop = _singleton._initialY - _singleton.Options.ExtraPromptLineCount; + string newPrompt = GetPrompt(); + _singleton._console.Write(newPrompt); + + _singleton._initialX = _singleton._console.CursorLeft; + _singleton._consoleBuffer = ReadBufferLines(_singleton._initialY, 1 + _singleton.Options.ExtraPromptLineCount); +#if CORECLR + for (int i=0; i (_console.WindowTop + _console.WindowHeight)) { +#if !CORECLR _console.WindowTop = _initialY + bufferLineCount - _console.WindowHeight; +#endif } _lastRenderTime.Restart(); @@ -638,9 +644,12 @@ private int GetStatusLineCount() return (_statusLinePrompt.Length + _statusBuffer.Length) / _console.BufferWidth + 1; } +#if !CORECLR [ExcludeFromCodeCoverage] +#endif void IPSConsoleReadLineMockableMethods.Ding() { +#if !CORECLR switch (Options.BellStyle) { case BellStyle.None: @@ -652,6 +661,7 @@ void IPSConsoleReadLineMockableMethods.Ding() // TODO: flash prompt? command line? break; } +#endif } /// diff --git a/PSReadLine/ScreenCapture.cs b/PSReadLine/ScreenCapture.cs index 0ab20b752..be053566a 100644 --- a/PSReadLine/ScreenCapture.cs +++ b/PSReadLine/ScreenCapture.cs @@ -2,6 +2,7 @@ Copyright (c) Microsoft Corporation. All rights reserved. --********************************************************************/ +#if !CORECLR using System; using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; @@ -194,7 +195,7 @@ private static string GetColorTable() var handle = NativeMethods.GetStdHandle((uint) StandardHandleId.Output); var csbe = new NativeMethods.CONSOLE_SCREEN_BUFFER_INFO_EX { - cbSize = Marshal.SizeOf(typeof(NativeMethods.CONSOLE_SCREEN_BUFFER_INFO_EX)) + cbSize = Marshal.SizeOf() }; if (NativeMethods.GetConsoleScreenBufferInfoEx(handle, ref csbe)) { @@ -304,3 +305,4 @@ private static void DumpScreenToClipboard(int top, int count) } } } +#endif diff --git a/PSReadLine/VisualEditing.vi.cs b/PSReadLine/VisualEditing.vi.cs index 0aa51a339..a8e8573e7 100644 --- a/PSReadLine/VisualEditing.vi.cs +++ b/PSReadLine/VisualEditing.vi.cs @@ -96,6 +96,16 @@ private void ProcessViVisualEditing() private static string GetPreferredEditor() { string[] names = {"VISUAL", "EDITOR"}; +#if CORECLR + foreach (string name in names) + { + string editor = Environment.GetEnvironmentVariable(name); + if (!string.IsNullOrWhiteSpace(editor)) + { + return editor; + } + } +#else EnvironmentVariableTarget[] targets = { EnvironmentVariableTarget.Machine, EnvironmentVariableTarget.Process, @@ -112,7 +122,7 @@ private static string GetPreferredEditor() } } } - +#endif return null; } } From 23bf8ba96103d027396273f31372975c653c858d Mon Sep 17 00:00:00 2001 From: George Fleming Date: Thu, 14 Apr 2016 16:26:03 -0700 Subject: [PATCH 03/58] Enable setting of new key bindings --- PSReadLine/Cmdlets.cs | 1 - PSReadLine/ConsoleKeyChordConverter.cs | 22 ++++++++++++++++++++-- PSReadLine/ReadLine.cs | 1 + 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/PSReadLine/Cmdlets.cs b/PSReadLine/Cmdlets.cs index 6055b079f..1d5ae638e 100644 --- a/PSReadLine/Cmdlets.cs +++ b/PSReadLine/Cmdlets.cs @@ -690,7 +690,6 @@ protected override void EndProcessing() MethodInfo mi = typeof (PSConsoleReadLine).GetMethod(function); var keyHandler = (Action) mi.CreateDelegate(typeof (Action)); - #else var keyHandler = (Action) Delegate.CreateDelegate(typeof (Action), diff --git a/PSReadLine/ConsoleKeyChordConverter.cs b/PSReadLine/ConsoleKeyChordConverter.cs index 1cd308266..7ab95732b 100644 --- a/PSReadLine/ConsoleKeyChordConverter.cs +++ b/PSReadLine/ConsoleKeyChordConverter.cs @@ -6,6 +6,9 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; +#if CORECLR +using System.Reflection; +#endif using System.Runtime.InteropServices; using Microsoft.PowerShell.Internal; @@ -211,7 +214,22 @@ internal static char GetCharFromConsoleKey(ConsoleKey key, ConsoleModifiers modi { // default for unprintables and unhandled char keyChar = '\u0000'; - +#if CORECLR + Type keyType = typeof (Keys); + FieldInfo[] keyFields = keyType.GetFields(); + + foreach (FieldInfo field in keyFields) + { + if (field.FieldType == typeof(ConsoleKeyInfo)) + { + ConsoleKeyInfo info = (ConsoleKeyInfo)field.GetValue(null); + if (info.Key == key && info.Modifiers == modifiers) + { + return info.KeyChar; + } + } + } +#else // emulate GetKeyboardState bitmap - set high order bit for relevant modifier virtual keys var state = new byte[256]; state[NativeMethods.VK_SHIFT] = (byte)(((modifiers & ConsoleModifiers.Shift) != 0) ? 0x80 : 0); @@ -234,7 +252,7 @@ internal static char GetCharFromConsoleKey(ConsoleKey key, ConsoleModifiers modi { keyChar = chars[0]; } - +#endif return keyChar; } } diff --git a/PSReadLine/ReadLine.cs b/PSReadLine/ReadLine.cs index 54384e438..58a9591db 100644 --- a/PSReadLine/ReadLine.cs +++ b/PSReadLine/ReadLine.cs @@ -490,6 +490,7 @@ void ProcessOneKey(ConsoleKeyInfo key, Dictionary di dispatchTable.TryGetValue(key, out handler); } } + if (handler != null) { if (handler.ScriptBlock != null) From 50b63f4ea27b5f568856de39948e252de27532ef Mon Sep 17 00:00:00 2001 From: George Fleming Date: Fri, 22 Apr 2016 13:49:23 -0700 Subject: [PATCH 04/58] Enable colors --- PSReadLine/ConsoleLib.cs | 43 +++++++++++++++------------------------- PSReadLine/Render.cs | 6 +++++- 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/PSReadLine/ConsoleLib.cs b/PSReadLine/ConsoleLib.cs index 7656a83a9..27bbd374f 100644 --- a/PSReadLine/ConsoleLib.cs +++ b/PSReadLine/ConsoleLib.cs @@ -315,6 +315,18 @@ internal struct CONSOLE_FONT_INFO_EX public struct CHAR_INFO { +#if CORECLR + public char UnicodeChar; + public ConsoleColor ForegroundColor; + public ConsoleColor BackgroundColor; + + public CHAR_INFO(char c, ConsoleColor foreground, ConsoleColor background) + { + UnicodeChar = c; + ForegroundColor = foreground; + BackgroundColor = background; + } +#else public ushort UnicodeChar; public ushort Attributes; @@ -324,27 +336,21 @@ public CHAR_INFO(char c, ConsoleColor foreground, ConsoleColor background) Attributes = (ushort)(((int)background << 4) | (int)foreground); } -#if !CORECLR [ExcludeFromCodeCoverage] -#endif public ConsoleColor ForegroundColor { get { return (ConsoleColor)(Attributes & 0xf); } set { Attributes = (ushort)((Attributes & 0xfff0) | ((int)value & 0xf)); } } -#if !CORECLR [ExcludeFromCodeCoverage] -#endif public ConsoleColor BackgroundColor { get { return (ConsoleColor)((Attributes & 0xf0) >> 4); } set { Attributes = (ushort)((Attributes & 0xff0f) | (((int)value & 0xf) << 4)); } } -#if !CORECLR [ExcludeFromCodeCoverage] -#endif public override string ToString() { var sb = new StringBuilder(); @@ -356,9 +362,7 @@ public override string ToString() return sb.ToString(); } -#if !CORECLR [ExcludeFromCodeCoverage] -#endif public override bool Equals(object obj) { if (!(obj is CHAR_INFO)) @@ -370,14 +374,12 @@ public override bool Equals(object obj) return this.UnicodeChar == other.UnicodeChar && this.Attributes == other.Attributes; } -#if !CORECLR [ExcludeFromCodeCoverage] -#endif public override int GetHashCode() { return UnicodeChar.GetHashCode() + Attributes.GetHashCode(); } - +#endif } internal static class ConsoleKeyInfoExtension @@ -626,20 +628,9 @@ public void WriteBufferLines(CHAR_INFO[] buffer, ref int top, bool ensureBottomL for (int i = 0; i < buffer.Length; ++i) { - /* For some reasons, the default color comes out white on white */ - /* - if (buffer[i].ForegroundColor == ConsoleColor.White - && buffer[i].BackgroundColor == ConsoleColor.White) - { - Console.ForegroundColor = foregroundColor; - Console.BackgroundColor = backgroundColor; - } - else - { - Console.ForegroundColor = buffer[i].ForegroundColor; - Console.BackgroundColor = backgroundColor; - } - */ + Console.ForegroundColor = buffer[i].ForegroundColor; + Console.BackgroundColor = buffer[i].BackgroundColor; + Console.Write((char)buffer[i].UnicodeChar); } @@ -675,8 +666,6 @@ public void WriteBufferLines(CHAR_INFO[] buffer, ref int top, bool ensureBottomL public void ScrollBuffer(int lines) { #if CORECLR -// Console.MoveBufferArea(lines, 0, Console.BufferWidth, Console.BufferHeight - lines, 0, 0, ' ', -// Console.ForegroundColor, Console.BackgroundColor); for (int i=0; i 1) { _consoleBuffer[j].UnicodeChar = charToRender; +#if !CORECLR _consoleBuffer[j].Attributes = (ushort)(_consoleBuffer[j].Attributes | (uint)CHAR_INFO_Attributes.COMMON_LVB_LEADING_BYTE); +#endif MaybeEmphasize(ref _consoleBuffer[j++], i, foregroundColor, backgroundColor); _consoleBuffer[j].UnicodeChar = charToRender; +#if !CORECLR _consoleBuffer[j].Attributes = (ushort)(_consoleBuffer[j].Attributes | (uint)CHAR_INFO_Attributes.COMMON_LVB_TRAILING_BYTE); +#endif MaybeEmphasize(ref _consoleBuffer[j++], i, foregroundColor, backgroundColor); } else From ac2f87a5aa3f2dc68b5b574809ebaac5b32d3191 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 27 Apr 2016 12:30:35 -0700 Subject: [PATCH 05/58] Fix resource manager Since the project is `Microsoft.PowerShell.PSReadLine`, the embedded resource name had to be fixed. --- PSReadLine/PSReadLineResources.Designer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PSReadLine/PSReadLineResources.Designer.cs b/PSReadLine/PSReadLineResources.Designer.cs index ee9503221..3308edd22 100644 --- a/PSReadLine/PSReadLineResources.Designer.cs +++ b/PSReadLine/PSReadLineResources.Designer.cs @@ -39,7 +39,7 @@ internal PSReadLineResources() { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PSReadLine.PSReadLineResources", typeof(PSReadLineResources).GetTypeInfo().Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.PowerShell.PSReadLine.PSReadLineResources", typeof(PSReadLineResources).GetTypeInfo().Assembly); resourceMan = temp; } return resourceMan; From 31708c9f0484eb10519112cc0620b53ac64f14c4 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 28 Apr 2016 17:17:37 -0700 Subject: [PATCH 06/58] Fix comparison of keys in dispatch dictionary This compares the keys by a combination of their ConsoleKey and Modifiers fields. We cannot compare the KeyChar field as it is platform (and TTY configuration) dependent. --- PSReadLine/KeyBindings.cs | 13 +++++++++++-- PSReadLine/Keys.cs | 18 +----------------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/PSReadLine/KeyBindings.cs b/PSReadLine/KeyBindings.cs index 5216933c0..8fff50948 100644 --- a/PSReadLine/KeyBindings.cs +++ b/PSReadLine/KeyBindings.cs @@ -82,12 +82,21 @@ internal class ConsoleKeyInfoComparer : IEqualityComparer { public bool Equals(ConsoleKeyInfo x, ConsoleKeyInfo y) { - return x.Key == y.Key && x.KeyChar == y.KeyChar && x.Modifiers == y.Modifiers; + // We *must not* compare the KeyChar field as its value is platform-dependent. + // We compare exactly the ConsoleKey enum field (which is platform-agnostic) + // and the modifiers. + + return x.Key == y.Key && x.Modifiers == y.Modifiers; } public int GetHashCode(ConsoleKeyInfo obj) { - return obj.GetHashCode(); + // Because a comparison of two ConsoleKeyInfo objects is a comparison of the + // combination of the ConsoleKey and Modifiers, we must combine their hashes. + // This is based on Tuple.GetHashCode + int h1 = obj.Key.GetHashCode(); + int h2 = obj.Modifiers.GetHashCode(); + return unchecked(((h1 << 5) + h1) ^ h2); } } diff --git a/PSReadLine/Keys.cs b/PSReadLine/Keys.cs index dbd138991..5cf1975d6 100644 --- a/PSReadLine/Keys.cs +++ b/PSReadLine/Keys.cs @@ -11,22 +11,6 @@ namespace Microsoft.PowerShell { internal static class Keys { - static Keys() - { -#if CORECLR - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - Enter = new ConsoleKeyInfo((char)10, ConsoleKey.Enter, false, false, false); - } - else - { - Enter = new ConsoleKeyInfo((char)13, ConsoleKey.Enter, false, false, false); - } -#else - Enter = new ConsoleKeyInfo((char)13, ConsoleKey.Enter, false, false, false); -#endif - } - public static ConsoleKeyInfo A = new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false); public static ConsoleKeyInfo B = new ConsoleKeyInfo('b', ConsoleKey.B, false, false, false); public static ConsoleKeyInfo C = new ConsoleKeyInfo('c', ConsoleKey.C, false, false, false); @@ -224,7 +208,7 @@ static Keys() public static ConsoleKeyInfo End = new ConsoleKeyInfo((char)0, ConsoleKey.End, false, false, false); public static ConsoleKeyInfo CtrlEnd = new ConsoleKeyInfo((char)0, ConsoleKey.End, false, false, true); public static ConsoleKeyInfo ShiftEnd = new ConsoleKeyInfo((char)0, ConsoleKey.End, true, false, false); - public static ConsoleKeyInfo Enter; + public static ConsoleKeyInfo Enter = new ConsoleKeyInfo((char)13, ConsoleKey.Enter, false, false, false); public static ConsoleKeyInfo Escape = new ConsoleKeyInfo((char)27, ConsoleKey.Escape, false, false, false); public static ConsoleKeyInfo Home = new ConsoleKeyInfo((char)0, ConsoleKey.Home, false, false, false); public static ConsoleKeyInfo CtrlHome = new ConsoleKeyInfo((char)0, ConsoleKey.Home, false, false, true); From 8866e33d6703fe1c35960929ee15112d08f43155 Mon Sep 17 00:00:00 2001 From: George Fleming Date: Thu, 28 Apr 2016 11:43:14 -0700 Subject: [PATCH 07/58] Change default colors, and show highlighted text properly --- PSReadLine/Cmdlets.cs | 16 +++++++++++++++- PSReadLine/Render.cs | 6 ++++++ PSReadLine/ScreenCapture.cs | 8 ++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/PSReadLine/Cmdlets.cs b/PSReadLine/Cmdlets.cs index 1d5ae638e..56fece165 100644 --- a/PSReadLine/Cmdlets.cs +++ b/PSReadLine/Cmdlets.cs @@ -72,6 +72,20 @@ public enum HistorySaveStyle public class PSConsoleReadlineOptions { +#if CORECLR + public const ConsoleColor DefaultCommentForegroundColor = ConsoleColor.Magenta; + public const ConsoleColor DefaultKeywordForegroundColor = ConsoleColor.Green; + public const ConsoleColor DefaultStringForegroundColor = ConsoleColor.DarkCyan; + public const ConsoleColor DefaultOperatorForegroundColor = ConsoleColor.Gray; + public const ConsoleColor DefaultVariableForegroundColor = ConsoleColor.Green; + public const ConsoleColor DefaultCommandForegroundColor = ConsoleColor.Yellow; + public const ConsoleColor DefaultParameterForegroundColor = ConsoleColor.Green; + public const ConsoleColor DefaultTypeForegroundColor = ConsoleColor.Gray; + public const ConsoleColor DefaultNumberForegroundColor = ConsoleColor.White; + public const ConsoleColor DefaultMemberForegroundColor = ConsoleColor.Gray; + public const ConsoleColor DefaultEmphasisForegroundColor = ConsoleColor.Cyan; + public const ConsoleColor DefaultErrorForegroundColor = ConsoleColor.Red; +#else public const ConsoleColor DefaultCommentForegroundColor = ConsoleColor.DarkGreen; public const ConsoleColor DefaultKeywordForegroundColor = ConsoleColor.Green; public const ConsoleColor DefaultStringForegroundColor = ConsoleColor.DarkCyan; @@ -84,7 +98,7 @@ public class PSConsoleReadlineOptions public const ConsoleColor DefaultMemberForegroundColor = ConsoleColor.Gray; public const ConsoleColor DefaultEmphasisForegroundColor = ConsoleColor.Cyan; public const ConsoleColor DefaultErrorForegroundColor = ConsoleColor.Red; - +#endif public const EditMode DefaultEditMode = EditMode.Windows; diff --git a/PSReadLine/Render.cs b/PSReadLine/Render.cs index 73be58128..fb7cec807 100644 --- a/PSReadLine/Render.cs +++ b/PSReadLine/Render.cs @@ -472,8 +472,14 @@ private void MaybeEmphasize(ref CHAR_INFO charInfo, int i, ConsoleColor foregrou // to invert only the lower 3 bits to change the color is somewhat // but looks best with the 2 default color schemes - starting PowerShell // from it's shortcut or from a cmd shortcut. +#if CORECLR + ConsoleColor tempColor = ((int)foregroundColor == -1) ? ConsoleColor.White : foregroundColor; + foregroundColor = ((int)backgroundColor == -1) ? ConsoleColor.Black : backgroundColor; + backgroundColor = tempColor; +#else foregroundColor = (ConsoleColor)((int)foregroundColor ^ 7); backgroundColor = (ConsoleColor)((int)backgroundColor ^ 7); +#endif } charInfo.ForegroundColor = foregroundColor; diff --git a/PSReadLine/ScreenCapture.cs b/PSReadLine/ScreenCapture.cs index be053566a..2659fec97 100644 --- a/PSReadLine/ScreenCapture.cs +++ b/PSReadLine/ScreenCapture.cs @@ -19,8 +19,16 @@ private static void InvertLines(int start, int count) var buffer = ReadBufferLines(start, count); for (int i = 0; i < buffer.Length; i++) { +#if CORECLR + ConsoleColor tempColor = (int)buffer[i].ForegroundColor == -1 + ? ConsoleColor.White : buffer[i].ForegroundColor; + buffer[i].ForegroundColor = (int)buffer[i].BackgroundColor == -1 + ? ConsoleColor.Black : buffer[i].BackgroundColor; + buffer[i].BackgroundColor = tempColor; +#else buffer[i].ForegroundColor = (ConsoleColor)((int)buffer[i].ForegroundColor ^ 7); buffer[i].BackgroundColor = (ConsoleColor)((int)buffer[i].BackgroundColor ^ 7); +#endif } _singleton._console.WriteBufferLines(buffer, ref start, false); } From 2975fb7ef5a3151b7516767a5fbf1ff3126954a8 Mon Sep 17 00:00:00 2001 From: George Fleming Date: Thu, 28 Apr 2016 11:44:09 -0700 Subject: [PATCH 08/58] Fix Undo/Redo --- PSReadLine/UndoRedo.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PSReadLine/UndoRedo.cs b/PSReadLine/UndoRedo.cs index 128e6548e..f54a96a87 100644 --- a/PSReadLine/UndoRedo.cs +++ b/PSReadLine/UndoRedo.cs @@ -76,7 +76,8 @@ public static void Undo(ConsoleKeyInfo? key = null, object arg = null) _singleton.ClearStatusMessage(render: false); } _singleton._edits[_singleton._undoEditIndex - 1].Undo(); - _singleton._edits.RemoveAt(_singleton._undoEditIndex - 1); + // How do you redo if you remove it permanently? +// _singleton._edits.RemoveAt(_singleton._undoEditIndex - 1); _singleton._undoEditIndex--; if (_singleton._options.EditMode == EditMode.Vi && _singleton._current >= _singleton._buffer.Length) { From 145e766925f850c6b65fa8dbcd869a7c530bd0c4 Mon Sep 17 00:00:00 2001 From: George Fleming Date: Thu, 28 Apr 2016 16:05:00 -0700 Subject: [PATCH 09/58] Fix ClearScreen, and disable scroll-related functions that don't work in CoreCLR --- PSReadLine/ConsoleLib.cs | 7 +++++++ PSReadLine/KeyBindings.cs | 4 +++- PSReadLine/Movement.cs | 6 ++++++ PSReadLine/PublicAPI.cs | 3 +++ PSReadLine/Render.cs | 2 ++ 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/PSReadLine/ConsoleLib.cs b/PSReadLine/ConsoleLib.cs index 27bbd374f..deadf12e3 100644 --- a/PSReadLine/ConsoleLib.cs +++ b/PSReadLine/ConsoleLib.cs @@ -908,6 +908,13 @@ public void EndRender() NativeMethods.ReleaseDC(_hwnd, _hDC); } } + +#if CORECLR + public void Clear() + { + Console.Clear(); + } +#endif } #pragma warning restore 1591 diff --git a/PSReadLine/KeyBindings.cs b/PSReadLine/KeyBindings.cs index 8fff50948..207f5cae1 100644 --- a/PSReadLine/KeyBindings.cs +++ b/PSReadLine/KeyBindings.cs @@ -181,10 +181,12 @@ void SetDefaultWindowsBindings() { Keys.ShiftF3, MakeKeyHandler(CharacterSearchBackward, "CharacterSearchBackward") }, { Keys.F8, MakeKeyHandler(HistorySearchBackward, "HistorySearchBackward") }, { Keys.ShiftF8, MakeKeyHandler(HistorySearchForward, "HistorySearchForward") }, +#if !CORECLR { Keys.PageUp, MakeKeyHandler(ScrollDisplayUp, "ScrollDisplayUp") }, { Keys.PageDown, MakeKeyHandler(ScrollDisplayDown, "ScrollDisplayDown") }, { Keys.CtrlPageUp, MakeKeyHandler(ScrollDisplayUpLine, "ScrollDisplayUpLine") }, { Keys.CtrlPageDown, MakeKeyHandler(ScrollDisplayDownLine, "ScrollDisplayDownLine") }, +#endif }; _chordDispatchTable = new Dictionary>(); @@ -267,13 +269,13 @@ void SetDefaultEmacsBindings() { Keys.VolumeDown, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeUp, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeMute, MakeKeyHandler(Ignore, "Ignore") }, -#endif { Keys.PageUp, MakeKeyHandler(ScrollDisplayUp, "ScrollDisplayUp") }, { Keys.CtrlPageUp, MakeKeyHandler(ScrollDisplayUpLine, "ScrollDisplayUpLine") }, { Keys.PageDown, MakeKeyHandler(ScrollDisplayDown, "ScrollDisplayDown") }, { Keys.CtrlPageDown, MakeKeyHandler(ScrollDisplayDownLine,"ScrollDisplayDownLine") }, { Keys.CtrlHome, MakeKeyHandler(ScrollDisplayTop, "ScrollDisplayTop") }, { Keys.CtrlEnd, MakeKeyHandler(ScrollDisplayToCursor,"ScrollDisplayToCursor") }, +#endif }; _chordDispatchTable = new Dictionary>(); diff --git a/PSReadLine/Movement.cs b/PSReadLine/Movement.cs index f7d7b74ad..610ee0462 100644 --- a/PSReadLine/Movement.cs +++ b/PSReadLine/Movement.cs @@ -434,6 +434,11 @@ public static void GotoBrace(ConsoleKeyInfo? key = null, object arg = null) public static void ClearScreen(ConsoleKeyInfo? key = null, object arg = null) { var console = _singleton._console; +#if CORECLR + console.Clear(); + _singleton._initialY = 0; + _singleton.Render(); +#else if (_singleton._initialY + console.WindowHeight > console.BufferHeight) { var scrollCount = _singleton._initialY - console.WindowTop; @@ -445,6 +450,7 @@ public static void ClearScreen(ConsoleKeyInfo? key = null, object arg = null) { console.SetWindowPosition(0, _singleton._initialY); } +#endif } // Try to convert the arg to a char, return 0 for failure diff --git a/PSReadLine/PublicAPI.cs b/PSReadLine/PublicAPI.cs index f245ec49a..8f38d5bf1 100644 --- a/PSReadLine/PublicAPI.cs +++ b/PSReadLine/PublicAPI.cs @@ -54,6 +54,9 @@ public interface IConsole void StartRender(); int LengthInBufferCells(char c); void EndRender(); +#if CORECLR + void Clear(); +#endif } #pragma warning restore 1591 diff --git a/PSReadLine/Render.cs b/PSReadLine/Render.cs index fb7cec807..6dd631ee2 100644 --- a/PSReadLine/Render.cs +++ b/PSReadLine/Render.cs @@ -696,6 +696,7 @@ private bool PromptYesOrNo(string s) #region Screen scrolling +#if !CORECLR /// /// Scroll the display up one screen. /// @@ -814,6 +815,7 @@ public static void ScrollDisplayToCursor(ConsoleKeyInfo? key = null, object arg console.SetWindowPosition(0, newTop); } +#endif #endregion Screen scrolling } } From 15b54d8378aab1228b26aff6f054c560ff435889 Mon Sep 17 00:00:00 2001 From: George Fleming Date: Fri, 29 Apr 2016 13:23:34 -0700 Subject: [PATCH 10/58] Merge with Andy's changes --- PSReadLine/Keys.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/PSReadLine/Keys.cs b/PSReadLine/Keys.cs index 5cf1975d6..07166088d 100644 --- a/PSReadLine/Keys.cs +++ b/PSReadLine/Keys.cs @@ -3,9 +3,6 @@ --********************************************************************/ using System; -#if CORECLR -using System.Runtime.InteropServices; -#endif namespace Microsoft.PowerShell { From fe8ed617a03878a3bd27f35f46ae25b065ddafcc Mon Sep 17 00:00:00 2001 From: George Fleming Date: Fri, 29 Apr 2016 08:34:32 -0700 Subject: [PATCH 11/58] Change from check for Linux to not Windows --- PSReadLine/Keys.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/PSReadLine/Keys.cs b/PSReadLine/Keys.cs index 07166088d..a1bbaca27 100644 --- a/PSReadLine/Keys.cs +++ b/PSReadLine/Keys.cs @@ -105,7 +105,6 @@ internal static class Keys public static ConsoleKeyInfo Minus = new ConsoleKeyInfo('-', ConsoleKey.OemMinus, false, false, false); public static ConsoleKeyInfo AltMinus = new ConsoleKeyInfo('-', ConsoleKey.OemMinus, false, true, false); public static ConsoleKeyInfo Plus = new ConsoleKeyInfo('+', ConsoleKey.OemPlus, true, false, false); - new public static ConsoleKeyInfo Equals = new ConsoleKeyInfo('=', ConsoleKey.OemPlus, false, false, false); public static ConsoleKeyInfo CtrlAt = new ConsoleKeyInfo((char)0, ConsoleKey.D2, true, false, true); From 04b7411b011f3a4a1542bc4ba866da1db808acfb Mon Sep 17 00:00:00 2001 From: George Fleming Date: Fri, 29 Apr 2016 08:35:16 -0700 Subject: [PATCH 12/58] Include System.Windows.Forms only if not CORECLR --- PSReadLine/KillYank.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/PSReadLine/KillYank.cs b/PSReadLine/KillYank.cs index ba94cbdbd..651364c78 100644 --- a/PSReadLine/KillYank.cs +++ b/PSReadLine/KillYank.cs @@ -6,7 +6,9 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Management.Automation.Language; -//using System.Windows.Forms; +#if !CORECLR +using System.Windows.Forms; +#endif namespace Microsoft.PowerShell { From 09b1ec8984507e504bf14409120c75835068f481 Mon Sep 17 00:00:00 2001 From: George Fleming Date: Fri, 29 Apr 2016 08:37:58 -0700 Subject: [PATCH 13/58] Change default history file location --- PSReadLine/Cmdlets.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PSReadLine/Cmdlets.cs b/PSReadLine/Cmdlets.cs index 56fece165..3210a8965 100644 --- a/PSReadLine/Cmdlets.cs +++ b/PSReadLine/Cmdlets.cs @@ -180,7 +180,8 @@ public PSConsoleReadlineOptions(string hostName) { HistorySavePath = System.IO.Path.Combine( Environment.GetEnvironmentVariable("HOME"), - ".psreadline", + ".powershell", + "PSReadLine", hostName + "_history.txt"); } #else From 6612e53c4d61f2bf8417931bd7ccab19fb7a0dbf Mon Sep 17 00:00:00 2001 From: George Fleming Date: Fri, 29 Apr 2016 13:34:26 -0700 Subject: [PATCH 14/58] Remove commented out line --- PSReadLine/UndoRedo.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/PSReadLine/UndoRedo.cs b/PSReadLine/UndoRedo.cs index f54a96a87..b451231e1 100644 --- a/PSReadLine/UndoRedo.cs +++ b/PSReadLine/UndoRedo.cs @@ -76,8 +76,6 @@ public static void Undo(ConsoleKeyInfo? key = null, object arg = null) _singleton.ClearStatusMessage(render: false); } _singleton._edits[_singleton._undoEditIndex - 1].Undo(); - // How do you redo if you remove it permanently? -// _singleton._edits.RemoveAt(_singleton._undoEditIndex - 1); _singleton._undoEditIndex--; if (_singleton._options.EditMode == EditMode.Vi && _singleton._current >= _singleton._buffer.Length) { From 9625e7133ebe57c971505817362ea6e687628806 Mon Sep 17 00:00:00 2001 From: George Fleming Date: Fri, 29 Apr 2016 13:40:36 -0700 Subject: [PATCH 15/58] Undo accidental removal of new keyword --- PSReadLine/Keys.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/PSReadLine/Keys.cs b/PSReadLine/Keys.cs index a1bbaca27..07166088d 100644 --- a/PSReadLine/Keys.cs +++ b/PSReadLine/Keys.cs @@ -105,6 +105,7 @@ internal static class Keys public static ConsoleKeyInfo Minus = new ConsoleKeyInfo('-', ConsoleKey.OemMinus, false, false, false); public static ConsoleKeyInfo AltMinus = new ConsoleKeyInfo('-', ConsoleKey.OemMinus, false, true, false); public static ConsoleKeyInfo Plus = new ConsoleKeyInfo('+', ConsoleKey.OemPlus, true, false, false); + new public static ConsoleKeyInfo Equals = new ConsoleKeyInfo('=', ConsoleKey.OemPlus, false, false, false); public static ConsoleKeyInfo CtrlAt = new ConsoleKeyInfo((char)0, ConsoleKey.D2, true, false, true); From e8887343289215b37e7e63e90950610b08fa94b6 Mon Sep 17 00:00:00 2001 From: George Fleming Date: Fri, 29 Apr 2016 14:56:16 -0700 Subject: [PATCH 16/58] Fix MenuComplete --- PSReadLine/Completion.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/PSReadLine/Completion.cs b/PSReadLine/Completion.cs index b2d801f7f..c477356f0 100644 --- a/PSReadLine/Completion.cs +++ b/PSReadLine/Completion.cs @@ -303,8 +303,16 @@ private static void InvertSelectedCompletion(CHAR_INFO[] buffer, int selectedIte for (int i = 0; i < menuColumnWidth; i++) { int j = i + start; +#if CORECLR + ConsoleColor tempColor = (int)buffer[j].ForegroundColor == -1 + ? ConsoleColor.White : buffer[j].ForegroundColor; + buffer[j].ForegroundColor = (int)buffer[j].BackgroundColor == -1 + ? ConsoleColor.Black : buffer[j].BackgroundColor; + buffer[j].BackgroundColor = tempColor; +#else buffer[j].ForegroundColor = (ConsoleColor)((int)buffer[j].ForegroundColor ^ 7); buffer[j].BackgroundColor = (ConsoleColor)((int)buffer[j].BackgroundColor ^ 7); +#endif } } From 613c4f2ad389e850e9f490c3d3769ca7b87be622 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Sat, 30 Apr 2016 15:39:07 -0700 Subject: [PATCH 17/58] Fix directory completion for different file-systems Use the file-system agnostic `System.IO.Path.DirectorySeparatorChar` for `GetReplacementTextForDirectory`, instead of hard-coded backslashes. --- PSReadLine/Completion.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/PSReadLine/Completion.cs b/PSReadLine/Completion.cs index c477356f0..9dd13a6a6 100644 --- a/PSReadLine/Completion.cs +++ b/PSReadLine/Completion.cs @@ -23,6 +23,9 @@ public partial class PSConsoleReadLine private CommandCompletion _tabCompletions; private Runspace _runspace; + // String helper for directory paths + private static string DirectorySeparatorString = System.IO.Path.DirectorySeparatorChar.ToString(); + // Stub helper method so completion can be mocked #if !CORECLR [ExcludeFromCodeCoverage] @@ -275,21 +278,23 @@ private void DoReplacementForCompletion(CompletionResult completionResult, Comma private static string GetReplacementTextForDirectory(string replacementText, ref int cursorAdjustment) { - if (!replacementText.EndsWith("\\", StringComparison.Ordinal)) + if (!replacementText.EndsWith(DirectorySeparatorString , StringComparison.Ordinal)) { - if (replacementText.EndsWith("\\'", StringComparison.Ordinal) || replacementText.EndsWith("\\\"", StringComparison.Ordinal)) + if (replacementText.EndsWith(String.Format("{0}\'", DirectorySeparatorString), StringComparison.Ordinal) || + replacementText.EndsWith(String.Format("{0}\"", DirectorySeparatorString), StringComparison.Ordinal)) { cursorAdjustment = -1; } - else if (replacementText.EndsWith("'", StringComparison.Ordinal) || replacementText.EndsWith("\"", StringComparison.Ordinal)) + else if (replacementText.EndsWith("'", StringComparison.Ordinal) || + replacementText.EndsWith("\"", StringComparison.Ordinal)) { var len = replacementText.Length; - replacementText = replacementText.Substring(0, len - 1) + '\\' + replacementText[len - 1]; + replacementText = replacementText.Substring(0, len - 1) + System.IO.Path.DirectorySeparatorChar + replacementText[len - 1]; cursorAdjustment = -1; } else { - replacementText = replacementText + '\\'; + replacementText = replacementText + System.IO.Path.DirectorySeparatorChar; } } return replacementText; From 2e1a7d065e6b87f9ff8e08be2e8285cca35bb6e9 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 2 May 2016 12:56:31 -0700 Subject: [PATCH 18/58] Build PSReadLine for ConsoleHost --- PSReadLine/project.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PSReadLine/project.json b/PSReadLine/project.json index 809c0b397..7734ad2ed 100644 --- a/PSReadLine/project.json +++ b/PSReadLine/project.json @@ -17,6 +17,8 @@ "define": [ "CORECLR" ] }, "imports": [ "dnxcore50", "portable-net45+win8" ] + }, + "net451": { } } } From e20332f1e387cea0965c4260a93c8b80268d5fc0 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 5 May 2016 14:28:33 -0700 Subject: [PATCH 19/58] Fix PSReadLine for net451 build Needed System.Windows.Forms --- PSReadLine/project.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/PSReadLine/project.json b/PSReadLine/project.json index 7734ad2ed..172b9ae40 100644 --- a/PSReadLine/project.json +++ b/PSReadLine/project.json @@ -19,6 +19,11 @@ "imports": [ "dnxcore50", "portable-net45+win8" ] }, "net451": { + "frameworkAssemblies": { + "System.Windows.Forms": { + "type": "build" + } + } } } } From eacb73237f6c5f1696ed00618b4e4a47e65d2953 Mon Sep 17 00:00:00 2001 From: v-alexjo Date: Tue, 24 May 2016 14:29:00 -0700 Subject: [PATCH 20/58] Initial XDG support and folder default changes Conflicts: src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs --- PSReadLine/Cmdlets.cs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/PSReadLine/Cmdlets.cs b/PSReadLine/Cmdlets.cs index 3210a8965..fb9145314 100644 --- a/PSReadLine/Cmdlets.cs +++ b/PSReadLine/Cmdlets.cs @@ -178,14 +178,25 @@ public PSConsoleReadlineOptions(string hostName) } else { + //PSReadline does not have access to Utils.CorePSPlatform. Must set PSReadline path seperately + string modulepath = System.Environment.GetEnvironmentVariable("XDG_CACHE_HOME"); + + if (String.IsNullOrEmpty(modulepath)) + { + modulepath = System.IO.Path.Combine( + Environment.GetEnvironmentVariable("HOME"), + ".config/powershell/modules"); + } + HistorySavePath = System.IO.Path.Combine( Environment.GetEnvironmentVariable("HOME"), - ".powershell", + modulepath, "PSReadLine", hostName + "_history.txt"); - } -#else - HistorySavePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + + } + #else + HistorySavePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Microsoft\Windows\PowerShell\PSReadline\" + hostName + "_history.txt"; #endif CommandValidationHandler = null; @@ -205,7 +216,7 @@ public PSConsoleReadlineOptions(string hostName) "Where-Object", "?", "where", }; } - + public EditMode EditMode { get; set; } public string ContinuationPrompt { get; set; } From 4a41d63f95ea8347eb544e2a4be35de97e0029c6 Mon Sep 17 00:00:00 2001 From: v-alexjo Date: Wed, 1 Jun 2016 11:03:05 -0700 Subject: [PATCH 21/58] Code review changes to XDG support --- PSReadLine/Cmdlets.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/PSReadLine/Cmdlets.cs b/PSReadLine/Cmdlets.cs index fb9145314..ff6eb9dd0 100644 --- a/PSReadLine/Cmdlets.cs +++ b/PSReadLine/Cmdlets.cs @@ -176,6 +176,7 @@ public PSConsoleReadlineOptions(string hostName) @"\Microsoft\Windows\PowerShell\PSReadline\", hostName + "_history.txt"); } + else { //PSReadline does not have access to Utils.CorePSPlatform. Must set PSReadline path seperately @@ -186,13 +187,20 @@ public PSConsoleReadlineOptions(string hostName) modulepath = System.IO.Path.Combine( Environment.GetEnvironmentVariable("HOME"), ".config/powershell/modules"); - } - HistorySavePath = System.IO.Path.Combine( + HistorySavePath = System.IO.Path.Combine( Environment.GetEnvironmentVariable("HOME"), modulepath, "PSReadLine", hostName + "_history.txt"); + } + + else { + + HistorySavePath = modulepath; + + } + } #else From 1adf27ac29a6e8cfa396ca117009942fe715e67d Mon Sep 17 00:00:00 2001 From: v-alexjo Date: Thu, 2 Jun 2016 10:14:51 -0700 Subject: [PATCH 22/58] Changes to xdg to append powershell path --- PSReadLine/Cmdlets.cs | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/PSReadLine/Cmdlets.cs b/PSReadLine/Cmdlets.cs index ff6eb9dd0..f32595182 100644 --- a/PSReadLine/Cmdlets.cs +++ b/PSReadLine/Cmdlets.cs @@ -181,29 +181,27 @@ public PSConsoleReadlineOptions(string hostName) { //PSReadline does not have access to Utils.CorePSPlatform. Must set PSReadline path seperately string modulepath = System.Environment.GetEnvironmentVariable("XDG_CACHE_HOME"); - - if (String.IsNullOrEmpty(modulepath)) - { - modulepath = System.IO.Path.Combine( - Environment.GetEnvironmentVariable("HOME"), - ".config/powershell/modules"); - - HistorySavePath = System.IO.Path.Combine( - Environment.GetEnvironmentVariable("HOME"), - modulepath, - "PSReadLine", - hostName + "_history.txt"); - } - - else { + if (!String.IsNullOrEmpty(modulepath)) + { + modulepath = System.IO.Path.Combine(modulepath, "powershell"); HistorySavePath = modulepath; - } - + else + { + modulepath = System.IO.Path.Combine( + Environment.GetEnvironmentVariable("HOME"), + ".config/powershell/modules"); + + HistorySavePath = System.IO.Path.Combine( + Environment.GetEnvironmentVariable("HOME"), + modulepath, + "PSReadLine", + hostName + "_history.txt"); } - #else + } +#else HistorySavePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Microsoft\Windows\PowerShell\PSReadline\" + hostName + "_history.txt"; #endif From 22477c0a50b3f7d061f9b3655c8597f87bac9eb8 Mon Sep 17 00:00:00 2001 From: v-alexjo Date: Fri, 3 Jun 2016 03:15:13 -0700 Subject: [PATCH 23/58] Further code review changes --- PSReadLine/Cmdlets.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/PSReadLine/Cmdlets.cs b/PSReadLine/Cmdlets.cs index f32595182..d3fae3ee6 100644 --- a/PSReadLine/Cmdlets.cs +++ b/PSReadLine/Cmdlets.cs @@ -180,23 +180,23 @@ public PSConsoleReadlineOptions(string hostName) else { //PSReadline does not have access to Utils.CorePSPlatform. Must set PSReadline path seperately - string modulepath = System.Environment.GetEnvironmentVariable("XDG_CACHE_HOME"); + string historypath = System.Environment.GetEnvironmentVariable("XDG_DATA_HOME"); - if (!String.IsNullOrEmpty(modulepath)) + if (!String.IsNullOrEmpty(historypath)) { - modulepath = System.IO.Path.Combine(modulepath, "powershell"); - HistorySavePath = modulepath; + historypath = System.IO.Path.Combine(historypath, "powershell"); + HistorySavePath = historypath; } else { - modulepath = System.IO.Path.Combine( + historypath = System.IO.Path.Combine( Environment.GetEnvironmentVariable("HOME"), - ".config/powershell/modules"); + ".local/share/powershell/modules"); HistorySavePath = System.IO.Path.Combine( Environment.GetEnvironmentVariable("HOME"), - modulepath, + historypath, "PSReadLine", hostName + "_history.txt"); } From 6a9e6dfd425f0663cd87f3d72b0925b1ef186a0e Mon Sep 17 00:00:00 2001 From: v-alexjo Date: Fri, 3 Jun 2016 13:55:23 -0700 Subject: [PATCH 24/58] Changing history to cache, removed redundant code --- PSReadLine/Cmdlets.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/PSReadLine/Cmdlets.cs b/PSReadLine/Cmdlets.cs index d3fae3ee6..cd00286ac 100644 --- a/PSReadLine/Cmdlets.cs +++ b/PSReadLine/Cmdlets.cs @@ -180,23 +180,20 @@ public PSConsoleReadlineOptions(string hostName) else { //PSReadline does not have access to Utils.CorePSPlatform. Must set PSReadline path seperately - string historypath = System.Environment.GetEnvironmentVariable("XDG_DATA_HOME"); + string historypath = System.Environment.GetEnvironmentVariable("XDG_CACHE_HOME"); if (!String.IsNullOrEmpty(historypath)) { - historypath = System.IO.Path.Combine(historypath, "powershell"); + historypath = System.IO.Path.Combine(historypath, "powershell", "PSReadLine", hostName + "_history.txt"); HistorySavePath = historypath; } else { - historypath = System.IO.Path.Combine( - Environment.GetEnvironmentVariable("HOME"), - ".local/share/powershell/modules"); - HistorySavePath = System.IO.Path.Combine( Environment.GetEnvironmentVariable("HOME"), - historypath, + ".cache", + "powershell", "PSReadLine", hostName + "_history.txt"); } From 19979e1aeeccd2b1a43979cd5c948bcd2f9b9168 Mon Sep 17 00:00:00 2001 From: v-alexjo Date: Sun, 5 Jun 2016 23:50:35 -0700 Subject: [PATCH 25/58] Style changes and psreadline path change --- PSReadLine/Cmdlets.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/PSReadLine/Cmdlets.cs b/PSReadLine/Cmdlets.cs index cd00286ac..6688d9ceb 100644 --- a/PSReadLine/Cmdlets.cs +++ b/PSReadLine/Cmdlets.cs @@ -190,11 +190,12 @@ public PSConsoleReadlineOptions(string hostName) else { + //While a module, history save path goes into the larger .local/share/powershell folder HistorySavePath = System.IO.Path.Combine( Environment.GetEnvironmentVariable("HOME"), - ".cache", - "powershell", - "PSReadLine", + ".local", + "share", + "powershell", hostName + "_history.txt"); } } From 7f3c32821892ac472afd79b0b02d7a09f1ef59ad Mon Sep 17 00:00:00 2001 From: v-alexjo Date: Mon, 6 Jun 2016 00:36:15 -0700 Subject: [PATCH 26/58] configdefault missed in refactoring --- PSReadLine/Cmdlets.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/PSReadLine/Cmdlets.cs b/PSReadLine/Cmdlets.cs index 6688d9ceb..7a72cee73 100644 --- a/PSReadLine/Cmdlets.cs +++ b/PSReadLine/Cmdlets.cs @@ -180,7 +180,7 @@ public PSConsoleReadlineOptions(string hostName) else { //PSReadline does not have access to Utils.CorePSPlatform. Must set PSReadline path seperately - string historypath = System.Environment.GetEnvironmentVariable("XDG_CACHE_HOME"); + string historypath = System.Environment.GetEnvironmentVariable("XDG_DATA_HOME"); if (!String.IsNullOrEmpty(historypath)) { @@ -195,7 +195,8 @@ public PSConsoleReadlineOptions(string hostName) Environment.GetEnvironmentVariable("HOME"), ".local", "share", - "powershell", + "powershell", + "PSReadLine", hostName + "_history.txt"); } } From 6e9b9772080f4bf2e490ab746d0195f3980f793f Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 6 Jun 2016 13:37:03 -0700 Subject: [PATCH 27/58] Fix PSReadLine history path on Windows Bug introduced in initial port of PSReadLine. `Path.Combine` sees the initial backslash as an absolute path, thus discarding `AppData`. --- PSReadLine/Cmdlets.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PSReadLine/Cmdlets.cs b/PSReadLine/Cmdlets.cs index 7a72cee73..ffb40e744 100644 --- a/PSReadLine/Cmdlets.cs +++ b/PSReadLine/Cmdlets.cs @@ -172,8 +172,8 @@ public PSConsoleReadlineOptions(string hostName) #if CORECLR if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) // MS Windows { - HistorySavePath = System.IO.Path.Combine(Environment.ExpandEnvironmentVariables("%AppData%"), - @"\Microsoft\Windows\PowerShell\PSReadline\", + HistorySavePath = System.IO.Path.Combine(Environment.GetEnvironmentVariable("APPDATA"), + @"Microsoft\Windows\PowerShell\PSReadline\", hostName + "_history.txt"); } From aea43f3289cdca9fc0ca80a7d1d06241767b579e Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 6 Jun 2016 13:37:27 -0700 Subject: [PATCH 28/58] Whitespace and formatting cleanups --- PSReadLine/Cmdlets.cs | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/PSReadLine/Cmdlets.cs b/PSReadLine/Cmdlets.cs index ffb40e744..8c2f37004 100644 --- a/PSReadLine/Cmdlets.cs +++ b/PSReadLine/Cmdlets.cs @@ -169,40 +169,39 @@ public PSConsoleReadlineOptions(string hostName) WordDelimiters = DefaultWordDelimiters; HistorySearchCaseSensitive = DefaultHistorySearchCaseSensitive; HistorySaveStyle = DefaultHistorySaveStyle; + + string historyFileName = hostName + "_history.txt"; #if CORECLR if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) // MS Windows { HistorySavePath = System.IO.Path.Combine(Environment.GetEnvironmentVariable("APPDATA"), @"Microsoft\Windows\PowerShell\PSReadline\", - hostName + "_history.txt"); + historyFileName); } - else { - //PSReadline does not have access to Utils.CorePSPlatform. Must set PSReadline path seperately - string historypath = System.Environment.GetEnvironmentVariable("XDG_DATA_HOME"); - - if (!String.IsNullOrEmpty(historypath)) + // PSReadline does not have access to Utils.CorePSPlatform. Must set PSReadline path separately + string historyPath = System.Environment.GetEnvironmentVariable("XDG_DATA_HOME"); + + if (!String.IsNullOrEmpty(historyPath)) { - historypath = System.IO.Path.Combine(historypath, "powershell", "PSReadLine", hostName + "_history.txt"); - HistorySavePath = historypath; + historyPath = System.IO.Path.Combine(historyPath, "powershell", "PSReadLine", historyFileName); + HistorySavePath = historyPath; } - else { - //While a module, history save path goes into the larger .local/share/powershell folder - HistorySavePath = System.IO.Path.Combine( - Environment.GetEnvironmentVariable("HOME"), + // History is data, so it goes into .local/share/powershell folder + HistorySavePath = System.IO.Path.Combine(Environment.GetEnvironmentVariable("HOME"), ".local", "share", - "powershell", + "powershell", "PSReadLine", - hostName + "_history.txt"); + historyFileName); } } #else - HistorySavePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) - + @"\Microsoft\Windows\PowerShell\PSReadline\" + hostName + "_history.txt"; + HistorySavePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + + @"\Microsoft\Windows\PowerShell\PSReadline\" + historyFileName; #endif CommandValidationHandler = null; CommandsToValidateScriptBlockArguments = new HashSet(StringComparer.OrdinalIgnoreCase) @@ -221,7 +220,7 @@ public PSConsoleReadlineOptions(string hostName) "Where-Object", "?", "where", }; } - + public EditMode EditMode { get; set; } public string ContinuationPrompt { get; set; } From 1b092094906d7e216d415d0a60d8a3ef94b0c274 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 10 Jun 2016 11:03:56 -0700 Subject: [PATCH 29/58] Rename compilationOptions to buildOptions in project.json files This resolves #928. This is a breaking change in that you *must* be running a recent version of .NET CLI. --- PSReadLine/project.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PSReadLine/project.json b/PSReadLine/project.json index 172b9ae40..7f9bce543 100644 --- a/PSReadLine/project.json +++ b/PSReadLine/project.json @@ -3,7 +3,7 @@ "version": "1.0.0-*", "authors": [ "andschwa" ], - "compilationOptions": { + "buildOptions": { "warningsAsErrors": true }, @@ -13,7 +13,7 @@ "frameworks": { "netstandard1.5": { - "compilationOptions": { + "buildOptions": { "define": [ "CORECLR" ] }, "imports": [ "dnxcore50", "portable-net45+win8" ] From 40b6870514b2442ec3a4f25599b55aee6770571c Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 16 Jun 2016 14:27:29 -0700 Subject: [PATCH 30/58] Sign all assemblies with key --- PSReadLine/project.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/PSReadLine/project.json b/PSReadLine/project.json index 7f9bce543..83acdaa7b 100644 --- a/PSReadLine/project.json +++ b/PSReadLine/project.json @@ -4,6 +4,9 @@ "authors": [ "andschwa" ], "buildOptions": { + "keyFile": "../signing/visualstudiopublic.snk", + "delaySign": true, + "publicSign": false, "warningsAsErrors": true }, From 26317b8e77c30840c256ecaef90b9b4bd6d526e0 Mon Sep 17 00:00:00 2001 From: Sergei Vorobev Date: Thu, 16 Jun 2016 19:33:19 -0700 Subject: [PATCH 31/58] Remove authors section from product project.json --- PSReadLine/project.json | 1 - 1 file changed, 1 deletion(-) diff --git a/PSReadLine/project.json b/PSReadLine/project.json index 83acdaa7b..1947e301e 100644 --- a/PSReadLine/project.json +++ b/PSReadLine/project.json @@ -1,7 +1,6 @@ { "name": "Microsoft.PowerShell.PSReadLine", "version": "1.0.0-*", - "authors": [ "andschwa" ], "buildOptions": { "keyFile": "../signing/visualstudiopublic.snk", From 7156fcfaadcbe275d645150da1fdaa018578d012 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 24 Jun 2016 14:21:06 -0700 Subject: [PATCH 32/58] Bump framework to netstandard1.6 This is required to use the new .NET Core RTM packages, specifically the `IEnumerable Append` API. --- PSReadLine/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PSReadLine/project.json b/PSReadLine/project.json index 1947e301e..9973dd8c5 100644 --- a/PSReadLine/project.json +++ b/PSReadLine/project.json @@ -14,7 +14,7 @@ }, "frameworks": { - "netstandard1.5": { + "netstandard1.6": { "buildOptions": { "define": [ "CORECLR" ] }, From 9220b04747efa192f8a93690b9d9850d13e971ba Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 1 Jul 2016 11:51:12 -0700 Subject: [PATCH 33/58] Import PSReadLine change to throw when redirected A similar change was made to the Source Depot fork of PSReadLine, and the behavior is depended on in the ConsoleHost. The host always attempts to load PSReadLine, because a future version of PSReadLine will support redirected input/output, and until then, PSReadLine must throw so that the host correctly falls back to Console.ReadLine(). --- PSReadLine/ReadLine.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/PSReadLine/ReadLine.cs b/PSReadLine/ReadLine.cs index 58a9591db..aabf5a46a 100644 --- a/PSReadLine/ReadLine.cs +++ b/PSReadLine/ReadLine.cs @@ -258,6 +258,14 @@ private bool BreakHandler(ConsoleBreakSignal signal) public static string ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics) { var console = _singleton._console; + + // If either stdin or stdout is redirected, PSReadline doesn't really work, so throw + // and let PowerShell call Console.ReadLine or do whatever else it decides to do. + if (Console.IsInputRedirected || Console.IsOutputRedirected) + { + throw new NotSupportedException(); + } + #if CORECLR _singleton._prePSReadlineControlCMode = Console.TreatControlCAsInput; #else From e2388e0e740ce1a93005b2c35998f8c920909592 Mon Sep 17 00:00:00 2001 From: "Jason Shirk (POWERSHELL)" Date: Tue, 5 Jul 2016 10:27:41 -0700 Subject: [PATCH 34/58] Add csproj files and sln for editing but not building --- PSReadLine/PSReadLine.csproj | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/PSReadLine/PSReadLine.csproj b/PSReadLine/PSReadLine.csproj index 63431248c..a9845be9f 100644 --- a/PSReadLine/PSReadLine.csproj +++ b/PSReadLine/PSReadLine.csproj @@ -34,6 +34,12 @@ true false + + bin\UNIX\ + + + bin\CORECLR\ + @@ -140,4 +146,4 @@ --> - + \ No newline at end of file From c4b66b98f4d3257daee585ac90ebd5d1943aeea1 Mon Sep 17 00:00:00 2001 From: "Jason Shirk (POWERSHELL)" Date: Tue, 5 Jul 2016 18:57:18 -0700 Subject: [PATCH 35/58] First stab addressing CORECLR vs. LINUX in PSReadLine --- PSReadLine/Cmdlets.cs | 78 ++++++++------------------ PSReadLine/Completion.cs | 4 +- PSReadLine/ConsoleKeyChordConverter.cs | 4 +- PSReadLine/ConsoleLib.cs | 40 +++++-------- PSReadLine/HistoryQueue.cs | 9 ++- PSReadLine/KeyBindings.cs | 6 +- PSReadLine/KeyBindings.vi.cs | 4 +- PSReadLine/Keys.cs | 8 +-- PSReadLine/KillYank.cs | 10 ++-- PSReadLine/Movement.cs | 2 +- PSReadLine/PublicAPI.cs | 2 +- PSReadLine/ReadLine.cs | 30 +++++----- PSReadLine/Render.cs | 19 +------ PSReadLine/ScreenCapture.cs | 21 +++---- PSReadLine/VisualEditing.vi.cs | 20 +------ PSReadLine/project.json | 8 +++ 16 files changed, 94 insertions(+), 171 deletions(-) diff --git a/PSReadLine/Cmdlets.cs b/PSReadLine/Cmdlets.cs index 8c2f37004..514eed8ed 100644 --- a/PSReadLine/Cmdlets.cs +++ b/PSReadLine/Cmdlets.cs @@ -12,6 +12,7 @@ using System.Linq; #if CORECLR using System.Runtime.InteropServices; +using Microsoft.PowerShell.Internal; #endif namespace Microsoft.PowerShell @@ -72,33 +73,24 @@ public enum HistorySaveStyle public class PSConsoleReadlineOptions { -#if CORECLR +#if LINUX // TODO: why different schemes for LINUX? public const ConsoleColor DefaultCommentForegroundColor = ConsoleColor.Magenta; - public const ConsoleColor DefaultKeywordForegroundColor = ConsoleColor.Green; - public const ConsoleColor DefaultStringForegroundColor = ConsoleColor.DarkCyan; public const ConsoleColor DefaultOperatorForegroundColor = ConsoleColor.Gray; - public const ConsoleColor DefaultVariableForegroundColor = ConsoleColor.Green; - public const ConsoleColor DefaultCommandForegroundColor = ConsoleColor.Yellow; public const ConsoleColor DefaultParameterForegroundColor = ConsoleColor.Green; - public const ConsoleColor DefaultTypeForegroundColor = ConsoleColor.Gray; - public const ConsoleColor DefaultNumberForegroundColor = ConsoleColor.White; - public const ConsoleColor DefaultMemberForegroundColor = ConsoleColor.Gray; - public const ConsoleColor DefaultEmphasisForegroundColor = ConsoleColor.Cyan; - public const ConsoleColor DefaultErrorForegroundColor = ConsoleColor.Red; #else public const ConsoleColor DefaultCommentForegroundColor = ConsoleColor.DarkGreen; + public const ConsoleColor DefaultOperatorForegroundColor = ConsoleColor.DarkGray; + public const ConsoleColor DefaultParameterForegroundColor = ConsoleColor.DarkGray; +#endif public const ConsoleColor DefaultKeywordForegroundColor = ConsoleColor.Green; public const ConsoleColor DefaultStringForegroundColor = ConsoleColor.DarkCyan; - public const ConsoleColor DefaultOperatorForegroundColor = ConsoleColor.DarkGray; public const ConsoleColor DefaultVariableForegroundColor = ConsoleColor.Green; public const ConsoleColor DefaultCommandForegroundColor = ConsoleColor.Yellow; - public const ConsoleColor DefaultParameterForegroundColor = ConsoleColor.DarkGray; public const ConsoleColor DefaultTypeForegroundColor = ConsoleColor.Gray; public const ConsoleColor DefaultNumberForegroundColor = ConsoleColor.White; public const ConsoleColor DefaultMemberForegroundColor = ConsoleColor.Gray; public const ConsoleColor DefaultEmphasisForegroundColor = ConsoleColor.Cyan; public const ConsoleColor DefaultErrorForegroundColor = ConsoleColor.Red; -#endif public const EditMode DefaultEditMode = EditMode.Windows; @@ -171,37 +163,29 @@ public PSConsoleReadlineOptions(string hostName) HistorySaveStyle = DefaultHistorySaveStyle; string historyFileName = hostName + "_history.txt"; -#if CORECLR - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) // MS Windows +#if LINUX + // PSReadline does not have access to Utils.CorePSPlatform. Must set PSReadline path separately + string historyPath = System.Environment.GetEnvironmentVariable("XDG_DATA_HOME"); + + if (!String.IsNullOrEmpty(historyPath)) { - HistorySavePath = System.IO.Path.Combine(Environment.GetEnvironmentVariable("APPDATA"), - @"Microsoft\Windows\PowerShell\PSReadline\", - historyFileName); + historyPath = System.IO.Path.Combine(historyPath, "powershell", "PSReadLine", historyFileName); + HistorySavePath = historyPath; } else { - // PSReadline does not have access to Utils.CorePSPlatform. Must set PSReadline path separately - string historyPath = System.Environment.GetEnvironmentVariable("XDG_DATA_HOME"); - - if (!String.IsNullOrEmpty(historyPath)) - { - historyPath = System.IO.Path.Combine(historyPath, "powershell", "PSReadLine", historyFileName); - HistorySavePath = historyPath; - } - else - { - // History is data, so it goes into .local/share/powershell folder - HistorySavePath = System.IO.Path.Combine(Environment.GetEnvironmentVariable("HOME"), - ".local", - "share", - "powershell", - "PSReadLine", - historyFileName); - } + // History is data, so it goes into .local/share/powershell folder + HistorySavePath = System.IO.Path.Combine(Environment.GetEnvironmentVariable("HOME"), + ".local", + "share", + "powershell", + "PSReadLine", + historyFileName); } #else - HistorySavePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) - + @"\Microsoft\Windows\PowerShell\PSReadline\" + historyFileName; + HistorySavePath = System.IO.Path.Combine(Environment.GetEnvironmentVariable("APPDATA"), + @"Microsoft\Windows\PowerShell\PSReadline\", + historyFileName); #endif CommandValidationHandler = null; CommandsToValidateScriptBlockArguments = new HashSet(StringComparer.OrdinalIgnoreCase) @@ -396,9 +380,7 @@ internal void SetBackgroundColor(TokenClassification tokenKind, ConsoleColor col [OutputType(typeof(PSConsoleReadlineOptions))] public class GetPSReadlineOption : PSCmdlet { -#if !CORECLR [ExcludeFromCodeCoverage] -#endif protected override void EndProcessing() { WriteObject(PSConsoleReadLine.GetOptions()); @@ -641,9 +623,7 @@ public ConsoleColor BackgroundColor } internal ConsoleColor? _backgroundColor; -#if !CORECLR [ExcludeFromCodeCoverage] -#endif protected override void EndProcessing() { PSConsoleReadLine.SetOptions(this); @@ -661,9 +641,7 @@ public class ChangePSReadlineKeyHandlerCommandBase : PSCmdlet [Parameter] public ViMode ViMode { get; set; } -#if !CORECLR [ExcludeFromCodeCoverage] -#endif protected IDisposable UseRequestedDispatchTables() { bool inViMode = PSConsoleReadLine.GetOptions().EditMode == EditMode.Vi; @@ -706,9 +684,7 @@ public class SetPSReadlineKeyHandlerCommand : ChangePSReadlineKeyHandlerCommandB private const string FunctionParameter = "Function"; private const string FunctionParameterSet = "Function"; -#if !CORECLR [ExcludeFromCodeCoverage] -#endif protected override void EndProcessing() { using (UseRequestedDispatchTables()) @@ -716,15 +692,9 @@ protected override void EndProcessing() if (ParameterSetName.Equals(FunctionParameterSet)) { var function = (string)_dynamicParameters.Value[FunctionParameter].Value; -#if CORECLR MethodInfo mi = typeof (PSConsoleReadLine).GetMethod(function); var keyHandler = (Action) mi.CreateDelegate(typeof (Action)); -#else - var keyHandler = (Action) - Delegate.CreateDelegate(typeof (Action), - typeof (PSConsoleReadLine).GetMethod(function)); -#endif BriefDescription = function; PSConsoleReadLine.SetKeyHandler(Chord, keyHandler, BriefDescription, Description); } @@ -792,9 +762,7 @@ public SwitchParameter Unbound } private SwitchParameter? _unbound; -#if !CORECLR [ExcludeFromCodeCoverage] -#endif protected override void EndProcessing() { bool bound = true; @@ -821,9 +789,7 @@ protected override void EndProcessing() [Cmdlet("Remove", "PSReadlineKeyHandler", HelpUri = "http://go.microsoft.com/fwlink/?LinkId=528809")] public class RemoveKeyHandlerCommand : ChangePSReadlineKeyHandlerCommandBase { -#if !CORECLR [ExcludeFromCodeCoverage] -#endif protected override void EndProcessing() { using (UseRequestedDispatchTables()) diff --git a/PSReadLine/Completion.cs b/PSReadLine/Completion.cs index 9dd13a6a6..4407de00f 100644 --- a/PSReadLine/Completion.cs +++ b/PSReadLine/Completion.cs @@ -27,9 +27,7 @@ public partial class PSConsoleReadLine private static string DirectorySeparatorString = System.IO.Path.DirectorySeparatorChar.ToString(); // Stub helper method so completion can be mocked -#if !CORECLR [ExcludeFromCodeCoverage] -#endif CommandCompletion IPSConsoleReadLineMockableMethods.CompleteInput(string input, int cursorIndex, Hashtable options, System.Management.Automation.PowerShell powershell) { return CalloutUsingDefaultConsoleMode( @@ -308,7 +306,7 @@ private static void InvertSelectedCompletion(CHAR_INFO[] buffer, int selectedIte for (int i = 0; i < menuColumnWidth; i++) { int j = i + start; -#if CORECLR +#if LINUX // TODO: use real inverse ConsoleColor tempColor = (int)buffer[j].ForegroundColor == -1 ? ConsoleColor.White : buffer[j].ForegroundColor; buffer[j].ForegroundColor = (int)buffer[j].BackgroundColor == -1 diff --git a/PSReadLine/ConsoleKeyChordConverter.cs b/PSReadLine/ConsoleKeyChordConverter.cs index 7ab95732b..32722153d 100644 --- a/PSReadLine/ConsoleKeyChordConverter.cs +++ b/PSReadLine/ConsoleKeyChordConverter.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; -#if CORECLR +#if LINUX using System.Reflection; #endif using System.Runtime.InteropServices; @@ -214,7 +214,7 @@ internal static char GetCharFromConsoleKey(ConsoleKey key, ConsoleModifiers modi { // default for unprintables and unhandled char keyChar = '\u0000'; -#if CORECLR +#if LINUX Type keyType = typeof (Keys); FieldInfo[] keyFields = keyType.GetFields(); diff --git a/PSReadLine/ConsoleLib.cs b/PSReadLine/ConsoleLib.cs index deadf12e3..76c46d40d 100644 --- a/PSReadLine/ConsoleLib.cs +++ b/PSReadLine/ConsoleLib.cs @@ -227,9 +227,7 @@ public struct SMALL_RECT public short Right; public short Bottom; -#if !CORECLR [ExcludeFromCodeCoverage] -#endif public override string ToString() { return String.Format(CultureInfo.InvariantCulture, "{0},{1},{2},{3}", Left, Top, Right, Bottom); @@ -241,9 +239,7 @@ internal struct COORD public short X; public short Y; -#if !CORECLR [ExcludeFromCodeCoverage] -#endif public override string ToString() { return String.Format(CultureInfo.InvariantCulture, "{0},{1}", X, Y); @@ -315,18 +311,6 @@ internal struct CONSOLE_FONT_INFO_EX public struct CHAR_INFO { -#if CORECLR - public char UnicodeChar; - public ConsoleColor ForegroundColor; - public ConsoleColor BackgroundColor; - - public CHAR_INFO(char c, ConsoleColor foreground, ConsoleColor background) - { - UnicodeChar = c; - ForegroundColor = foreground; - BackgroundColor = background; - } -#else public ushort UnicodeChar; public ushort Attributes; @@ -379,7 +363,6 @@ public override int GetHashCode() { return UnicodeChar.GetHashCode() + Attributes.GetHashCode(); } -#endif } internal static class ConsoleKeyInfoExtension @@ -400,9 +383,10 @@ public static string ToGestureString(this ConsoleKeyInfo key) sb.Append("Alt"); } -#if CORECLR +#if LINUX if (sb.Length > 0) sb.Append("+"); + // TODO: find better way to map these characters to something more friendly if ((key.Key >= ConsoleKey.D0 && key.Key <= ConsoleKey.D9) || (key.Key >= ConsoleKey.Oem1 && key.Key <= ConsoleKey.Oem8)) { @@ -609,9 +593,6 @@ public void WriteBufferLines(CHAR_INFO[] buffer, ref int top) public void WriteBufferLines(CHAR_INFO[] buffer, ref int top, bool ensureBottomLineVisible) { -#if !CORECLR - var handle = NativeMethods.GetStdHandle((uint) StandardHandleId.Output); -#endif int bufferWidth = Console.BufferWidth; int bufferLineCount = buffer.Length / bufferWidth; if ((top + bufferLineCount) > Console.BufferHeight) @@ -620,7 +601,7 @@ public void WriteBufferLines(CHAR_INFO[] buffer, ref int top, bool ensureBottomL ScrollBuffer(scrollCount); top -= scrollCount; } -#if CORECLR +#if LINUX ConsoleColor foregroundColor = Console.ForegroundColor; ConsoleColor backgroundColor = Console.BackgroundColor; @@ -628,6 +609,7 @@ public void WriteBufferLines(CHAR_INFO[] buffer, ref int top, bool ensureBottomL for (int i = 0; i < buffer.Length; ++i) { + // TODO: use escape sequences for better perf Console.ForegroundColor = buffer[i].ForegroundColor; Console.BackgroundColor = buffer[i].BackgroundColor; @@ -637,6 +619,7 @@ public void WriteBufferLines(CHAR_INFO[] buffer, ref int top, bool ensureBottomL Console.BackgroundColor = backgroundColor; Console.ForegroundColor = foregroundColor; #else + var handle = NativeMethods.GetStdHandle((uint) StandardHandleId.Output); var bufferSize = new COORD { X = (short) bufferWidth, @@ -665,7 +648,7 @@ public void WriteBufferLines(CHAR_INFO[] buffer, ref int top, bool ensureBottomL public void ScrollBuffer(int lines) { -#if CORECLR +#if LINUX for (int i=0; i { private readonly HistoryQueue _queue; @@ -116,9 +117,7 @@ public T[] ToArray() return result; } -#if !CORECLR [ExcludeFromCodeCoverage] -#endif public T this[int index] { get diff --git a/PSReadLine/KeyBindings.cs b/PSReadLine/KeyBindings.cs index 207f5cae1..aae97e503 100644 --- a/PSReadLine/KeyBindings.cs +++ b/PSReadLine/KeyBindings.cs @@ -142,7 +142,7 @@ void SetDefaultWindowsBindings() { Keys.CtrlSpace, MakeKeyHandler(MenuComplete, "MenuComplete") }, { Keys.Tab, MakeKeyHandler(TabCompleteNext, "TabCompleteNext") }, { Keys.ShiftTab, MakeKeyHandler(TabCompletePrevious, "TabCompletePrevious") }, -#if !CORECLR +#if !LINUX { Keys.VolumeDown, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeUp, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeMute, MakeKeyHandler(Ignore, "Ignore") }, @@ -181,7 +181,7 @@ void SetDefaultWindowsBindings() { Keys.ShiftF3, MakeKeyHandler(CharacterSearchBackward, "CharacterSearchBackward") }, { Keys.F8, MakeKeyHandler(HistorySearchBackward, "HistorySearchBackward") }, { Keys.ShiftF8, MakeKeyHandler(HistorySearchForward, "HistorySearchForward") }, -#if !CORECLR +#if !LINUX { Keys.PageUp, MakeKeyHandler(ScrollDisplayUp, "ScrollDisplayUp") }, { Keys.PageDown, MakeKeyHandler(ScrollDisplayDown, "ScrollDisplayDown") }, { Keys.CtrlPageUp, MakeKeyHandler(ScrollDisplayUpLine, "ScrollDisplayUpLine") }, @@ -265,7 +265,7 @@ void SetDefaultEmacsBindings() { Keys.AltPeriod, MakeKeyHandler(YankLastArg, "YankLastArg") }, { Keys.AltUnderbar, MakeKeyHandler(YankLastArg, "YankLastArg") }, { Keys.AltCtrlY, MakeKeyHandler(YankNthArg, "YankNthArg") }, -#if !CORECLR +#if !LINUX { Keys.VolumeDown, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeUp, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeMute, MakeKeyHandler(Ignore, "Ignore") }, diff --git a/PSReadLine/KeyBindings.vi.cs b/PSReadLine/KeyBindings.vi.cs index d31cba72d..29cfa61b3 100644 --- a/PSReadLine/KeyBindings.vi.cs +++ b/PSReadLine/KeyBindings.vi.cs @@ -70,7 +70,7 @@ private void SetDefaultViBindings() { Keys.Tab, MakeKeyHandler(ViTabCompleteNext, "ViTabCompleteNext") }, { Keys.ShiftTab, MakeKeyHandler(ViTabCompletePrevious, "ViTabCompletePrevious") }, { Keys.CtrlV, MakeKeyHandler(Paste, "Paste") }, -#if !CORECLR +#if !LINUX { Keys.VolumeDown, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeUp, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeMute, MakeKeyHandler(Ignore, "Ignore") }, @@ -109,7 +109,7 @@ private void SetDefaultViBindings() { Keys.Tab, MakeKeyHandler(TabCompleteNext, "TabCompleteNext") }, { Keys.ShiftTab, MakeKeyHandler(TabCompletePrevious, "TabCompletePrevious") }, { Keys.CtrlV, MakeKeyHandler(Paste, "Paste") }, -#if !CORECLR +#if !LINUX { Keys.VolumeDown, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeUp, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeMute, MakeKeyHandler(Ignore, "Ignore") }, diff --git a/PSReadLine/Keys.cs b/PSReadLine/Keys.cs index 07166088d..94c566716 100644 --- a/PSReadLine/Keys.cs +++ b/PSReadLine/Keys.cs @@ -290,10 +290,10 @@ internal static class Keys public static ConsoleKeyInfo ShiftF8 = new ConsoleKeyInfo((char)0, ConsoleKey.F8, true, false, false); // Keys to ignore -#if !CORECLR - public static ConsoleKeyInfo VolumeUp = new ConsoleKeyInfo((char)0, ConsoleKey.VolumeUp, false, false, false); - public static ConsoleKeyInfo VolumeDown = new ConsoleKeyInfo((char)0, ConsoleKey.VolumeDown, false, false, false); - public static ConsoleKeyInfo VolumeMute = new ConsoleKeyInfo((char)0, ConsoleKey.VolumeMute, false, false, false); +#if !LINUX + public static ConsoleKeyInfo VolumeUp = new ConsoleKeyInfo((char)0, /*ConsoleKey.VolumeUp*/(ConsoleKey)175, false, false, false); + public static ConsoleKeyInfo VolumeDown = new ConsoleKeyInfo((char)0, /*ConsoleKey.VolumeDown*/(ConsoleKey)174, false, false, false); + public static ConsoleKeyInfo VolumeMute = new ConsoleKeyInfo((char)0, /*ConsoleKey.VolumeMute*/(ConsoleKey)173, false, false, false); #endif } } diff --git a/PSReadLine/KillYank.cs b/PSReadLine/KillYank.cs index 651364c78..ba6a87b22 100644 --- a/PSReadLine/KillYank.cs +++ b/PSReadLine/KillYank.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Management.Automation.Language; -#if !CORECLR +#if !CORECLR // TODO: clipboard using System.Windows.Forms; #endif @@ -478,7 +478,7 @@ public static void SelectBackwardsLine(ConsoleKeyInfo? key = null, object arg = [SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")] public static void Paste(ConsoleKeyInfo? key = null, object arg = null) { -#if !CORECLR +#if !CORECLR // TODO: clipboard string textToPaste = null; ExecuteOnSTAThread(() => { if (Clipboard.ContainsText()) @@ -510,7 +510,7 @@ public static void Paste(ConsoleKeyInfo? key = null, object arg = null) [SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")] public static void Copy(ConsoleKeyInfo? key = null, object arg = null) { -#if !CORECLR +#if !CORECLR // TODO: clipboard string textToSet; if (_singleton._visualSelectionCommandCount > 0) { @@ -551,15 +551,15 @@ public static void CopyOrCancelLine(ConsoleKeyInfo? key = null, object arg = nul [SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")] public static void Cut(ConsoleKeyInfo? key = null, object arg = null) { -#if !CORECLR if (_singleton._visualSelectionCommandCount > 0) { int start, length; _singleton.GetRegion(out start, out length); +#if !CORECLR // TODO: clipboard ExecuteOnSTAThread(() => Clipboard.SetText(_singleton._buffer.ToString(start, length))); +#endif Delete(start, length); } -#endif } } } diff --git a/PSReadLine/Movement.cs b/PSReadLine/Movement.cs index 610ee0462..52c1983f0 100644 --- a/PSReadLine/Movement.cs +++ b/PSReadLine/Movement.cs @@ -434,7 +434,7 @@ public static void GotoBrace(ConsoleKeyInfo? key = null, object arg = null) public static void ClearScreen(ConsoleKeyInfo? key = null, object arg = null) { var console = _singleton._console; -#if CORECLR +#if LINUX // TODO: this is not correct, it should only scroll console.Clear(); _singleton._initialY = 0; _singleton.Render(); diff --git a/PSReadLine/PublicAPI.cs b/PSReadLine/PublicAPI.cs index 8f38d5bf1..58ae62be8 100644 --- a/PSReadLine/PublicAPI.cs +++ b/PSReadLine/PublicAPI.cs @@ -54,7 +54,7 @@ public interface IConsole void StartRender(); int LengthInBufferCells(char c); void EndRender(); -#if CORECLR +#if LINUX void Clear(); #endif } diff --git a/PSReadLine/ReadLine.cs b/PSReadLine/ReadLine.cs index aabf5a46a..24777cef6 100644 --- a/PSReadLine/ReadLine.cs +++ b/PSReadLine/ReadLine.cs @@ -34,7 +34,7 @@ public partial class PSConsoleReadLine : IPSConsoleReadLineMockableMethods private IConsole _console; private EngineIntrinsics _engineIntrinsics; -#if !CORECLR +#if !LINUX private static GCHandle _breakHandlerGcHandle; #endif private Thread _readKeyThread; @@ -43,7 +43,7 @@ public partial class PSConsoleReadLine : IPSConsoleReadLineMockableMethods private ManualResetEvent _closingWaitHandle; private WaitHandle[] _threadProcWaitHandles; private WaitHandle[] _requestKeyWaitHandles; -#if CORECLR +#if LINUX // TODO: move to IConsole when there is a Linux IConsole implementation private bool _prePSReadlineControlCMode; #else private uint _prePSReadlineConsoleMode; @@ -266,7 +266,7 @@ public static string ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsi throw new NotSupportedException(); } -#if CORECLR +#if LINUX // TODO: move to IConsole when there is a Linux IConsole implementation _singleton._prePSReadlineControlCMode = Console.TreatControlCAsInput; #else _singleton._prePSReadlineConsoleMode = console.GetConsoleInputMode(); @@ -276,7 +276,7 @@ public static string ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsi { try { -#if CORECLR +#if LINUX // TODO: move to IConsole when there is a Linux IConsole implementation Console.TreatControlCAsInput = true; #else // Clear a couple flags so we can actually receive certain keys: @@ -362,7 +362,7 @@ public static string ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsi } finally { -#if CORECLR +#if LINUX // TODO: move to IConsole when there is a Linux IConsole implementation Console.TreatControlCAsInput = _singleton._prePSReadlineControlCMode; #else console.SetConsoleInputMode(_singleton._prePSReadlineConsoleMode); @@ -454,7 +454,7 @@ private string InputLoop() T CalloutUsingDefaultConsoleMode(Func func) { -#if CORECLR +#if LINUX // TODO: move to IConsole when there is a Linux IConsole implementation bool psReadlineControlCMode = Console.TreatControlCAsInput; try { @@ -590,7 +590,7 @@ private void Initialize(Runspace runspace, EngineIntrinsics engineIntrinsics) _statusIsErrorMessage = false; _consoleBuffer = ReadBufferLines(_initialY, 1 + Options.ExtraPromptLineCount); -#if CORECLR +#if LINUX // TODO: not necessary if ReadBufferLines worked, or if rendering worked on spans instead of complete lines string newPrompt = GetPrompt(); for (int i=0; i(Options.MaximumKillRingCount); -#if !CORECLR +#if !LINUX _breakHandlerGcHandle = GCHandle.Alloc(new BreakHandler(_singleton.BreakHandler)); NativeMethods.SetConsoleCtrlHandler((BreakHandler)_breakHandlerGcHandle.Target, true); #endif @@ -691,11 +691,11 @@ private void DelayedOneTimeInitialize() _singleton._requestKeyWaitHandles = new WaitHandle[] {_singleton._keyReadWaitHandle, _singleton._closingWaitHandle}; _singleton._threadProcWaitHandles = new WaitHandle[] {_singleton._readKeyWaitHandle, _singleton._closingWaitHandle}; +#if !CORECLR // This is for a "being hosted in an alternate appdomain scenario" (the // DomainUnload event is not raised for the default appdomain). It allows us // to exit cleanly when the appdomain is unloaded but the process is not going // away. -#if !CORECLR if (!AppDomain.CurrentDomain.IsDefaultAppDomain()) { AppDomain.CurrentDomain.DomainUnload += (x, y) => @@ -733,13 +733,14 @@ private static void Ignore(ConsoleKeyInfo? key = null, object arg = null) private static void ExecuteOnSTAThread(Action action) { -#if !CORECLR +#if CORECLR + action(); +#else if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA) { action(); return; } -#endif Exception exception = null; var thread = new Thread(() => @@ -754,9 +755,7 @@ private static void ExecuteOnSTAThread(Action action) } }); -#if !CORECLR thread.SetApartmentState(ApartmentState.STA); -#endif thread.Start(); thread.Join(); @@ -764,6 +763,7 @@ private static void ExecuteOnSTAThread(Action action) { throw exception; } +#endif } #region Miscellaneous bindable functions @@ -899,7 +899,7 @@ public static void InvokePrompt(ConsoleKeyInfo? key = null, object arg = null) _singleton._initialX = _singleton._console.CursorLeft; _singleton._consoleBuffer = ReadBufferLines(_singleton._initialY, 1 + _singleton.Options.ExtraPromptLineCount); -#if CORECLR +#if LINUX // TODO: ReadBufferLines only needed for extra line, but doesn't work on Linux for (int i=0; i 1) { _consoleBuffer[j].UnicodeChar = charToRender; -#if !CORECLR _consoleBuffer[j].Attributes = (ushort)(_consoleBuffer[j].Attributes | (uint)CHAR_INFO_Attributes.COMMON_LVB_LEADING_BYTE); -#endif MaybeEmphasize(ref _consoleBuffer[j++], i, foregroundColor, backgroundColor); _consoleBuffer[j].UnicodeChar = charToRender; -#if !CORECLR _consoleBuffer[j].Attributes = (ushort)(_consoleBuffer[j].Attributes | (uint)CHAR_INFO_Attributes.COMMON_LVB_TRAILING_BYTE); -#endif MaybeEmphasize(ref _consoleBuffer[j++], i, foregroundColor, backgroundColor); } else @@ -253,9 +246,7 @@ private void ReallyRender() } finally { -#if !CORECLR _console.EndRender(); -#endif } for (; j < (_consoleBuffer.Length - (statusLineCount * _bufferWidth)); j++) @@ -319,7 +310,7 @@ private void ReallyRender() if ((_initialY + bufferLineCount) > (_console.WindowTop + _console.WindowHeight)) { -#if !CORECLR +#if !LINUX // TODO: verify this isn't necessary for LINUX _console.WindowTop = _initialY + bufferLineCount - _console.WindowHeight; #endif } @@ -472,7 +463,7 @@ private void MaybeEmphasize(ref CHAR_INFO charInfo, int i, ConsoleColor foregrou // to invert only the lower 3 bits to change the color is somewhat // but looks best with the 2 default color schemes - starting PowerShell // from it's shortcut or from a cmd shortcut. -#if CORECLR +#if LINUX // TODO: set Inverse attribute and let render choose what to do. ConsoleColor tempColor = ((int)foregroundColor == -1) ? ConsoleColor.White : foregroundColor; foregroundColor = ((int)backgroundColor == -1) ? ConsoleColor.Black : backgroundColor; backgroundColor = tempColor; @@ -654,12 +645,9 @@ private int GetStatusLineCount() return (_statusLinePrompt.Length + _statusBuffer.Length) / _console.BufferWidth + 1; } -#if !CORECLR [ExcludeFromCodeCoverage] -#endif void IPSConsoleReadLineMockableMethods.Ding() { -#if !CORECLR switch (Options.BellStyle) { case BellStyle.None: @@ -671,7 +659,6 @@ void IPSConsoleReadLineMockableMethods.Ding() // TODO: flash prompt? command line? break; } -#endif } /// @@ -696,7 +683,7 @@ private bool PromptYesOrNo(string s) #region Screen scrolling -#if !CORECLR +#if !LINUX /// /// Scroll the display up one screen. /// diff --git a/PSReadLine/ScreenCapture.cs b/PSReadLine/ScreenCapture.cs index 2659fec97..85bfcc42b 100644 --- a/PSReadLine/ScreenCapture.cs +++ b/PSReadLine/ScreenCapture.cs @@ -2,12 +2,11 @@ Copyright (c) Microsoft Corporation. All rights reserved. --********************************************************************/ -#if !CORECLR +#if !LINUX using System; using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using System.Text; -using System.Windows.Forms; using Microsoft.PowerShell.Internal; namespace Microsoft.PowerShell @@ -19,16 +18,8 @@ private static void InvertLines(int start, int count) var buffer = ReadBufferLines(start, count); for (int i = 0; i < buffer.Length; i++) { -#if CORECLR - ConsoleColor tempColor = (int)buffer[i].ForegroundColor == -1 - ? ConsoleColor.White : buffer[i].ForegroundColor; - buffer[i].ForegroundColor = (int)buffer[i].BackgroundColor == -1 - ? ConsoleColor.Black : buffer[i].BackgroundColor; - buffer[i].BackgroundColor = tempColor; -#else buffer[i].ForegroundColor = (ConsoleColor)((int)buffer[i].ForegroundColor ^ 7); buffer[i].BackgroundColor = (ConsoleColor)((int)buffer[i].BackgroundColor ^ 7); -#endif } _singleton._console.WriteBufferLines(buffer, ref start, false); } @@ -237,7 +228,6 @@ private static void DumpScreenToClipboard(int top, int count) var buffer = ReadBufferLines(top, count); var bufferWidth = _singleton._console.BufferWidth; - var dataObject = new DataObject(); var textBuffer = new StringBuilder(buffer.Length + count); var rtfBuffer = new StringBuilder(); @@ -307,9 +297,12 @@ private static void DumpScreenToClipboard(int top, int count) } rtfBuffer.Append("}}"); - dataObject.SetData(DataFormats.Text, textBuffer.ToString()); - dataObject.SetData(DataFormats.Rtf, rtfBuffer.ToString()); - ExecuteOnSTAThread(() => Clipboard.SetDataObject(dataObject, copy: true)); +#if !CORECLR // TODO: break dependency on Window.Forms w/ p/invokes to clipboard directly, for now, just silently skip the copy. + var dataObject = new System.Windows.Forms.DataObject(); + dataObject.SetData(System.Windows.Forms.DataFormats.Text, textBuffer.ToString()); + dataObject.SetData(System.Windows.Forms.DataFormats.Rtf, rtfBuffer.ToString()); + ExecuteOnSTAThread(() => System.Windows.Forms.Clipboard.SetDataObject(dataObject, copy: true)); +#endif } } } diff --git a/PSReadLine/VisualEditing.vi.cs b/PSReadLine/VisualEditing.vi.cs index a8e8573e7..59a14053e 100644 --- a/PSReadLine/VisualEditing.vi.cs +++ b/PSReadLine/VisualEditing.vi.cs @@ -96,7 +96,6 @@ private void ProcessViVisualEditing() private static string GetPreferredEditor() { string[] names = {"VISUAL", "EDITOR"}; -#if CORECLR foreach (string name in names) { string editor = Environment.GetEnvironmentVariable(name); @@ -105,24 +104,7 @@ private static string GetPreferredEditor() return editor; } } -#else - EnvironmentVariableTarget[] targets = { - EnvironmentVariableTarget.Machine, - EnvironmentVariableTarget.Process, - EnvironmentVariableTarget.User - }; - foreach (string name in names) - { - foreach (EnvironmentVariableTarget target in targets) - { - string editor = Environment.GetEnvironmentVariable(name, target); - if (!string.IsNullOrWhiteSpace(editor)) - { - return editor; - } - } - } -#endif + return null; } } diff --git a/PSReadLine/project.json b/PSReadLine/project.json index 9973dd8c5..f8f9ba1f1 100644 --- a/PSReadLine/project.json +++ b/PSReadLine/project.json @@ -9,6 +9,14 @@ "warningsAsErrors": true }, + "configurations": { + "Linux": { + "buildOptions": { + "define": [ "LINUX" ] + } + } + }, + "dependencies": { "System.Management.Automation": "1.0.0-*" }, From 67176b324b71e3aa73805d5f43080b213c04b2ec Mon Sep 17 00:00:00 2001 From: "Jason Shirk (POWERSHELL)" Date: Wed, 6 Jul 2016 17:30:16 -0700 Subject: [PATCH 36/58] Introduce TTYConsole for UNIX --- PSReadLine/Completion.cs | 4 +- PSReadLine/ConsoleLib.cs | 265 ++++++++++++++++++++++++++++++++------- PSReadLine/PublicAPI.cs | 5 +- PSReadLine/ReadLine.cs | 60 ++------- PSReadLine/Render.cs | 5 +- 5 files changed, 238 insertions(+), 101 deletions(-) diff --git a/PSReadLine/Completion.cs b/PSReadLine/Completion.cs index 4407de00f..cba45cd01 100644 --- a/PSReadLine/Completion.cs +++ b/PSReadLine/Completion.cs @@ -307,9 +307,9 @@ private static void InvertSelectedCompletion(CHAR_INFO[] buffer, int selectedIte { int j = i + start; #if LINUX // TODO: use real inverse - ConsoleColor tempColor = (int)buffer[j].ForegroundColor == -1 + ConsoleColor tempColor = buffer[j].ForegroundColor == UnknownColor ? ConsoleColor.White : buffer[j].ForegroundColor; - buffer[j].ForegroundColor = (int)buffer[j].BackgroundColor == -1 + buffer[j].ForegroundColor = buffer[j].BackgroundColor == UnknownColor ? ConsoleColor.Black : buffer[j].BackgroundColor; buffer[j].BackgroundColor = tempColor; #else diff --git a/PSReadLine/ConsoleLib.cs b/PSReadLine/ConsoleLib.cs index 76c46d40d..03be91594 100644 --- a/PSReadLine/ConsoleLib.cs +++ b/PSReadLine/ConsoleLib.cs @@ -317,7 +317,7 @@ public struct CHAR_INFO public CHAR_INFO(char c, ConsoleColor foreground, ConsoleColor background) { UnicodeChar = c; - Attributes = (ushort)(((int)background << 4) | (int)foreground); + Attributes = (ushort)((((int)background << 4) & 0xf) | ((int)foreground & 0xf)); } [ExcludeFromCodeCoverage] @@ -330,7 +330,7 @@ public ConsoleColor ForegroundColor [ExcludeFromCodeCoverage] public ConsoleColor BackgroundColor { - get { return (ConsoleColor)((Attributes & 0xf0) >> 4); } + get { return (ConsoleColor)((Attributes & 0x00f0) >> 4); } set { Attributes = (ushort)((Attributes & 0xff0f) | (((int)value & 0xf) << 4)); } } @@ -426,6 +426,7 @@ public static string ToGestureString(this ConsoleKeyInfo key) } } +#if !LINUX internal class ConhostConsole : IConsole { [SuppressMessage("Microsoft.Reliability", "CA2006:UseSafeHandleToEncapsulateNativeResources")] @@ -482,18 +483,42 @@ internal class ConhostConsole : IConsole return new SafeFileHandle(handle, true); }); - public uint GetConsoleInputMode() + public object GetConsoleInputMode() { + uint mode; var handle = _inputHandle.Value.DangerousGetHandle(); - uint result; - NativeMethods.GetConsoleMode(handle, out result); - return result; + NativeMethods.GetConsoleMode(handle, out mode); + return mode; } - public void SetConsoleInputMode(uint mode) + public void SetConsoleInputMode(object modeObj) { - var handle = _inputHandle.Value.DangerousGetHandle(); - NativeMethods.SetConsoleMode(handle, mode); + if (modeObj is uint) + { + // Clear a couple flags so we can actually receive certain keys: + // ENABLE_PROCESSED_INPUT - enables Ctrl+C + // ENABLE_LINE_INPUT - enables Ctrl+S + // Also clear a couple flags so we don't mask the input that we ignore: + // ENABLE_MOUSE_INPUT - mouse events + // ENABLE_WINDOW_INPUT - window resize events + var mode = (uint)modeObj & + ~(NativeMethods.ENABLE_PROCESSED_INPUT | + NativeMethods.ENABLE_LINE_INPUT | + NativeMethods.ENABLE_WINDOW_INPUT | + NativeMethods.ENABLE_MOUSE_INPUT); + + var handle = _inputHandle.Value.DangerousGetHandle(); + NativeMethods.SetConsoleMode(handle, mode); + } + } + + public void RestoreConsoleInputMode(object modeObj) + { + if (modeObj is uint) + { + var handle = _inputHandle.Value.DangerousGetHandle(); + NativeMethods.SetConsoleMode(handle, (uint)modeObj); + } } public ConsoleKeyInfo ReadKey() @@ -601,24 +626,7 @@ public void WriteBufferLines(CHAR_INFO[] buffer, ref int top, bool ensureBottomL ScrollBuffer(scrollCount); top -= scrollCount; } -#if LINUX - ConsoleColor foregroundColor = Console.ForegroundColor; - ConsoleColor backgroundColor = Console.BackgroundColor; - - Console.SetCursorPosition(0, (top>=0) ? top : 0); - - for (int i = 0; i < buffer.Length; ++i) - { - // TODO: use escape sequences for better perf - Console.ForegroundColor = buffer[i].ForegroundColor; - Console.BackgroundColor = buffer[i].BackgroundColor; - - Console.Write((char)buffer[i].UnicodeChar); - } - Console.BackgroundColor = backgroundColor; - Console.ForegroundColor = foregroundColor; -#else var handle = NativeMethods.GetStdHandle((uint) StandardHandleId.Output); var bufferSize = new COORD { @@ -643,18 +651,10 @@ public void WriteBufferLines(CHAR_INFO[] buffer, ref int top, bool ensureBottomL { Console.CursorTop = bottom; } -#endif } public void ScrollBuffer(int lines) { -#if LINUX - for (int i=0; i Console.BufferHeight) + { + var scrollCount = (top + bufferLineCount) - Console.BufferHeight; + ScrollBuffer(scrollCount); + top -= scrollCount; + } + + ConsoleColor foregroundColor = Console.ForegroundColor; + ConsoleColor backgroundColor = Console.BackgroundColor; + + Console.SetCursorPosition(0, (top>=0) ? top : 0); + + for (int i = 0; i < buffer.Length; ++i) + { + // TODO: use escape sequences for better perf + Console.ForegroundColor = buffer[i].ForegroundColor; + Console.BackgroundColor = buffer[i].BackgroundColor; + + Console.Write((char)buffer[i].UnicodeChar); + } + + Console.BackgroundColor = backgroundColor; + Console.ForegroundColor = foregroundColor; + } + + public void ScrollBuffer(int lines) + { + for (int i=0; i(Func func) { -#if LINUX // TODO: move to IConsole when there is a Linux IConsole implementation - bool psReadlineControlCMode = Console.TreatControlCAsInput; - try - { - Console.TreatControlCAsInput = _prePSReadlineControlCMode; - return func(); - } - finally - { - Console.TreatControlCAsInput = psReadlineControlCMode; - } -#else - uint psReadlineConsoleMode = _console.GetConsoleInputMode(); + var currentMode = _console.GetConsoleInputMode(); try { - _console.SetConsoleInputMode(_prePSReadlineConsoleMode); + _console.RestoreConsoleInputMode(_savedConsoleInputMode); return func(); } finally { - _console.SetConsoleInputMode(psReadlineConsoleMode); + _console.RestoreConsoleInputMode(currentMode); } -#endif } void CalloutUsingDefaultConsoleMode(Action action) @@ -519,7 +479,11 @@ void ProcessOneKey(ConsoleKeyInfo key, Dictionary di private PSConsoleReadLine() { _mockableMethods = this; +#if LINUX + _console = new TTYConsole(); +#else _console = new ConhostConsole(); +#endif SetDefaultWindowsBindings(); @@ -788,13 +752,11 @@ public static void DigitArgument(ConsoleKeyInfo? key = null, object arg = null) return; } - #region VI special case if (_singleton._options.EditMode == EditMode.Vi && key.Value.KeyChar == '0') { BeginningOfLine(); return; } - #endregion VI special case bool sawDigit = false; _singleton._statusLinePrompt = "digit-argument: "; diff --git a/PSReadLine/Render.cs b/PSReadLine/Render.cs index 876dc3f66..1d468fa33 100644 --- a/PSReadLine/Render.cs +++ b/PSReadLine/Render.cs @@ -13,6 +13,7 @@ namespace Microsoft.PowerShell { public partial class PSConsoleReadLine { + private const ConsoleColor UnknownColor = (ConsoleColor) (-1); private CHAR_INFO[] _consoleBuffer; private int _initialX; private int _initialY; @@ -464,8 +465,8 @@ private void MaybeEmphasize(ref CHAR_INFO charInfo, int i, ConsoleColor foregrou // but looks best with the 2 default color schemes - starting PowerShell // from it's shortcut or from a cmd shortcut. #if LINUX // TODO: set Inverse attribute and let render choose what to do. - ConsoleColor tempColor = ((int)foregroundColor == -1) ? ConsoleColor.White : foregroundColor; - foregroundColor = ((int)backgroundColor == -1) ? ConsoleColor.Black : backgroundColor; + ConsoleColor tempColor = (foregroundColor == UnknownColor) ? ConsoleColor.White : foregroundColor; + foregroundColor = (backgroundColor == UnknownColor) ? ConsoleColor.Black : backgroundColor; backgroundColor = tempColor; #else foregroundColor = (ConsoleColor)((int)foregroundColor ^ 7); From 389b3eaa8a1988073accab76dd846794272eb08d Mon Sep 17 00:00:00 2001 From: "Jason Shirk (POWERSHELL)" Date: Thu, 7 Jul 2016 11:45:08 -0700 Subject: [PATCH 37/58] Only use CHAR_INFO on Windows CHAR_INFO has 4 bits for ConsoleColor. On Linux, ConsoleColor is sometimes -1 (unknown), which is a 17th possible value for ConsoleColor, which can't be represented in CHAR_INFO. To fix this, I've introduced a bigger type that gets converted to CHAR_INFO when necessary. --- PSReadLine/Completion.cs | 14 +-- PSReadLine/ConsoleBufferBuilder.cs | 10 +- PSReadLine/ConsoleLib.cs | 143 ++++++++++++++++++----------- PSReadLine/PublicAPI.cs | 6 +- PSReadLine/ReadLine.cs | 7 +- PSReadLine/Render.cs | 28 +++--- 6 files changed, 120 insertions(+), 88 deletions(-) diff --git a/PSReadLine/Completion.cs b/PSReadLine/Completion.cs index cba45cd01..3daa6b948 100644 --- a/PSReadLine/Completion.cs +++ b/PSReadLine/Completion.cs @@ -298,24 +298,14 @@ private static string GetReplacementTextForDirectory(string replacementText, ref return replacementText; } - private static void InvertSelectedCompletion(CHAR_INFO[] buffer, int selectedItem, int menuColumnWidth, int menuRows) + private static void InvertSelectedCompletion(BufferChar[] buffer, int selectedItem, int menuColumnWidth, int menuRows) { var selectedX = selectedItem / menuRows; var selectedY = selectedItem - (selectedX * menuRows); var start = selectedY * _singleton._console.BufferWidth + selectedX * menuColumnWidth; for (int i = 0; i < menuColumnWidth; i++) { - int j = i + start; -#if LINUX // TODO: use real inverse - ConsoleColor tempColor = buffer[j].ForegroundColor == UnknownColor - ? ConsoleColor.White : buffer[j].ForegroundColor; - buffer[j].ForegroundColor = buffer[j].BackgroundColor == UnknownColor - ? ConsoleColor.Black : buffer[j].BackgroundColor; - buffer[j].BackgroundColor = tempColor; -#else - buffer[j].ForegroundColor = (ConsoleColor)((int)buffer[j].ForegroundColor ^ 7); - buffer[j].BackgroundColor = (ConsoleColor)((int)buffer[j].BackgroundColor ^ 7); -#endif + buffer[i + start].Inverse = true; } } diff --git a/PSReadLine/ConsoleBufferBuilder.cs b/PSReadLine/ConsoleBufferBuilder.cs index d839e4ed9..fad206fcc 100644 --- a/PSReadLine/ConsoleBufferBuilder.cs +++ b/PSReadLine/ConsoleBufferBuilder.cs @@ -10,18 +10,18 @@ namespace Microsoft.PowerShell { internal class ConsoleBufferBuilder { - private List buffer; + private List buffer; private IConsole _console; public ConsoleBufferBuilder(int capacity, IConsole console) { - buffer = new List(capacity); + buffer = new List(capacity); _console = console; } - CHAR_INFO NewCharInfo(char c) + BufferChar NewCharInfo(char c) { - return new CHAR_INFO + return new BufferChar { UnicodeChar = c, BackgroundColor = _console.BackgroundColor, @@ -45,7 +45,7 @@ public void Append(char c, int count) } } - public CHAR_INFO[] ToArray() + public BufferChar[] ToArray() { return buffer.ToArray(); } diff --git a/PSReadLine/ConsoleLib.cs b/PSReadLine/ConsoleLib.cs index 03be91594..e985f4d43 100644 --- a/PSReadLine/ConsoleLib.cs +++ b/PSReadLine/ConsoleLib.cs @@ -309,60 +309,63 @@ internal struct CONSOLE_FONT_INFO_EX internal string FontFace; } - public struct CHAR_INFO + public struct BufferChar { - public ushort UnicodeChar; - public ushort Attributes; - - public CHAR_INFO(char c, ConsoleColor foreground, ConsoleColor background) - { - UnicodeChar = c; - Attributes = (ushort)((((int)background << 4) & 0xf) | ((int)foreground & 0xf)); - } + public char UnicodeChar; + public ConsoleColor ForegroundColor; + public ConsoleColor BackgroundColor; +#if !LINUX + public bool IsLeadByte; + public bool IsTrailByte; +#endif + public bool Inverse; - [ExcludeFromCodeCoverage] - public ConsoleColor ForegroundColor +#if !LINUX + public CHAR_INFO ToCharInfo() { - get { return (ConsoleColor)(Attributes & 0xf); } - set { Attributes = (ushort)((Attributes & 0xfff0) | ((int)value & 0xf)); } - } + int fg = (int) ForegroundColor; + int bg = (int) BackgroundColor; - [ExcludeFromCodeCoverage] - public ConsoleColor BackgroundColor - { - get { return (ConsoleColor)((Attributes & 0x00f0) >> 4); } - set { Attributes = (ushort)((Attributes & 0xff0f) | (((int)value & 0xf) << 4)); } - } + if (fg < 0 || fg > 0xf || bg < 0 || bg > 0xf) + throw new InvalidOperationException(); - [ExcludeFromCodeCoverage] - public override string ToString() - { - var sb = new StringBuilder(); - sb.Append((char)UnicodeChar); - if (ForegroundColor != Console.ForegroundColor) - sb.AppendFormat(" fg: {0}", ForegroundColor); - if (BackgroundColor != Console.BackgroundColor) - sb.AppendFormat(" bg: {0}", BackgroundColor); - return sb.ToString(); - } - - [ExcludeFromCodeCoverage] - public override bool Equals(object obj) - { - if (!(obj is CHAR_INFO)) + if (Inverse) { - return false; + // TODO: check $host.UI.SupportsVirtualTerminal and maybe set Inverse instead (it does look weird) + fg = fg ^ 7; + bg = bg ^ 7; } + ushort attrs = (ushort)(fg | (bg << 4)); + if (IsLeadByte) + attrs |= (ushort)CHAR_INFO_Attributes.COMMON_LVB_LEADING_BYTE; + if (IsTrailByte) + attrs |= (ushort)CHAR_INFO_Attributes.COMMON_LVB_TRAILING_BYTE; + CHAR_INFO result = new CHAR_INFO + { + UnicodeChar = UnicodeChar, + Attributes = attrs, + }; - var other = (CHAR_INFO)obj; - return this.UnicodeChar == other.UnicodeChar && this.Attributes == other.Attributes; + return result; } - [ExcludeFromCodeCoverage] - public override int GetHashCode() + public static BufferChar FromCharInfo(CHAR_INFO charInfo) { - return UnicodeChar.GetHashCode() + Attributes.GetHashCode(); + BufferChar result = new BufferChar + { + UnicodeChar = (char) charInfo.UnicodeChar, + ForegroundColor = (ConsoleColor)(charInfo.Attributes & 0xf), + BackgroundColor = (ConsoleColor)((charInfo.Attributes & 0x00f0) >> 4), + }; + return result; } +#endif + } + + public struct CHAR_INFO + { + public ushort UnicodeChar; + public ushort Attributes; } internal static class ConsoleKeyInfoExtension @@ -611,12 +614,12 @@ public void WriteLine(string value) Console.WriteLine(value); } - public void WriteBufferLines(CHAR_INFO[] buffer, ref int top) + public void WriteBufferLines(BufferChar[] buffer, ref int top) { WriteBufferLines(buffer, ref top, true); } - public void WriteBufferLines(CHAR_INFO[] buffer, ref int top, bool ensureBottomLineVisible) + public void WriteBufferLines(BufferChar[] buffer, ref int top, bool ensureBottomLineVisible) { int bufferWidth = Console.BufferWidth; int bufferLineCount = buffer.Length / bufferWidth; @@ -642,7 +645,7 @@ public void WriteBufferLines(CHAR_INFO[] buffer, ref int top, bool ensureBottomL Bottom = (short) bottom, Right = (short) (bufferWidth - 1) }; - NativeMethods.WriteConsoleOutput(handle, buffer, + NativeMethods.WriteConsoleOutput(handle, ToCharInfoBuffer(buffer), bufferSize, bufferCoord, ref writeRegion); // Now make sure the bottom line is visible @@ -665,11 +668,15 @@ public void ScrollBuffer(int lines) Right = (short)Console.BufferWidth }; var destinationOrigin = new COORD {X = 0, Y = 0}; - var fillChar = new CHAR_INFO(' ', Console.ForegroundColor, Console.BackgroundColor); + var fillChar = new CHAR_INFO + { + UnicodeChar = ' ', + Attributes = (ushort)((int)Console.ForegroundColor | ((int)Console.BackgroundColor << 4)) + }; NativeMethods.ScrollConsoleScreenBuffer(handle, ref scrollRectangle, IntPtr.Zero, destinationOrigin, ref fillChar); } - public CHAR_INFO[] ReadBufferLines(int top, int count) + public BufferChar[] ReadBufferLines(int top, int count) { var result = new CHAR_INFO[BufferWidth * count]; var handle = NativeMethods.GetStdHandle((uint) StandardHandleId.Output); @@ -688,7 +695,7 @@ public CHAR_INFO[] ReadBufferLines(int top, int count) NativeMethods.ReadConsoleOutput(handle, result, readBufferSize, readBufferCoord, ref readRegion); - return result; + return ToBufferCharBuffer(result); } [SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", @@ -882,6 +889,35 @@ public void EndRender() NativeMethods.ReleaseDC(_hwnd, _hDC); } } + + private CHAR_INFO[] cachedBuffer; + private CHAR_INFO[] ToCharInfoBuffer(BufferChar[] buffer) + { + if (cachedBuffer == null || cachedBuffer.Length != buffer.Length) + { + cachedBuffer = new CHAR_INFO[buffer.Length]; + } + + for (int i = 0; i < buffer.Length; i++) + { + cachedBuffer[i] = buffer[i].ToCharInfo(); + } + + return cachedBuffer; + } + + private BufferChar[] ToBufferCharBuffer(CHAR_INFO[] buffer) + { + var result = new BufferChar[buffer.Length]; + + for (int i = 0; i < buffer.Length; i++) + { + result[i] = BufferChar.FromCharInfo(buffer[i]); + } + + return result; + } + } #else @@ -996,12 +1032,12 @@ public void WriteLine(string value) Console.WriteLine(value); } - public void WriteBufferLines(CHAR_INFO[] buffer, ref int top) + public void WriteBufferLines(BufferChar[] buffer, ref int top) { WriteBufferLines(buffer, ref top, true); } - public void WriteBufferLines(CHAR_INFO[] buffer, ref int top, bool ensureBottomLineVisible) + public void WriteBufferLines(BufferChar[] buffer, ref int top, bool ensureBottomLineVisible) { int bufferWidth = Console.BufferWidth; int bufferLineCount = buffer.Length / bufferWidth; @@ -1023,7 +1059,7 @@ public void WriteBufferLines(CHAR_INFO[] buffer, ref int top, bool ensureBottomL Console.ForegroundColor = buffer[i].ForegroundColor; Console.BackgroundColor = buffer[i].BackgroundColor; - Console.Write((char)buffer[i].UnicodeChar); + Console.Write(buffer[i].UnicodeChar); } Console.BackgroundColor = backgroundColor; @@ -1039,9 +1075,9 @@ public void ScrollBuffer(int lines) } } - public CHAR_INFO[] ReadBufferLines(int top, int count) + public BufferChar[] ReadBufferLines(int top, int count) { - var result = new CHAR_INFO[BufferWidth * count]; + var result = new BufferChar[BufferWidth * count]; for (int i=0; i bufferLineCount * bufferWidth) { @@ -226,17 +228,17 @@ private void ReallyRender() MaybeEmphasize(ref _consoleBuffer[j++], i, foregroundColor, backgroundColor); } +#if !LINUX else if (size > 1) { _consoleBuffer[j].UnicodeChar = charToRender; - _consoleBuffer[j].Attributes = (ushort)(_consoleBuffer[j].Attributes | - (uint)CHAR_INFO_Attributes.COMMON_LVB_LEADING_BYTE); + _consoleBuffer[j].IsLeadByte = true; MaybeEmphasize(ref _consoleBuffer[j++], i, foregroundColor, backgroundColor); _consoleBuffer[j].UnicodeChar = charToRender; - _consoleBuffer[j].Attributes = (ushort)(_consoleBuffer[j].Attributes | - (uint)CHAR_INFO_Attributes.COMMON_LVB_TRAILING_BYTE); + _consoleBuffer[j].IsTrailByte = true; MaybeEmphasize(ref _consoleBuffer[j++], i, foregroundColor, backgroundColor); } +#endif else { _consoleBuffer[j].UnicodeChar = charToRender; @@ -286,7 +288,7 @@ private void ReallyRender() while (promptChar >= 0) { - var c = (char)_consoleBuffer[promptChar].UnicodeChar; + var c = _consoleBuffer[promptChar].UnicodeChar; if (char.IsWhiteSpace(c)) { promptChar -= 1; @@ -332,7 +334,7 @@ private int LengthInBufferCells(char c) private static void WriteBlankLines(int count, int top) { var console = _singleton._console; - var blanks = new CHAR_INFO[count * console.BufferWidth]; + var blanks = new BufferChar[count * console.BufferWidth]; for (int i = 0; i < blanks.Length; i++) { blanks[i].BackgroundColor = console.BackgroundColor; @@ -342,7 +344,7 @@ private static void WriteBlankLines(int count, int top) console.WriteBufferLines(blanks, ref top); } - private static CHAR_INFO[] ReadBufferLines(int top, int count) + private static BufferChar[] ReadBufferLines(int top, int count) { return _singleton._console.ReadBufferLines(top, count); } @@ -450,7 +452,7 @@ private bool InRegion(int i) return i >= start && i < end; } - private void MaybeEmphasize(ref CHAR_INFO charInfo, int i, ConsoleColor foregroundColor, ConsoleColor backgroundColor) + private void MaybeEmphasize(ref BufferChar charInfo, int i, ConsoleColor foregroundColor, ConsoleColor backgroundColor) { if (i >= _emphasisStart && i < (_emphasisStart + _emphasisLength)) { @@ -682,7 +684,7 @@ private bool PromptYesOrNo(string s) return key.Key == ConsoleKey.Y; } - #region Screen scrolling +#region Screen scrolling #if !LINUX /// @@ -804,6 +806,6 @@ public static void ScrollDisplayToCursor(ConsoleKeyInfo? key = null, object arg } #endif - #endregion Screen scrolling +#endregion Screen scrolling } } From 2abb380c64fe26811afe10b7c704e3003791eafd Mon Sep 17 00:00:00 2001 From: "Jason Shirk (POWERSHELL)" Date: Thu, 7 Jul 2016 12:07:06 -0700 Subject: [PATCH 38/58] Skip tone/duration on beep on LINUX --- PSReadLine/Render.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/PSReadLine/Render.cs b/PSReadLine/Render.cs index c6f14bc7a..6a232bf84 100644 --- a/PSReadLine/Render.cs +++ b/PSReadLine/Render.cs @@ -656,7 +656,11 @@ void IPSConsoleReadLineMockableMethods.Ding() case BellStyle.None: break; case BellStyle.Audible: +#if LINUX + Console.Beep(); +#else Console.Beep(Options.DingTone, Options.DingDuration); +#endif break; case BellStyle.Visual: // TODO: flash prompt? command line? From 6f67e9caa473521718657db6ef665be91037c992 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 15 Jul 2016 13:38:55 -0700 Subject: [PATCH 39/58] Refactor switch into SetDefaultBindings(EditMode) --- PSReadLine/KeyBindings.cs | 19 +++++++++++++++++++ PSReadLine/Options.cs | 13 +------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/PSReadLine/KeyBindings.cs b/PSReadLine/KeyBindings.cs index aae97e503..b543aef8a 100644 --- a/PSReadLine/KeyBindings.cs +++ b/PSReadLine/KeyBindings.cs @@ -114,6 +114,25 @@ static KeyHandler MakeKeyHandler(Action action, string private Dictionary _dispatchTable; private Dictionary> _chordDispatchTable; + /// + /// Helper to set bindings based on EditMode + /// + void SetDefaultBindings(EditMode editMode) + { + switch (editMode) + { + case EditMode.Emacs: + SetDefaultEmacsBindings(); + break; + case EditMode.Vi: + SetDefaultViBindings(); + break; + case EditMode.Windows: + SetDefaultWindowsBindings(); + break; + } + } + void SetDefaultWindowsBindings() { _dispatchTable = new Dictionary(new ConsoleKeyInfoComparer()) diff --git a/PSReadLine/Options.cs b/PSReadLine/Options.cs index d8162b743..b927282e2 100644 --- a/PSReadLine/Options.cs +++ b/PSReadLine/Options.cs @@ -96,18 +96,7 @@ private void SetOptionsInternal(SetPSReadlineOption options) // Switching/resetting modes - clear out chord dispatch table _chordDispatchTable.Clear(); - switch (options._editMode) - { - case EditMode.Emacs: - SetDefaultEmacsBindings(); - break; - case EditMode.Vi: - SetDefaultViBindings(); - break; - case EditMode.Windows: - SetDefaultWindowsBindings(); - break; - } + SetDefaultBindings(Options.EditMode); } if (options._showToolTips.HasValue) { From 4cb0f22e0313199576529b7041ad3f4027096663 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 15 Jul 2016 13:39:29 -0700 Subject: [PATCH 40/58] Set bindings based on options This is instead of hard-coding a call to SetDefaultWindowsBindings(). --- PSReadLine/ReadLine.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/PSReadLine/ReadLine.cs b/PSReadLine/ReadLine.cs index c2848f054..75654e21d 100644 --- a/PSReadLine/ReadLine.cs +++ b/PSReadLine/ReadLine.cs @@ -485,8 +485,6 @@ private PSConsoleReadLine() _console = new ConhostConsole(); #endif - SetDefaultWindowsBindings(); - _buffer = new StringBuilder(8 * 1024); _statusBuffer = new StringBuilder(256); _savedCurrentLine = new HistoryItem(); @@ -516,6 +514,7 @@ private PSConsoleReadLine() hostName = "PSReadline"; } _options = new PSConsoleReadlineOptions(hostName); + SetDefaultBindings(_options.EditMode); } private void Initialize(Runspace runspace, EngineIntrinsics engineIntrinsics) From 97e4fefb72ff8d6e90ade4db85e59200e52d24f8 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 15 Jul 2016 13:40:16 -0700 Subject: [PATCH 41/58] Set DefaultEditMode to Emacs on Linux / OS X --- PSReadLine/Cmdlets.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/PSReadLine/Cmdlets.cs b/PSReadLine/Cmdlets.cs index 514eed8ed..fbd0c867c 100644 --- a/PSReadLine/Cmdlets.cs +++ b/PSReadLine/Cmdlets.cs @@ -92,7 +92,12 @@ public class PSConsoleReadlineOptions public const ConsoleColor DefaultEmphasisForegroundColor = ConsoleColor.Cyan; public const ConsoleColor DefaultErrorForegroundColor = ConsoleColor.Red; - public const EditMode DefaultEditMode = EditMode.Windows; + public const EditMode DefaultEditMode = +#if LINUX + EditMode.Emacs; +#else + EditMode.Windows; +#endif public const string DefaultContinuationPrompt = ">> "; From 07e1fba51ee3b991a82548eecae049a2eeba9646 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 18 Jul 2016 18:21:40 -0700 Subject: [PATCH 42/58] Enable XML documentation generation This is enabled for PowerShell projects, but not PackageManagment, WSMan, Cim, or MMI. --- PSReadLine/project.json | 1 + 1 file changed, 1 insertion(+) diff --git a/PSReadLine/project.json b/PSReadLine/project.json index f8f9ba1f1..5addba2b9 100644 --- a/PSReadLine/project.json +++ b/PSReadLine/project.json @@ -3,6 +3,7 @@ "version": "1.0.0-*", "buildOptions": { + "xmlDoc": true, "keyFile": "../signing/visualstudiopublic.snk", "delaySign": true, "publicSign": false, From f7be60bfac1f1de7e6a0f48499de9e4539d15e75 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 18 Jul 2016 18:23:29 -0700 Subject: [PATCH 43/58] Fix some documentation warnings Mostly low-hanging fruit and Linux additions/changes. --- PSReadLine/ReadLine.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/PSReadLine/ReadLine.cs b/PSReadLine/ReadLine.cs index 75654e21d..3601670c7 100644 --- a/PSReadLine/ReadLine.cs +++ b/PSReadLine/ReadLine.cs @@ -876,6 +876,11 @@ public static void InvokePrompt(ConsoleKeyInfo? key = null, object arg = null) _singleton.Render(); } + /// + /// Gets the current prompt as possibly defined by the user through the + /// prompt function, and returns a default prompt if no other is + /// available. Also handles remote prompts. + /// public static string GetPrompt() { var runspaceIsRemote = _singleton._mockableMethods.RunspaceIsRemote(_singleton._runspace); From 355753912530d8b49f424e72278486b81f6bb615 Mon Sep 17 00:00:00 2001 From: "Jason Shirk (POWERSHELL)" Date: Fri, 22 Jul 2016 10:49:45 -0700 Subject: [PATCH 44/58] Change preprocessor macro LINUX to UNIX --- PSReadLine/Cmdlets.cs | 6 +++--- PSReadLine/ConsoleKeyChordConverter.cs | 4 ++-- PSReadLine/ConsoleLib.cs | 8 ++++---- PSReadLine/KeyBindings.cs | 6 +++--- PSReadLine/KeyBindings.vi.cs | 4 ++-- PSReadLine/Keys.cs | 2 +- PSReadLine/Movement.cs | 2 +- PSReadLine/PublicAPI.cs | 2 +- PSReadLine/ReadLine.cs | 12 ++++++------ PSReadLine/Render.cs | 12 ++++++------ PSReadLine/ScreenCapture.cs | 2 +- PSReadLine/project.json | 2 +- 12 files changed, 31 insertions(+), 31 deletions(-) diff --git a/PSReadLine/Cmdlets.cs b/PSReadLine/Cmdlets.cs index fbd0c867c..47a7a8118 100644 --- a/PSReadLine/Cmdlets.cs +++ b/PSReadLine/Cmdlets.cs @@ -73,7 +73,7 @@ public enum HistorySaveStyle public class PSConsoleReadlineOptions { -#if LINUX // TODO: why different schemes for LINUX? +#if UNIX // TODO: why different schemes for LINUX? public const ConsoleColor DefaultCommentForegroundColor = ConsoleColor.Magenta; public const ConsoleColor DefaultOperatorForegroundColor = ConsoleColor.Gray; public const ConsoleColor DefaultParameterForegroundColor = ConsoleColor.Green; @@ -93,7 +93,7 @@ public class PSConsoleReadlineOptions public const ConsoleColor DefaultErrorForegroundColor = ConsoleColor.Red; public const EditMode DefaultEditMode = -#if LINUX +#if UNIX EditMode.Emacs; #else EditMode.Windows; @@ -168,7 +168,7 @@ public PSConsoleReadlineOptions(string hostName) HistorySaveStyle = DefaultHistorySaveStyle; string historyFileName = hostName + "_history.txt"; -#if LINUX +#if UNIX // PSReadline does not have access to Utils.CorePSPlatform. Must set PSReadline path separately string historyPath = System.Environment.GetEnvironmentVariable("XDG_DATA_HOME"); diff --git a/PSReadLine/ConsoleKeyChordConverter.cs b/PSReadLine/ConsoleKeyChordConverter.cs index 32722153d..eb108b41e 100644 --- a/PSReadLine/ConsoleKeyChordConverter.cs +++ b/PSReadLine/ConsoleKeyChordConverter.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; -#if LINUX +#if UNIX using System.Reflection; #endif using System.Runtime.InteropServices; @@ -214,7 +214,7 @@ internal static char GetCharFromConsoleKey(ConsoleKey key, ConsoleModifiers modi { // default for unprintables and unhandled char keyChar = '\u0000'; -#if LINUX +#if UNIX Type keyType = typeof (Keys); FieldInfo[] keyFields = keyType.GetFields(); diff --git a/PSReadLine/ConsoleLib.cs b/PSReadLine/ConsoleLib.cs index e985f4d43..17ef3de2a 100644 --- a/PSReadLine/ConsoleLib.cs +++ b/PSReadLine/ConsoleLib.cs @@ -314,13 +314,13 @@ public struct BufferChar public char UnicodeChar; public ConsoleColor ForegroundColor; public ConsoleColor BackgroundColor; -#if !LINUX +#if !UNIX public bool IsLeadByte; public bool IsTrailByte; #endif public bool Inverse; -#if !LINUX +#if !UNIX public CHAR_INFO ToCharInfo() { int fg = (int) ForegroundColor; @@ -386,7 +386,7 @@ public static string ToGestureString(this ConsoleKeyInfo key) sb.Append("Alt"); } -#if LINUX +#if UNIX if (sb.Length > 0) sb.Append("+"); // TODO: find better way to map these characters to something more friendly @@ -429,7 +429,7 @@ public static string ToGestureString(this ConsoleKeyInfo key) } } -#if !LINUX +#if !UNIX internal class ConhostConsole : IConsole { [SuppressMessage("Microsoft.Reliability", "CA2006:UseSafeHandleToEncapsulateNativeResources")] diff --git a/PSReadLine/KeyBindings.cs b/PSReadLine/KeyBindings.cs index b543aef8a..f4843b3c4 100644 --- a/PSReadLine/KeyBindings.cs +++ b/PSReadLine/KeyBindings.cs @@ -161,7 +161,7 @@ void SetDefaultWindowsBindings() { Keys.CtrlSpace, MakeKeyHandler(MenuComplete, "MenuComplete") }, { Keys.Tab, MakeKeyHandler(TabCompleteNext, "TabCompleteNext") }, { Keys.ShiftTab, MakeKeyHandler(TabCompletePrevious, "TabCompletePrevious") }, -#if !LINUX +#if !UNIX { Keys.VolumeDown, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeUp, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeMute, MakeKeyHandler(Ignore, "Ignore") }, @@ -200,7 +200,7 @@ void SetDefaultWindowsBindings() { Keys.ShiftF3, MakeKeyHandler(CharacterSearchBackward, "CharacterSearchBackward") }, { Keys.F8, MakeKeyHandler(HistorySearchBackward, "HistorySearchBackward") }, { Keys.ShiftF8, MakeKeyHandler(HistorySearchForward, "HistorySearchForward") }, -#if !LINUX +#if !UNIX { Keys.PageUp, MakeKeyHandler(ScrollDisplayUp, "ScrollDisplayUp") }, { Keys.PageDown, MakeKeyHandler(ScrollDisplayDown, "ScrollDisplayDown") }, { Keys.CtrlPageUp, MakeKeyHandler(ScrollDisplayUpLine, "ScrollDisplayUpLine") }, @@ -284,7 +284,7 @@ void SetDefaultEmacsBindings() { Keys.AltPeriod, MakeKeyHandler(YankLastArg, "YankLastArg") }, { Keys.AltUnderbar, MakeKeyHandler(YankLastArg, "YankLastArg") }, { Keys.AltCtrlY, MakeKeyHandler(YankNthArg, "YankNthArg") }, -#if !LINUX +#if !UNIX { Keys.VolumeDown, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeUp, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeMute, MakeKeyHandler(Ignore, "Ignore") }, diff --git a/PSReadLine/KeyBindings.vi.cs b/PSReadLine/KeyBindings.vi.cs index 29cfa61b3..eb6f76da6 100644 --- a/PSReadLine/KeyBindings.vi.cs +++ b/PSReadLine/KeyBindings.vi.cs @@ -70,7 +70,7 @@ private void SetDefaultViBindings() { Keys.Tab, MakeKeyHandler(ViTabCompleteNext, "ViTabCompleteNext") }, { Keys.ShiftTab, MakeKeyHandler(ViTabCompletePrevious, "ViTabCompletePrevious") }, { Keys.CtrlV, MakeKeyHandler(Paste, "Paste") }, -#if !LINUX +#if !UNIX { Keys.VolumeDown, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeUp, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeMute, MakeKeyHandler(Ignore, "Ignore") }, @@ -109,7 +109,7 @@ private void SetDefaultViBindings() { Keys.Tab, MakeKeyHandler(TabCompleteNext, "TabCompleteNext") }, { Keys.ShiftTab, MakeKeyHandler(TabCompletePrevious, "TabCompletePrevious") }, { Keys.CtrlV, MakeKeyHandler(Paste, "Paste") }, -#if !LINUX +#if !UNIX { Keys.VolumeDown, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeUp, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeMute, MakeKeyHandler(Ignore, "Ignore") }, diff --git a/PSReadLine/Keys.cs b/PSReadLine/Keys.cs index 94c566716..25b594441 100644 --- a/PSReadLine/Keys.cs +++ b/PSReadLine/Keys.cs @@ -290,7 +290,7 @@ internal static class Keys public static ConsoleKeyInfo ShiftF8 = new ConsoleKeyInfo((char)0, ConsoleKey.F8, true, false, false); // Keys to ignore -#if !LINUX +#if !UNIX public static ConsoleKeyInfo VolumeUp = new ConsoleKeyInfo((char)0, /*ConsoleKey.VolumeUp*/(ConsoleKey)175, false, false, false); public static ConsoleKeyInfo VolumeDown = new ConsoleKeyInfo((char)0, /*ConsoleKey.VolumeDown*/(ConsoleKey)174, false, false, false); public static ConsoleKeyInfo VolumeMute = new ConsoleKeyInfo((char)0, /*ConsoleKey.VolumeMute*/(ConsoleKey)173, false, false, false); diff --git a/PSReadLine/Movement.cs b/PSReadLine/Movement.cs index 52c1983f0..a413ef63d 100644 --- a/PSReadLine/Movement.cs +++ b/PSReadLine/Movement.cs @@ -434,7 +434,7 @@ public static void GotoBrace(ConsoleKeyInfo? key = null, object arg = null) public static void ClearScreen(ConsoleKeyInfo? key = null, object arg = null) { var console = _singleton._console; -#if LINUX // TODO: this is not correct, it should only scroll +#if UNIX // TODO: this is not correct, it should only scroll console.Clear(); _singleton._initialY = 0; _singleton.Render(); diff --git a/PSReadLine/PublicAPI.cs b/PSReadLine/PublicAPI.cs index 03f1d6707..8827a0970 100644 --- a/PSReadLine/PublicAPI.cs +++ b/PSReadLine/PublicAPI.cs @@ -55,7 +55,7 @@ public interface IConsole void StartRender(); int LengthInBufferCells(char c); void EndRender(); -#if LINUX +#if UNIX void Clear(); #endif } diff --git a/PSReadLine/ReadLine.cs b/PSReadLine/ReadLine.cs index 3601670c7..609a31958 100644 --- a/PSReadLine/ReadLine.cs +++ b/PSReadLine/ReadLine.cs @@ -34,7 +34,7 @@ public partial class PSConsoleReadLine : IPSConsoleReadLineMockableMethods private IConsole _console; private EngineIntrinsics _engineIntrinsics; -#if !LINUX +#if !UNIX private static GCHandle _breakHandlerGcHandle; #endif private Thread _readKeyThread; @@ -479,7 +479,7 @@ void ProcessOneKey(ConsoleKeyInfo key, Dictionary di private PSConsoleReadLine() { _mockableMethods = this; -#if LINUX +#if UNIX _console = new TTYConsole(); #else _console = new ConhostConsole(); @@ -558,7 +558,7 @@ private void Initialize(Runspace runspace, EngineIntrinsics engineIntrinsics) _statusIsErrorMessage = false; _consoleBuffer = ReadBufferLines(_initialY, 1 + Options.ExtraPromptLineCount); -#if LINUX // TODO: not necessary if ReadBufferLines worked, or if rendering worked on spans instead of complete lines +#if UNIX // TODO: not necessary if ReadBufferLines worked, or if rendering worked on spans instead of complete lines string newPrompt = GetPrompt(); for (int i=0; i(Options.MaximumKillRingCount); -#if !LINUX +#if !UNIX _breakHandlerGcHandle = GCHandle.Alloc(new BreakHandler(_singleton.BreakHandler)); NativeMethods.SetConsoleCtrlHandler((BreakHandler)_breakHandlerGcHandle.Target, true); #endif @@ -865,7 +865,7 @@ public static void InvokePrompt(ConsoleKeyInfo? key = null, object arg = null) _singleton._initialX = _singleton._console.CursorLeft; _singleton._consoleBuffer = ReadBufferLines(_singleton._initialY, 1 + _singleton.Options.ExtraPromptLineCount); -#if LINUX // TODO: ReadBufferLines only needed for extra line, but doesn't work on Linux +#if UNIX // TODO: ReadBufferLines only needed for extra line, but doesn't work on Linux for (int i=0; i 1) { _consoleBuffer[j].UnicodeChar = charToRender; @@ -313,7 +313,7 @@ private void ReallyRender() if ((_initialY + bufferLineCount) > (_console.WindowTop + _console.WindowHeight)) { -#if !LINUX // TODO: verify this isn't necessary for LINUX +#if !UNIX // TODO: verify this isn't necessary for LINUX _console.WindowTop = _initialY + bufferLineCount - _console.WindowHeight; #endif } @@ -466,7 +466,7 @@ private void MaybeEmphasize(ref BufferChar charInfo, int i, ConsoleColor foregro // to invert only the lower 3 bits to change the color is somewhat // but looks best with the 2 default color schemes - starting PowerShell // from it's shortcut or from a cmd shortcut. -#if LINUX // TODO: set Inverse attribute and let render choose what to do. +#if UNIX // TODO: set Inverse attribute and let render choose what to do. ConsoleColor tempColor = (foregroundColor == UnknownColor) ? ConsoleColor.White : foregroundColor; foregroundColor = (backgroundColor == UnknownColor) ? ConsoleColor.Black : backgroundColor; backgroundColor = tempColor; @@ -656,7 +656,7 @@ void IPSConsoleReadLineMockableMethods.Ding() case BellStyle.None: break; case BellStyle.Audible: -#if LINUX +#if UNIX Console.Beep(); #else Console.Beep(Options.DingTone, Options.DingDuration); @@ -690,7 +690,7 @@ private bool PromptYesOrNo(string s) #region Screen scrolling -#if !LINUX +#if !UNIX /// /// Scroll the display up one screen. /// diff --git a/PSReadLine/ScreenCapture.cs b/PSReadLine/ScreenCapture.cs index 85bfcc42b..e35d83a5c 100644 --- a/PSReadLine/ScreenCapture.cs +++ b/PSReadLine/ScreenCapture.cs @@ -2,7 +2,7 @@ Copyright (c) Microsoft Corporation. All rights reserved. --********************************************************************/ -#if !LINUX +#if !UNIX using System; using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; diff --git a/PSReadLine/project.json b/PSReadLine/project.json index 5addba2b9..ca228c8a6 100644 --- a/PSReadLine/project.json +++ b/PSReadLine/project.json @@ -13,7 +13,7 @@ "configurations": { "Linux": { "buildOptions": { - "define": [ "LINUX" ] + "define": [ "UNIX" ] } } }, From 09d76f74962f73b56fc36f2ff1ff50860bdaf5c8 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 19 Jul 2016 14:09:13 -0700 Subject: [PATCH 45/58] Remove GetCharFromConsoleKey The ConsoleKey enum does not necessarily cover all possible chars. Moreover, the times we need to obtain this info, we already have it. --- PSReadLine/ConsoleKeyChordConverter.cs | 52 ++------------------------ PSReadLine/ConsoleLib.cs | 3 +- 2 files changed, 5 insertions(+), 50 deletions(-) diff --git a/PSReadLine/ConsoleKeyChordConverter.cs b/PSReadLine/ConsoleKeyChordConverter.cs index eb108b41e..8993fff99 100644 --- a/PSReadLine/ConsoleKeyChordConverter.cs +++ b/PSReadLine/ConsoleKeyChordConverter.cs @@ -56,6 +56,7 @@ private static ConsoleKeyInfo ConvertOneSequence(string sequence) Stack tokens = null; ConsoleModifiers modifiers = 0; ConsoleKey key = 0; + char keyChar = '\u0000'; bool valid = !String.IsNullOrEmpty(sequence); @@ -81,6 +82,9 @@ private static ConsoleKeyInfo ConvertOneSequence(string sequence) // key should be first token to be popped if (key == 0) { + // the keyChar is this token + keyChar = token[0]; + // Enum.TryParse accepts arbitrary integers. We shouldn't, // but single digits need to map to the correct key, e.g. // ConsoleKey.D1 @@ -152,8 +156,6 @@ private static ConsoleKeyInfo ConvertOneSequence(string sequence) throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, PSReadLineResources.InvalidSequence, sequence)); } - char keyChar = GetCharFromConsoleKey(key, modifiers); - return new ConsoleKeyInfo(keyChar, key, shift: ((modifiers & ConsoleModifiers.Shift) != 0), alt: ((modifiers & ConsoleModifiers.Alt) != 0), @@ -209,51 +211,5 @@ private static bool TryParseCharLiteral(char literal, ref ConsoleModifiers modif return valid; } - - internal static char GetCharFromConsoleKey(ConsoleKey key, ConsoleModifiers modifiers) - { - // default for unprintables and unhandled - char keyChar = '\u0000'; -#if UNIX - Type keyType = typeof (Keys); - FieldInfo[] keyFields = keyType.GetFields(); - - foreach (FieldInfo field in keyFields) - { - if (field.FieldType == typeof(ConsoleKeyInfo)) - { - ConsoleKeyInfo info = (ConsoleKeyInfo)field.GetValue(null); - if (info.Key == key && info.Modifiers == modifiers) - { - return info.KeyChar; - } - } - } -#else - // emulate GetKeyboardState bitmap - set high order bit for relevant modifier virtual keys - var state = new byte[256]; - state[NativeMethods.VK_SHIFT] = (byte)(((modifiers & ConsoleModifiers.Shift) != 0) ? 0x80 : 0); - state[NativeMethods.VK_CONTROL] = (byte)(((modifiers & ConsoleModifiers.Control) != 0) ? 0x80 : 0); - state[NativeMethods.VK_ALT] = (byte)(((modifiers & ConsoleModifiers.Alt) != 0) ? 0x80 : 0); - - // a ConsoleKey enum's value is a virtual key code - uint virtualKey = (uint)key; - - // get corresponding scan code - uint scanCode = NativeMethods.MapVirtualKey(virtualKey, NativeMethods.MAPVK_VK_TO_VSC); - - // get corresponding character - maybe be 0, 1 or 2 in length (diacriticals) - var chars = new char[2]; - int charCount = NativeMethods.ToUnicode( - virtualKey, scanCode, state, chars, chars.Length, NativeMethods.MENU_IS_INACTIVE); - - // TODO: support diacriticals (charCount == 2) - if (charCount == 1) - { - keyChar = chars[0]; - } -#endif - return keyChar; - } } } diff --git a/PSReadLine/ConsoleLib.cs b/PSReadLine/ConsoleLib.cs index 17ef3de2a..efb78b1d0 100644 --- a/PSReadLine/ConsoleLib.cs +++ b/PSReadLine/ConsoleLib.cs @@ -404,8 +404,7 @@ public static string ToGestureString(this ConsoleKeyInfo key) sb.Append(key.Key); } #else - char c = ConsoleKeyChordConverter.GetCharFromConsoleKey(key.Key, - (mods & ConsoleModifiers.Shift) != 0 ? ConsoleModifiers.Shift : 0); + char c = key.KeyChar; if (char.IsControl(c) || char.IsWhiteSpace(c)) { if (key.Modifiers.HasFlag(ConsoleModifiers.Shift)) From 0285870faddba5d2ecc3228a30e17f4f93210c6c Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 19 Jul 2016 16:28:00 -0700 Subject: [PATCH 46/58] Implement TryParseCharLiteral for Linux --- PSReadLine/ConsoleKeyChordConverter.cs | 96 ++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/PSReadLine/ConsoleKeyChordConverter.cs b/PSReadLine/ConsoleKeyChordConverter.cs index 8993fff99..cb5444a1e 100644 --- a/PSReadLine/ConsoleKeyChordConverter.cs +++ b/PSReadLine/ConsoleKeyChordConverter.cs @@ -166,6 +166,27 @@ private static bool TryParseCharLiteral(char literal, ref ConsoleModifiers modif { bool valid = false; +#if UNIX + bool isShift; + bool isCtrl; + key = GetKeyFromCharValue(literal, out isShift, out isCtrl); + + // Failure to get a key for the char just means that the key is not + // special (in the ConsoleKey enum), so we return a default key. + // Thus this never fails. + valid = true; + failReason = null; + + if (isShift) + { + modifiers |= ConsoleModifiers.Shift; + } + if (isCtrl) + { + modifiers |= ConsoleModifiers.Control; + } + // alt is not possible to get +#else // shift state will be in MSB short virtualKey = NativeMethods.VkKeyScan(literal); int hresult = Marshal.GetLastWin32Error(); @@ -208,8 +229,83 @@ private static bool TryParseCharLiteral(char literal, ref ConsoleModifiers modif Exception e = Marshal.GetExceptionForHR(hresult); failReason = e.Message; } +#endif return valid; } + +#if UNIX + // this is borrowed from the CoreFX internal System.IO.StdInReader class + // https://github.com/dotnet/corefx/blob/5b2ae6aa485773cd5569f56f446698633c9ad945/src/System.Console/src/System/IO/StdInReader.cs#L222 + private static ConsoleKey GetKeyFromCharValue(char x, out bool isShift, out bool isCtrl) + { + isShift = false; + isCtrl = false; + + switch (x) + { + case '\b': + return ConsoleKey.Backspace; + + case '\t': + return ConsoleKey.Tab; + + case '\n': + return ConsoleKey.Enter; + + case (char)(0x1B): + return ConsoleKey.Escape; + + case '*': + return ConsoleKey.Multiply; + + case '+': + return ConsoleKey.Add; + + case '-': + return ConsoleKey.Subtract; + + case '/': + return ConsoleKey.Divide; + + case (char)(0x7F): + return ConsoleKey.Delete; + + case ' ': + return ConsoleKey.Spacebar; + + default: + // 1. Ctrl A to Ctrl Z. + if (x >= 1 && x <= 26) + { + isCtrl = true; + return ConsoleKey.A + x - 1; + } + + // 2. Numbers from 0 to 9. + if (x >= '0' && x <= '9') + { + return ConsoleKey.D0 + x - '0'; + } + + //3. A to Z + if (x >= 'A' && x <= 'Z') + { + isShift = true; + return ConsoleKey.A + (x - 'A'); + } + + // 4. a to z. + if (x >= 'a' && x <= 'z') + { + return ConsoleKey.A + (x - 'a'); + } + + break; + } + + return default(ConsoleKey); + } +#endif } } From e2d7a803c96140cfc17e0380e853bf4d6ba41a42 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 20 Jul 2016 10:52:47 -0700 Subject: [PATCH 47/58] Revert changes made to GetGestureString Given the use of key.KeyChar, the original implementation is now portable. --- PSReadLine/ConsoleLib.cs | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/PSReadLine/ConsoleLib.cs b/PSReadLine/ConsoleLib.cs index efb78b1d0..1b3f648b0 100644 --- a/PSReadLine/ConsoleLib.cs +++ b/PSReadLine/ConsoleLib.cs @@ -386,24 +386,6 @@ public static string ToGestureString(this ConsoleKeyInfo key) sb.Append("Alt"); } -#if UNIX - if (sb.Length > 0) - sb.Append("+"); - // TODO: find better way to map these characters to something more friendly - if ((key.Key >= ConsoleKey.D0 && key.Key <= ConsoleKey.D9) - || (key.Key >= ConsoleKey.Oem1 && key.Key <= ConsoleKey.Oem8)) - { - sb.Append(key.KeyChar); - } - else - { - if (key.Modifiers.HasFlag(ConsoleModifiers.Shift)) - { - sb.Append("Shift+"); - } - sb.Append(key.Key); - } -#else char c = key.KeyChar; if (char.IsControl(c) || char.IsWhiteSpace(c)) { @@ -423,7 +405,6 @@ public static string ToGestureString(this ConsoleKeyInfo key) sb.Append("+"); sb.Append(c); } -#endif return sb.ToString(); } } From 7f10c268bff79dffa32133009befda7a8acf2922 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 20 Jul 2016 11:30:22 -0700 Subject: [PATCH 48/58] Use GetCharFromConsoleKey on Windows Due to virtual key codes on Windows, simple chords like Ctrl+] are not recognized as such. Instead, the ConsoleKey is Oem6, and the KeyChar is an control code. --- PSReadLine/ConsoleKeyChordConverter.cs | 33 +++++++++++++++++++++++--- PSReadLine/ConsoleLib.cs | 6 +++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/PSReadLine/ConsoleKeyChordConverter.cs b/PSReadLine/ConsoleKeyChordConverter.cs index cb5444a1e..a6248e8be 100644 --- a/PSReadLine/ConsoleKeyChordConverter.cs +++ b/PSReadLine/ConsoleKeyChordConverter.cs @@ -6,9 +6,6 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; -#if UNIX -using System.Reflection; -#endif using System.Runtime.InteropServices; using Microsoft.PowerShell.Internal; @@ -306,6 +303,36 @@ private static ConsoleKey GetKeyFromCharValue(char x, out bool isShift, out bool return default(ConsoleKey); } +#else + internal static char GetCharFromConsoleKey(ConsoleKey key, ConsoleModifiers modifiers) + { + // default for unprintables and unhandled + char keyChar = '\u0000'; + + // emulate GetKeyboardState bitmap - set high order bit for relevant modifier virtual keys + var state = new byte[256]; + state[NativeMethods.VK_SHIFT] = (byte)(((modifiers & ConsoleModifiers.Shift) != 0) ? 0x80 : 0); + state[NativeMethods.VK_CONTROL] = (byte)(((modifiers & ConsoleModifiers.Control) != 0) ? 0x80 : 0); + state[NativeMethods.VK_ALT] = (byte)(((modifiers & ConsoleModifiers.Alt) != 0) ? 0x80 : 0); + + // a ConsoleKey enum's value is a virtual key code + uint virtualKey = (uint)key; + + // get corresponding scan code + uint scanCode = NativeMethods.MapVirtualKey(virtualKey, NativeMethods.MAPVK_VK_TO_VSC); + + // get corresponding character - maybe be 0, 1 or 2 in length (diacriticals) + var chars = new char[2]; + int charCount = NativeMethods.ToUnicode( + virtualKey, scanCode, state, chars, chars.Length, NativeMethods.MENU_IS_INACTIVE); + + // TODO: support diacriticals (charCount == 2) + if (charCount == 1) + { + keyChar = chars[0]; + } + return keyChar; + } #endif } } diff --git a/PSReadLine/ConsoleLib.cs b/PSReadLine/ConsoleLib.cs index 1b3f648b0..f9d1b7cc7 100644 --- a/PSReadLine/ConsoleLib.cs +++ b/PSReadLine/ConsoleLib.cs @@ -386,7 +386,13 @@ public static string ToGestureString(this ConsoleKeyInfo key) sb.Append("Alt"); } +#if UNIX char c = key.KeyChar; +#else + // Windows cannot use KeyChar as some chords (like Ctrl+[) show up as control characters. + char c = ConsoleKeyChordConverter.GetCharFromConsoleKey(key.Key, + (mods & ConsoleModifiers.Shift) != 0 ? ConsoleModifiers.Shift : 0); +#endif if (char.IsControl(c) || char.IsWhiteSpace(c)) { if (key.Modifiers.HasFlag(ConsoleModifiers.Shift)) From ed7719fe0cb79f2adbf2e9465615a1158fa708e6 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 20 Jul 2016 14:44:14 -0700 Subject: [PATCH 49/58] Fix comparison for default ConsoleKey --- PSReadLine/KeyBindings.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/PSReadLine/KeyBindings.cs b/PSReadLine/KeyBindings.cs index f4843b3c4..d527dd1bd 100644 --- a/PSReadLine/KeyBindings.cs +++ b/PSReadLine/KeyBindings.cs @@ -93,9 +93,13 @@ public int GetHashCode(ConsoleKeyInfo obj) { // Because a comparison of two ConsoleKeyInfo objects is a comparison of the // combination of the ConsoleKey and Modifiers, we must combine their hashes. - // This is based on Tuple.GetHashCode - int h1 = obj.Key.GetHashCode(); + // Note that if the ConsoleKey is default, we must fall back to the KeyChar, + // otherwise every non-special key will compare as the same. + int h1 = obj.Key == default(ConsoleKey) + ? obj.KeyChar.GetHashCode() + : obj.Key.GetHashCode(); int h2 = obj.Modifiers.GetHashCode(); + // This is based on Tuple.GetHashCode return unchecked(((h1 << 5) + h1) ^ h2); } } From 4e4000cee5cf0635b01dcb4675189e00cfcd2652 Mon Sep 17 00:00:00 2001 From: Alex Jordan Date: Mon, 8 Aug 2016 21:57:25 -0700 Subject: [PATCH 50/58] Fix crash on file name being too long in prompt --- PSReadLine/ReadLine.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/PSReadLine/ReadLine.cs b/PSReadLine/ReadLine.cs index 609a31958..9c56bf928 100644 --- a/PSReadLine/ReadLine.cs +++ b/PSReadLine/ReadLine.cs @@ -557,13 +557,18 @@ private void Initialize(Runspace runspace, EngineIntrinsics engineIntrinsics) _visualSelectionCommandCount = 0; _statusIsErrorMessage = false; - _consoleBuffer = ReadBufferLines(_initialY, 1 + Options.ExtraPromptLineCount); + #if UNIX // TODO: not necessary if ReadBufferLines worked, or if rendering worked on spans instead of complete lines string newPrompt = GetPrompt(); + var bufferLineCount = (newPrompt.Length) / (_console.BufferWidth) + 1; + _consoleBuffer = ReadBufferLines(_initialY, bufferLineCount); + for (int i=0; i Date: Tue, 23 Aug 2016 12:38:25 -0500 Subject: [PATCH 51/58] Adding debugType portable to project.json. (#1959) * Adding debugType portable to project.json. * Move debugType. * Update project.json * Update project.json * Update project.json * Update project.json * Update project.json * Update project.json * Update project.json * Update project.json * Moving debugType into correct places. Removing from non-core builds. * Added missed files. * Fixing project.json debugType placement. --- PSReadLine/project.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PSReadLine/project.json b/PSReadLine/project.json index ca228c8a6..e68f7d42a 100644 --- a/PSReadLine/project.json +++ b/PSReadLine/project.json @@ -25,7 +25,8 @@ "frameworks": { "netstandard1.6": { "buildOptions": { - "define": [ "CORECLR" ] + "define": [ "CORECLR" ], + "debugType": "portable" }, "imports": [ "dnxcore50", "portable-net45+win8" ] }, From be7c401a272abf678c4edc9b8c68f2ae6aa93372 Mon Sep 17 00:00:00 2001 From: xiaoyinl Date: Tue, 23 Aug 2016 21:21:31 -0400 Subject: [PATCH 52/58] Use HTTPS links for go.microsoft.com I replace all occurrences of http://go.microsoft.com with https://go.microsoft.com in text files. --- PSReadLine/Cmdlets.cs | 10 +++++----- PSReadLine/PSReadLine.psd1 | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/PSReadLine/Cmdlets.cs b/PSReadLine/Cmdlets.cs index 47a7a8118..175224a25 100644 --- a/PSReadLine/Cmdlets.cs +++ b/PSReadLine/Cmdlets.cs @@ -381,7 +381,7 @@ internal void SetBackgroundColor(TokenClassification tokenKind, ConsoleColor col } } - [Cmdlet("Get", "PSReadlineOption", HelpUri = "http://go.microsoft.com/fwlink/?LinkId=528808")] + [Cmdlet("Get", "PSReadlineOption", HelpUri = "https://go.microsoft.com/fwlink/?LinkId=528808")] [OutputType(typeof(PSConsoleReadlineOptions))] public class GetPSReadlineOption : PSCmdlet { @@ -392,7 +392,7 @@ protected override void EndProcessing() } } - [Cmdlet("Set", "PSReadlineOption", HelpUri = "http://go.microsoft.com/fwlink/?LinkId=528811")] + [Cmdlet("Set", "PSReadlineOption", HelpUri = "https://go.microsoft.com/fwlink/?LinkId=528811")] public class SetPSReadlineOption : PSCmdlet { [Parameter(ParameterSetName = "OptionsSet")] @@ -672,7 +672,7 @@ protected IDisposable UseRequestedDispatchTables() } } - [Cmdlet("Set", "PSReadlineKeyHandler", HelpUri = "http://go.microsoft.com/fwlink/?LinkId=528810")] + [Cmdlet("Set", "PSReadlineKeyHandler", HelpUri = "https://go.microsoft.com/fwlink/?LinkId=528810")] public class SetPSReadlineKeyHandlerCommand : ChangePSReadlineKeyHandlerCommandBase, IDynamicParameters { [Parameter(Position = 1, Mandatory = true, ParameterSetName = "ScriptBlock")] @@ -747,7 +747,7 @@ public object GetDynamicParameters() } } - [Cmdlet("Get", "PSReadlineKeyHandler", HelpUri = "http://go.microsoft.com/fwlink/?LinkId=528807")] + [Cmdlet("Get", "PSReadlineKeyHandler", HelpUri = "https://go.microsoft.com/fwlink/?LinkId=528807")] [OutputType(typeof(KeyHandler))] public class GetKeyHandlerCommand : PSCmdlet { @@ -791,7 +791,7 @@ protected override void EndProcessing() } } - [Cmdlet("Remove", "PSReadlineKeyHandler", HelpUri = "http://go.microsoft.com/fwlink/?LinkId=528809")] + [Cmdlet("Remove", "PSReadlineKeyHandler", HelpUri = "https://go.microsoft.com/fwlink/?LinkId=528809")] public class RemoveKeyHandlerCommand : ChangePSReadlineKeyHandlerCommandBase { [ExcludeFromCodeCoverage] diff --git a/PSReadLine/PSReadLine.psd1 b/PSReadLine/PSReadLine.psd1 index 65daec419..6af2eea6f 100644 --- a/PSReadLine/PSReadLine.psd1 +++ b/PSReadLine/PSReadLine.psd1 @@ -13,5 +13,5 @@ CLRVersion = '4.0' FunctionsToExport = 'PSConsoleHostReadline' CmdletsToExport = 'Get-PSReadlineKeyHandler','Set-PSReadlineKeyHandler','Remove-PSReadlineKeyHandler', 'Get-PSReadlineOption','Set-PSReadlineOption' -HelpInfoURI = 'http://go.microsoft.com/fwlink/?LinkId=528806' +HelpInfoURI = 'https://go.microsoft.com/fwlink/?LinkId=528806' } From 872915d9075c0020e091edab5e5b16f393639d16 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Fri, 26 Aug 2016 16:46:03 -0400 Subject: [PATCH 53/58] Spelling comments (#2066) * spelling: comments in src/Microsoft.Management.Infrastructure.CimCmdlets * spelling: comments in src/Microsoft.PackageManagement.ArchiverProviders * spelling: comments in src/Microsoft.PackageManagement.CoreProviders * spelling: comments in src/Microsoft.PackageManagement.MetaProvider.PowerShell * spelling: comments in src/Microsoft.PackageManagement.MsiProvider * spelling: comments in src/Microsoft.PackageManagement.MsuProvider * spelling: comments in src/Microsoft.PackageManagement.NuGetProvider * spelling: comments in src/Microsoft.PackageManagement.PackageSourceListProvider * spelling: comments in src/Microsoft.PackageManagement * spelling: comments in src/Microsoft.PowerShell.Activities * spelling: comments in src/Microsoft.PowerShell.Commands.Diagnostics * spelling: comments in src/Microsoft.PowerShell.Commands.Management * spelling: comments in src/Microsoft.PowerShell.Commands.Utility * spelling: comments in src/Microsoft.PowerShell.ConsoleHost * spelling: comments in src/Microsoft.PowerShell.Core.Activities * spelling: comments in src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext * spelling: comments in src/Microsoft.PowerShell.CoreCLR.Eventing * spelling: comments in src/Microsoft.PowerShell.Diagnostics.Activities * spelling: comments in src/Microsoft.PowerShell.GraphicalHost * spelling: comments in src/Microsoft.PowerShell.LocalAccounts * spelling: comments in src/Microsoft.PowerShell.Management.Activities * spelling: comments in src/Microsoft.PowerShell.PSReadLine * spelling: comments in src/Microsoft.PowerShell.PackageManagement * spelling: comments in src/Microsoft.PowerShell.ScheduledJob * spelling: comments in src/Microsoft.PowerShell.Security.Activities * spelling: comments in src/Microsoft.PowerShell.Security * spelling: comments in src/Microsoft.PowerShell.Utility.Activities * spelling: comments in src/Microsoft.PowerShell.Workflow.ServiceCore * spelling: comments in src/Microsoft.WSMan.Management.Activities * spelling: comments in src/Modules * spelling: comments in src/Schemas * spelling: comments in src/libpsl-native * spelling: comments in src/powershell-native * spelling: comments in build.psm1 * spelling: comments in src/System.Management.Automation/CoreCLR * spelling: comments in src/System.Management.Automation/DscSupport * spelling: comments in src/System.Management.Automation/cimSupport * spelling: comments in src/System.Management.Automation/commands * spelling: comments in src/System.Management.Automation/engine/Modules --- PSReadLine/BasicEditing.cs | 4 ++-- PSReadLine/Changes.txt | 4 ++-- PSReadLine/Cmdlets.cs | 2 +- PSReadLine/ConsoleKeyChordConverter.cs | 4 ++-- PSReadLine/KeyBindings.cs | 2 +- PSReadLine/KillYank.cs | 2 +- PSReadLine/PSReadLineResources.Designer.cs | 28 +++++++++++----------- PSReadLine/PSReadLineResources.resx | 26 ++++++++++---------- PSReadLine/PublicAPI.cs | 4 ++-- PSReadLine/ReadLine.cs | 2 +- PSReadLine/ReadLine.vi.cs | 8 +++---- PSReadLine/Render.cs | 2 +- PSReadLine/Words.vi.cs | 2 +- PSReadLine/en-US/PSReadline.md | 4 ++-- 14 files changed, 47 insertions(+), 47 deletions(-) diff --git a/PSReadLine/BasicEditing.cs b/PSReadLine/BasicEditing.cs index 2792f763f..bf571e8cd 100644 --- a/PSReadLine/BasicEditing.cs +++ b/PSReadLine/BasicEditing.cs @@ -523,7 +523,7 @@ public static void AddLine(ConsoleKeyInfo? key = null, object arg = null) [SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")] public static void InsertLineAbove(ConsoleKeyInfo? key = null, object arg = null) { - // Move the current postion to the beginning of the current line and only the current line. + // Move the current position to the beginning of the current line and only the current line. if (_singleton.LineIsMultiLine()) { int i = Math.Max(0, _singleton._current - 1); @@ -554,7 +554,7 @@ public static void InsertLineAbove(ConsoleKeyInfo? key = null, object arg = null [SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")] public static void InsertLineBelow(ConsoleKeyInfo? key = null, object arg = null) { - // Move the current postion to the end of the current line and only the current line. + // Move the current position to the end of the current line and only the current line. if (_singleton.LineIsMultiLine()) { int i = _singleton._current; diff --git a/PSReadLine/Changes.txt b/PSReadLine/Changes.txt index 0dcee86ee..31aa77d0c 100644 --- a/PSReadLine/Changes.txt +++ b/PSReadLine/Changes.txt @@ -154,7 +154,7 @@ New features: * SamplePSReadlineProfile.ps1 added with examples of custom key bindings * Word movement takes DigitArgument * HistoryNoDuplicates now works a little differently - - Dupicates are saved (it was a dubious memory optimization anyway) + - Duplicates are saved (it was a dubious memory optimization anyway) - Recall will recall the most recently executed item instead of the first * When at the last word, NextWord/ForwardWord now move to the end of line instead of the last character of the word. @@ -227,7 +227,7 @@ Bugs fixed: * Ctrl+R with long search lines no longer causes big problems Behavior change: -* Word functions now use delimiters. The previous behavior is availble +* Word functions now use delimiters. The previous behavior is available via a Shell*Word function, e.g. instead of KillWord, use ShellKillWord. ### Version 1.0.0.4 diff --git a/PSReadLine/Cmdlets.cs b/PSReadLine/Cmdlets.cs index 175224a25..77149b57f 100644 --- a/PSReadLine/Cmdlets.cs +++ b/PSReadLine/Cmdlets.cs @@ -120,7 +120,7 @@ public class PSConsoleReadlineOptions /// /// When displaying possible completions, either display - /// tooltips or dipslay just the completions. + /// tooltips or display just the completions. /// public const bool DefaultShowToolTips = false; diff --git a/PSReadLine/ConsoleKeyChordConverter.cs b/PSReadLine/ConsoleKeyChordConverter.cs index a6248e8be..85178c6fa 100644 --- a/PSReadLine/ConsoleKeyChordConverter.cs +++ b/PSReadLine/ConsoleKeyChordConverter.cs @@ -321,12 +321,12 @@ internal static char GetCharFromConsoleKey(ConsoleKey key, ConsoleModifiers modi // get corresponding scan code uint scanCode = NativeMethods.MapVirtualKey(virtualKey, NativeMethods.MAPVK_VK_TO_VSC); - // get corresponding character - maybe be 0, 1 or 2 in length (diacriticals) + // get corresponding character - maybe be 0, 1 or 2 in length (diacritics) var chars = new char[2]; int charCount = NativeMethods.ToUnicode( virtualKey, scanCode, state, chars, chars.Length, NativeMethods.MENU_IS_INACTIVE); - // TODO: support diacriticals (charCount == 2) + // TODO: support diacritics (charCount == 2) if (charCount == 1) { keyChar = chars[0]; diff --git a/PSReadLine/KeyBindings.cs b/PSReadLine/KeyBindings.cs index d527dd1bd..d5fdaca56 100644 --- a/PSReadLine/KeyBindings.cs +++ b/PSReadLine/KeyBindings.cs @@ -55,7 +55,7 @@ class KeyHandler // should be included on all handlers that ignore their parameters so they // can be called from PowerShell without passing anything. // - // The first arugment is the key that caused the action to be called + // The first argument is the key that caused the action to be called // (the second key when it's a 2 key chord). The default is null (it's nullable) // because PowerShell can't handle default(ConsoleKeyInfo) as a default. // Most actions will ignore this argument. diff --git a/PSReadLine/KillYank.cs b/PSReadLine/KillYank.cs index ba6a87b22..be46011a7 100644 --- a/PSReadLine/KillYank.cs +++ b/PSReadLine/KillYank.cs @@ -32,7 +32,7 @@ class YankLastArgState private int _visualSelectionCommandCount; /// - /// Mark the current loction of the cursor for use in a subsequent editing command. + /// Mark the current location of the cursor for use in a subsequent editing command. /// [SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")] public static void SetMark(ConsoleKeyInfo? key = null, object arg = null) diff --git a/PSReadLine/PSReadLineResources.Designer.cs b/PSReadLine/PSReadLineResources.Designer.cs index 3308edd22..b6ed66993 100644 --- a/PSReadLine/PSReadLineResources.Designer.cs +++ b/PSReadLine/PSReadLineResources.Designer.cs @@ -106,7 +106,7 @@ internal static string BackwardCharDescription { } /// - /// Looks up a localized string similar to Delete the charcter before the cursor. + /// Looks up a localized string similar to Delete the character before the cursor. /// internal static string BackwardDeleteCharDescription { get { @@ -322,7 +322,7 @@ internal static string DeleteBraceDescription { } /// - /// Looks up a localized string similar to Delete the character under the cusor. + /// Looks up a localized string similar to Delete the character under the cursor. /// internal static string DeleteCharDescription { get { @@ -331,7 +331,7 @@ internal static string DeleteCharDescription { } /// - /// Looks up a localized string similar to Delete the character under the cusor, or if the line is empty, exit the process.. + /// Looks up a localized string similar to Delete the character under the cursor, or if the line is empty, exit the process.. /// internal static string DeleteCharOrExitDescription { get { @@ -502,7 +502,7 @@ internal static string GotoBraceDescription { } /// - /// Looks up a localized string similar to Moves the cursor to the perscribed column.. + /// Looks up a localized string similar to Moves the cursor to the prescribed column.. /// internal static string GotoColumnDescription { get { @@ -990,7 +990,7 @@ internal static string ScrollDisplayUpLineDescription { } /// - /// Looks up a localized string similar to Searches backward for the perscribed character.. + /// Looks up a localized string similar to Searches backward for the prescribed character.. /// internal static string SearchBackwardCharDescription { get { @@ -999,7 +999,7 @@ internal static string SearchBackwardCharDescription { } /// - /// Looks up a localized string similar to Move to the previous occurance of the specified character.. + /// Looks up a localized string similar to Move to the previous occurrence of the specified character.. /// internal static string SearchCharBackwardDescription { get { @@ -1008,7 +1008,7 @@ internal static string SearchCharBackwardDescription { } /// - /// Looks up a localized string similar to Move to the previous occurance of the specified character and then forward one character.. + /// Looks up a localized string similar to Move to the previous occurrence of the specified character and then forward one character.. /// internal static string SearchCharBackwardWithBackoffDescription { get { @@ -1017,7 +1017,7 @@ internal static string SearchCharBackwardWithBackoffDescription { } /// - /// Looks up a localized string similar to Move to the next occurance of the specified character.. + /// Looks up a localized string similar to Move to the next occurrence of the specified character.. /// internal static string SearchCharDescription { get { @@ -1026,7 +1026,7 @@ internal static string SearchCharDescription { } /// - /// Looks up a localized string similar to Move to he next occurance of the specified character and then back one character.. + /// Looks up a localized string similar to Move to he next occurrence of the specified character and then back one character.. /// internal static string SearchCharWithBackoffDescription { get { @@ -1035,7 +1035,7 @@ internal static string SearchCharWithBackoffDescription { } /// - /// Looks up a localized string similar to Searches for the perscribed character in the perscribed direction.. + /// Looks up a localized string similar to Searches for the prescribed character in the prescribed direction.. /// internal static string SearchDescription { get { @@ -1488,7 +1488,7 @@ internal static string ViGotoBraceDescription { /// /// Looks up a localized string similar to Moves the cursor to the beginning of the line and switches to insert mode.. /// - internal static string ViInsertAtBeginingDescription { + internal static string ViInsertAtBeginningDescription { get { return ResourceManager.GetString("ViInsertAtBeginingDescription", resourceCulture); } @@ -1585,7 +1585,7 @@ internal static string ViReplaceEndOfGlobDescription { } /// - /// Looks up a localized string similar to Delete to the end of the word, as delimited by white space and common delimters, and enter insert mode.. + /// Looks up a localized string similar to Delete to the end of the word, as delimited by white space and common delimiters, and enter insert mode.. /// internal static string ViReplaceEndOfWordDescription { get { @@ -1639,7 +1639,7 @@ internal static string ViReplaceWordDescription { } /// - /// Looks up a localized string similar to Starts a new seach backward in the history.. + /// Looks up a localized string similar to Starts a new search backward in the history.. /// internal static string ViSearchHistoryBackwardDescription { get { @@ -1756,7 +1756,7 @@ internal static string ViYankPreviousGlobDescription { } /// - /// Looks up a localized string similar to Place all characters from before the cursor to the beginning of the previous word, as delimted by white space and common delimiters, into the local clipboard.. + /// Looks up a localized string similar to Place all characters from before the cursor to the beginning of the previous word, as delimited by white space and common delimiters, into the local clipboard.. /// internal static string ViYankPreviousWordDescription { get { diff --git a/PSReadLine/PSReadLineResources.resx b/PSReadLine/PSReadLineResources.resx index 6348877b3..ca33545cc 100644 --- a/PSReadLine/PSReadLineResources.resx +++ b/PSReadLine/PSReadLineResources.resx @@ -127,7 +127,7 @@ Move the cursor back one character - Delete the charcter before the cursor + Delete the character before the cursor Delete text from the cursor to the start of the line @@ -154,7 +154,7 @@ Complete the input if there is a single completion, otherwise complete the input with common prefix for all completions. Show possible completions if pressed a second time. - Delete the character under the cusor + Delete the character under the cursor Move the cursor to the beginning of the current or previous token or start of the line @@ -412,7 +412,7 @@ Exception: If there are other parse errors, unresolved commands, or incorrect parameters, show the error and continue editing. - Delete the character under the cusor, or if the line is empty, exit the process. + Delete the character under the cursor, or if the line is empty, exit the process. Unable to translate '{0}' to virtual key code: {1}. @@ -451,10 +451,10 @@ If there are other parse errors, unresolved commands, or incorrect parameters, s Repeats the last search. - Searches backward for the perscribed character. + Searches backward for the prescribed character. - Searches for the perscribed character in the perscribed direction. + Searches for the prescribed character in the prescribed direction. Switches to insert mode after positioning the cursor past the end of the line. @@ -496,7 +496,7 @@ If there are other parse errors, unresolved commands, or incorrect parameters, s Moves the cursor forward to the end of the next word. - Moves the cursor to the perscribed column. + Moves the cursor to the prescribed column. Switches to insert mode. @@ -547,7 +547,7 @@ If there are other parse errors, unresolved commands, or incorrect parameters, s Delete the current character and insert the next character. - Starts a new seach backward in the history. + Starts a new search backward in the history. Transposes the current character with the next character in the line. @@ -565,16 +565,16 @@ If there are other parse errors, unresolved commands, or incorrect parameters, s Repeat the last recorded character search. - Move to the previous occurance of the specified character. + Move to the previous occurrence of the specified character. - Move to the previous occurance of the specified character and then forward one character. + Move to the previous occurrence of the specified character and then forward one character. - Move to the next occurance of the specified character. + Move to the next occurrence of the specified character. - Move to he next occurance of the specified character and then back one character. + Move to he next occurrence of the specified character and then back one character. Replace the previous word. @@ -622,7 +622,7 @@ If there are other parse errors, unresolved commands, or incorrect parameters, s Delete to the beginning of the next word, as delimited by white space, and enter insert mode. - Delete to the end of the word, as delimited by white space and common delimters, and enter insert mode. + Delete to the end of the word, as delimited by white space and common delimiters, and enter insert mode. Delete to the end of the word, as delimited by white space, and enter insert mode. @@ -634,7 +634,7 @@ If there are other parse errors, unresolved commands, or incorrect parameters, s Place all characters at and after the cursor into the local clipboard. - Place all characters from before the cursor to the beginning of the previous word, as delimted by white space and common delimiters, into the local clipboard. + Place all characters from before the cursor to the beginning of the previous word, as delimited by white space and common delimiters, into the local clipboard. Place all characters from before the cursor to the beginning of the previous word, as delimited by white space, into the local clipboard. diff --git a/PSReadLine/PublicAPI.cs b/PSReadLine/PublicAPI.cs index 8827a0970..3f0163a78 100644 --- a/PSReadLine/PublicAPI.cs +++ b/PSReadLine/PublicAPI.cs @@ -125,7 +125,7 @@ public static void Delete(int start, int length) /// The length to replace /// The replacement text /// The action that initiated the replace (used for undo) - /// The argument to the action that initiaed the replace (used for undo) + /// The argument to the action that initiated the replace (used for undo) public static void Replace(int start, int length, string replacement, Action instigator = null, object instigatorArg = null) { if (start < 0 || start > _singleton._buffer.Length) @@ -224,7 +224,7 @@ public static void SetCursorPosition(int cursor) /// /// A helper method when your function expects an optional int argument (e.g. from DigitArgument) - /// If there is not argument (it's null), returns true and sets numericArg to derfaultNumericArg. + /// If there is not argument (it's null), returns true and sets numericArg to defaultNumericArg. /// Dings and returns false if the argument is not an int (no conversion is attempted) /// Otherwise returns true, and numericArg has the result. /// diff --git a/PSReadLine/ReadLine.cs b/PSReadLine/ReadLine.cs index 9c56bf928..e7ec6fb01 100644 --- a/PSReadLine/ReadLine.cs +++ b/PSReadLine/ReadLine.cs @@ -158,7 +158,7 @@ private static ConsoleKeyInfo ReadKey() // There is an OnIdle event. We're idle because we timed out. Normally // PowerShell generates this event, but PowerShell assumes the engine is not // idle because it called PSConsoleHostReadline which isn't returning. - // So we generate the event intstead. + // So we generate the event instead. _singleton._engineIntrinsics.Events.GenerateEvent("PowerShell.OnIdle", null, null, null); runPipelineForEventProcessing = true; break; diff --git a/PSReadLine/ReadLine.vi.cs b/PSReadLine/ReadLine.vi.cs index bb0410a3d..ce3a30392 100644 --- a/PSReadLine/ReadLine.vi.cs +++ b/PSReadLine/ReadLine.vi.cs @@ -197,7 +197,7 @@ public static void SearchChar(ConsoleKeyInfo? key = null, object arg = null) } /// - /// Read the next character and then find it, going backard, and then back off a character. + /// Read the next character and then find it, going backward, and then back off a character. /// This is for 'T' functionality. /// public static void SearchCharBackward(ConsoleKeyInfo? key = null, object arg = null) @@ -219,7 +219,7 @@ public static void SearchCharWithBackoff(ConsoleKeyInfo? key = null, object arg } /// - /// Read the next character and then find it, going backard, and then back off a character. + /// Read the next character and then find it, going backward, and then back off a character. /// This is for 'T' functionality. /// public static void SearchCharBackwardWithBackoff(ConsoleKeyInfo? key = null, object arg = null) @@ -570,7 +570,7 @@ private void ViIndicateInsertMode() } /// - /// Switch to Insert mode and position the cursor at the begining of the line. + /// Switch to Insert mode and position the cursor at the beginning of the line. /// public static void ViInsertAtBegining(ConsoleKeyInfo? key = null, object arg = null) { @@ -887,7 +887,7 @@ public static void RepeatSearchBackward(ConsoleKeyInfo? key = null, object arg = /// /// Prompts for a string for history searching. /// - /// True for seaching backward in the history. + /// True for searching backward in the history. private void StartSearch(bool backward) { _statusLinePrompt = "find: "; diff --git a/PSReadLine/Render.cs b/PSReadLine/Render.cs index 3491ead67..f6807bf19 100644 --- a/PSReadLine/Render.cs +++ b/PSReadLine/Render.cs @@ -462,7 +462,7 @@ private void MaybeEmphasize(ref BufferChar charInfo, int i, ConsoleColor foregro else if (_visualSelectionCommandCount > 0 && InRegion(i)) { // We can't quite emulate real console selection because it inverts - // based on actual screen colors, our pallete is limited. The choice + // based on actual screen colors, our palette is limited. The choice // to invert only the lower 3 bits to change the color is somewhat // but looks best with the 2 default color schemes - starting PowerShell // from it's shortcut or from a cmd shortcut. diff --git a/PSReadLine/Words.vi.cs b/PSReadLine/Words.vi.cs index 265378ed9..182ebc27c 100644 --- a/PSReadLine/Words.vi.cs +++ b/PSReadLine/Words.vi.cs @@ -129,7 +129,7 @@ private int ViFindPreviousWordPoint(string wordDelimiters) /// Returns the beginning of the current/next word as defined by wordDelimiters and whitespace. /// /// Current cursor location. - /// Characters used to deliminate words. + /// Characters used to delimit words. /// Location of the beginning of the previous word. private int ViFindPreviousWordPoint(int i, string wordDelimiters) { diff --git a/PSReadLine/en-US/PSReadline.md b/PSReadLine/en-US/PSReadline.md index 1b2a491ea..9e86dc535 100644 --- a/PSReadLine/en-US/PSReadline.md +++ b/PSReadLine/en-US/PSReadline.md @@ -10,9 +10,9 @@ If neither -Bound nor -Unbound is specified, returns all bound keys and unbound If -Bound is specified and -Unbound is not specified, only bound keys are returned. -If -Unound is specified and -Bound is not specified, only unbound keys are returned. +If -Unbound is specified and -Bound is not specified, only unbound keys are returned. -If both -Bound and -Unound are specified, returns all bound keys and unbound functions. +If both -Bound and -Unbound are specified, returns all bound keys and unbound functions. ## PARAMETERS From 6bd9f079470463b68f83ba46bd2525e801c5e903 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 28 Aug 2016 06:47:18 +0000 Subject: [PATCH 54/58] spelling: debug... --- PSReadLine/ConsoleLib.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PSReadLine/ConsoleLib.cs b/PSReadLine/ConsoleLib.cs index f9d1b7cc7..fdadc62cb 100644 --- a/PSReadLine/ConsoleLib.cs +++ b/PSReadLine/ConsoleLib.cs @@ -443,7 +443,7 @@ internal class ConhostConsole : IConsole { int err = Marshal.GetLastWin32Error(); Win32Exception innerException = new Win32Exception(err); - throw new Exception("Failed to retreive the input console handle.", innerException); + throw new Exception("Failed to retrieve the input console handle.", innerException); } return new SafeFileHandle(handle, true); @@ -466,7 +466,7 @@ internal class ConhostConsole : IConsole { int err = Marshal.GetLastWin32Error(); Win32Exception innerException = new Win32Exception(err); - throw new Exception("Failed to retreive the input console handle.", innerException); + throw new Exception("Failed to retrieve the input console handle.", innerException); } return new SafeFileHandle(handle, true); From 89e5ca4ef4ed034cc6ff4c264df05ef7f3b8f14a Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Fri, 2 Sep 2016 14:48:08 +0000 Subject: [PATCH 55/58] add space to switch-case statement in CommandValidationVisitor.UnresolvedCommandCouldSucceed --- PSReadLine/BasicEditing.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PSReadLine/BasicEditing.cs b/PSReadLine/BasicEditing.cs index bf571e8cd..4eb151dbf 100644 --- a/PSReadLine/BasicEditing.cs +++ b/PSReadLine/BasicEditing.cs @@ -428,8 +428,8 @@ private bool UnresolvedCommandCouldSucceed(string commandName, Ast rootAst) { // The following are debugger commands that should be accepted if we're debugging // because the console host will interpret these commands directly. - case 's': case 'v': case 'o': case 'c': case 'q': case'k': case 'l': - case 'S': case 'V': case 'O': case 'C': case 'Q': case'K': case 'L': + case 's': case 'v': case 'o': case 'c': case 'q': case 'k': case 'l': + case 'S': case 'V': case 'O': case 'C': case 'Q': case 'K': case 'L': case '?': case 'h': case 'H': // Ideally we would check $PSDebugContext, but it is set at function // scope, and because we're in a module, we can't find that variable From bd76c873b9bc9902d2b3447dfff4ebe02117722c Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Fri, 2 Sep 2016 15:14:45 +0000 Subject: [PATCH 56/58] spelling: Hangul (unify spelling) Before this commit there were three spellings, one of which was a typo, one was a variant spelling, and one was the dominant spelling. Microsoft generally uses Hangul for its enums: https://msdn.microsoft.com/en-us/library/cc250412.aspx And this is the dominant spelling in general and as used in web browsers. --- PSReadLine/ConsoleLib.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PSReadLine/ConsoleLib.cs b/PSReadLine/ConsoleLib.cs index fdadc62cb..ed04122a3 100644 --- a/PSReadLine/ConsoleLib.cs +++ b/PSReadLine/ConsoleLib.cs @@ -713,10 +713,10 @@ public int LengthInBufferCells(char c) internal static bool IsAnyDBCSCharSet(uint charSet) { const uint SHIFTJIS_CHARSET = 128; - const uint HANGEUL_CHARSET = 129; + const uint HANGUL_CHARSET = 129; const uint CHINESEBIG5_CHARSET = 136; const uint GB2312_CHARSET = 134; - return charSet == SHIFTJIS_CHARSET || charSet == HANGEUL_CHARSET || + return charSet == SHIFTJIS_CHARSET || charSet == HANGUL_CHARSET || charSet == CHINESEBIG5_CHARSET || charSet == GB2312_CHARSET; } @@ -798,7 +798,7 @@ internal int LengthInBufferCellsFE(char c) (0xffd2 <= c && c <= 0xffd7) || (0xffda <= c && c <= 0xffdc)) { - /* Halfwidth Hangule variants */ + /* Halfwidth Hangul variants */ return 1; } else if (0xffe0 <= c && c <= 0xffe6) From cfbc8671f7cbdaa601ce834ea98ac40795fbabed Mon Sep 17 00:00:00 2001 From: Paul Higinbotham Date: Tue, 13 Sep 2016 11:31:48 -0700 Subject: [PATCH 57/58] Fix for Linux remote script debugging hang (#2213) * Fix for Linux remote debugging hang bug. * Removing dependency in PSReadLine on new engine helper API since it needs to be compatible with V3. --- PSReadLine/ReadLine.cs | 46 +++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/PSReadLine/ReadLine.cs b/PSReadLine/ReadLine.cs index e7ec6fb01..f3805676a 100644 --- a/PSReadLine/ReadLine.cs +++ b/PSReadLine/ReadLine.cs @@ -881,6 +881,9 @@ public static void InvokePrompt(ConsoleKeyInfo? key = null, object arg = null) _singleton.Render(); } + private const string PromptCommand = "prompt"; + private const string DefaultPrompt = "PS>"; + /// /// Gets the current prompt as possibly defined by the user through the /// prompt function, and returns a default prompt if no other is @@ -888,23 +891,45 @@ public static void InvokePrompt(ConsoleKeyInfo? key = null, object arg = null) /// public static string GetPrompt() { + string newPrompt; var runspaceIsRemote = _singleton._mockableMethods.RunspaceIsRemote(_singleton._runspace); - System.Management.Automation.PowerShell ps; - if (!runspaceIsRemote) + + if ((_singleton._runspace.Debugger != null) && _singleton._runspace.Debugger.InBreakpoint) { - ps = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace); + // Run prompt command in debugger API to ensure it is run correctly on the runspace. + // This handles remote runspace debugging and nested debugger scenarios. + PSDataCollection results = new PSDataCollection(); + var command = new PSCommand(); + command.AddCommand(PromptCommand); + _singleton._runspace.Debugger.ProcessCommand( + command, + results); + + newPrompt = (results.Count == 1) ? (results[0].BaseObject as string) : DefaultPrompt; } else { - ps = System.Management.Automation.PowerShell.Create(); - ps.Runspace = _singleton._runspace; + System.Management.Automation.PowerShell ps; + if (!runspaceIsRemote) + { + ps = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace); + } + else + { + ps = System.Management.Automation.PowerShell.Create(); + ps.Runspace = _singleton._runspace; + } + using (ps) + { + ps.AddCommand(PromptCommand); + var result = ps.Invoke(); + newPrompt = result.Count == 1 ? result[0] : DefaultPrompt; + } } - string newPrompt; - using (ps) + + if (string.IsNullOrEmpty(newPrompt)) { - ps.AddCommand("prompt"); - var result = ps.Invoke(); - newPrompt = result.Count == 1 ? result[0] : "PS>"; + newPrompt = DefaultPrompt; } if (runspaceIsRemote) @@ -915,6 +940,7 @@ public static string GetPrompt() newPrompt = string.Format(CultureInfo.InvariantCulture, "[{0}]: {1}", connectionInfo.ComputerName, newPrompt); } } + return newPrompt; } From 63e4d77fcddc2dbfd04d011cbc422069ebbde6ef Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 16 Sep 2016 14:53:59 -0700 Subject: [PATCH 58/58] Fix to build outside of PowerShell repo * Remove key signing (no key available) * Ignore project.lock.json * Add powershell-core MyGet feed * Depend on SMA NuGet package instead of project --- .gitignore | 1 + NuGet.config | 8 ++++++++ PSReadLine/project.json | 13 +++++-------- 3 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 NuGet.config diff --git a/.gitignore b/.gitignore index ebf89a98e..14b214373 100644 --- a/.gitignore +++ b/.gitignore @@ -43,6 +43,7 @@ x64/ *.vspscc *.vssscc .builds +project.lock.json # Visual C++ cache files ipch/ diff --git a/NuGet.config b/NuGet.config new file mode 100644 index 000000000..064fe4f00 --- /dev/null +++ b/NuGet.config @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/PSReadLine/project.json b/PSReadLine/project.json index e68f7d42a..ee8287783 100644 --- a/PSReadLine/project.json +++ b/PSReadLine/project.json @@ -4,9 +4,6 @@ "buildOptions": { "xmlDoc": true, - "keyFile": "../signing/visualstudiopublic.snk", - "delaySign": true, - "publicSign": false, "warningsAsErrors": true }, @@ -18,17 +15,17 @@ } }, - "dependencies": { - "System.Management.Automation": "1.0.0-*" - }, - "frameworks": { "netstandard1.6": { "buildOptions": { "define": [ "CORECLR" ], "debugType": "portable" }, - "imports": [ "dnxcore50", "portable-net45+win8" ] + "imports": [ "dnxcore50", "portable-net45+win8" ], + "dependencies": { + "System.Management.Automation": "1.0.0-alpha10" + } + }, "net451": { "frameworkAssemblies": {