Use ConsoleControl on Windows

This commit is contained in:
Andrew Schwartzmeyer committed 2016-07-01 17:01:07 -07:00
1 parent c1168e1a24
commit f70c0c51c2
5 files changed
+27 -18

No files matched your search

@@ -1,4 +1,4 @@
#if !PORTABLE
#if !LINUX
/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/
@@ -293,7 +293,7 @@ namespace Microsoft.PowerShell
/// </summary>
/// <param name="signal"></param>
/// <returns></returns>
#if PORTABLE
#if LINUX
private static void MyBreakHandler(object sender, ConsoleCancelEventArgs args)
{
// Set the Cancel property to true to prevent the process from terminating.
@@ -461,7 +461,7 @@ namespace Microsoft.PowerShell
// call the console APIs directly, instead of ui.rawui.FlushInputHandle, as ui may be finalized
// already if this thread is lagging behind the main thread.
#if !PORTABLE
#if !LINUX
ConsoleHandle handle = ConsoleControl.GetConioDeviceHandle();
ConsoleControl.FlushConsoleInputBuffer(handle);
#endif
@@ -1059,7 +1059,7 @@ namespace Microsoft.PowerShell
private void BindBreakHandler()
{
#if PORTABLE
#if LINUX
Console.CancelKeyPress += new ConsoleCancelEventHandler(MyBreakHandler);
#else
breakHandlerGcHandle = GCHandle.Alloc(new ConsoleControl.BreakHandler(MyBreakHandler));
@@ -1118,7 +1118,7 @@ namespace Microsoft.PowerShell
{
if (!isDisposed)
{
#if !PORTABLE
#if !LINUX
Dbg.Assert(breakHandlerGcHandle != null, "break handler should be set");
ConsoleControl.RemoveBreakHandler();
breakHandlerGcHandle.Free();
@@ -2867,7 +2867,7 @@ namespace Microsoft.PowerShell
/// </summary>
private RunspaceRef runspaceRef;
#if !PORTABLE
#if !LINUX
private GCHandle breakHandlerGcHandle;
#endif
private System.Threading.Thread breakHandlerThread;
@@ -1,4 +1,4 @@
#if !PORTABLE
#if !LINUX
/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/
@@ -14,7 +14,7 @@ using System.Management.Automation.Internal;
using System.Management.Automation.Host;
using System.Security;
using Dbg = System.Management.Automation.Diagnostics;
#if !PORTABLE
#if !LINUX
using ConsoleHandle = Microsoft.Win32.SafeHandles.SafeFileHandle;
#endif
@@ -61,7 +61,7 @@ namespace Microsoft.PowerShell
this.parent = parent;
this.rawui = new ConsoleHostRawUserInterface(this);
#if PORTABLE
#if LINUX
this._supportsVirtualTerminal = true;
#else
try
@@ -285,7 +285,7 @@ namespace Microsoft.PowerShell
private object ReadLineSafe(bool isSecureString, char? printToken)
{
#if PORTABLE
#if LINUX
throw new PlatformNotSupportedException("Cannot read secure strings!");
#else
// Don't lock (instanceLock) in here -- the caller needs to do that...
@@ -411,7 +411,7 @@ namespace Microsoft.PowerShell
#endif
}
#if !PORTABLE
#if !LINUX
/// <summary>
///
@@ -560,7 +560,7 @@ namespace Microsoft.PowerShell
internal void WriteToConsole(string value, bool transcribeResult)
{
#if !PORTABLE
#if !LINUX
ConsoleHandle handle = ConsoleControl.GetActiveScreenBufferHandle();
// Ensure that we're in the proper line-output mode. We don't lock here as it does not matter if we
@@ -583,7 +583,7 @@ namespace Microsoft.PowerShell
// This is atomic, so we don't lock here...
#if !PORTABLE
#if !LINUX
ConsoleControl.WriteConsole(handle, value);
#else
Console.Out.Write(value);
@@ -1637,7 +1637,7 @@ namespace Microsoft.PowerShell
private string ReadLineFromConsole(bool endOnTab, string initialContent, bool calledFromPipeline, ref string restOfLine, ref ReadLineResult result)
{
#if PORTABLE
#if LINUX
return ReadLineFromFile(initialContent);
#else
ConsoleHandle handle = ConsoleControl.GetConioDeviceHandle();
@@ -1771,7 +1771,7 @@ namespace Microsoft.PowerShell
/// </summary>
/// <param name="cursorPosition">the cursor position where 'tab' is hit</param>
/// <returns></returns>
#if !PORTABLE
#if !LINUX
private char GetCharacterUnderCursor(Coordinates cursorPosition)
{
Rectangle region = new Rectangle(0, cursorPosition.Y, RawUI.BufferSize.Width - 1, cursorPosition.Y);
@@ -1840,7 +1840,7 @@ namespace Microsoft.PowerShell
ReadLineResult rlResult = ReadLineResult.endedOnEnter;
#if !PORTABLE
#if !LINUX
ConsoleHandle handle = ConsoleControl.GetActiveScreenBufferHandle();
string lastCompletion = "";
@@ -1874,7 +1874,7 @@ namespace Microsoft.PowerShell
break;
}
#if PORTABLE // Portable code only ends on enter (or no input), so tab is not processed
#if LINUX // Portable code only ends on enter (or no input), so tab is not processed
throw new PlatformNotSupportedException("This readline state is unsupported in portable code!");
#else
@@ -2000,7 +2000,7 @@ namespace Microsoft.PowerShell
return input;
}
#if !PORTABLE
#if !LINUX
private void SendLeftArrows(int length)
{
var inputs = new ConsoleControl.INPUT[length * 2];
@@ -31,6 +31,15 @@
]
},
"configurations": {
"Linux": {
"buildOptions": {
"define": [ "LINUX" ]
}
}
},
"dependencies": {
"Microsoft.PowerShell.PSReadLine": "1.0.0-*",
"Microsoft.PowerShell.Commands.Diagnostics": "1.0.0-*",