mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
First stab addressing CORECLR vs. LINUX in PSReadLine
This commit is contained in:
@@ -12,6 +12,7 @@ using System.Reflection;
|
||||
using System.Linq;
|
||||
#if CORECLR
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.PowerShell.Internal;
|
||||
#endif
|
||||
|
||||
namespace Microsoft.PowerShell
|
||||
@@ -72,33 +73,24 @@ namespace Microsoft.PowerShell
|
||||
|
||||
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 @@ namespace Microsoft.PowerShell
|
||||
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<string>(StringComparer.OrdinalIgnoreCase)
|
||||
@@ -396,9 +380,7 @@ namespace Microsoft.PowerShell
|
||||
[OutputType(typeof(PSConsoleReadlineOptions))]
|
||||
public class GetPSReadlineOption : PSCmdlet
|
||||
{
|
||||
#if !CORECLR
|
||||
[ExcludeFromCodeCoverage]
|
||||
#endif
|
||||
protected override void EndProcessing()
|
||||
{
|
||||
WriteObject(PSConsoleReadLine.GetOptions());
|
||||
@@ -641,9 +623,7 @@ namespace Microsoft.PowerShell
|
||||
}
|
||||
internal ConsoleColor? _backgroundColor;
|
||||
|
||||
#if !CORECLR
|
||||
[ExcludeFromCodeCoverage]
|
||||
#endif
|
||||
protected override void EndProcessing()
|
||||
{
|
||||
PSConsoleReadLine.SetOptions(this);
|
||||
@@ -661,9 +641,7 @@ namespace Microsoft.PowerShell
|
||||
[Parameter]
|
||||
public ViMode ViMode { get; set; }
|
||||
|
||||
#if !CORECLR
|
||||
[ExcludeFromCodeCoverage]
|
||||
#endif
|
||||
protected IDisposable UseRequestedDispatchTables()
|
||||
{
|
||||
bool inViMode = PSConsoleReadLine.GetOptions().EditMode == EditMode.Vi;
|
||||
@@ -706,9 +684,7 @@ namespace Microsoft.PowerShell
|
||||
private const string FunctionParameter = "Function";
|
||||
private const string FunctionParameterSet = "Function";
|
||||
|
||||
#if !CORECLR
|
||||
[ExcludeFromCodeCoverage]
|
||||
#endif
|
||||
protected override void EndProcessing()
|
||||
{
|
||||
using (UseRequestedDispatchTables())
|
||||
@@ -716,15 +692,9 @@ namespace Microsoft.PowerShell
|
||||
if (ParameterSetName.Equals(FunctionParameterSet))
|
||||
{
|
||||
var function = (string)_dynamicParameters.Value[FunctionParameter].Value;
|
||||
#if CORECLR
|
||||
MethodInfo mi = typeof (PSConsoleReadLine).GetMethod(function);
|
||||
var keyHandler = (Action<ConsoleKeyInfo?, object>)
|
||||
mi.CreateDelegate(typeof (Action<ConsoleKeyInfo?, object>));
|
||||
#else
|
||||
var keyHandler = (Action<ConsoleKeyInfo?, object>)
|
||||
Delegate.CreateDelegate(typeof (Action<ConsoleKeyInfo?, object>),
|
||||
typeof (PSConsoleReadLine).GetMethod(function));
|
||||
#endif
|
||||
BriefDescription = function;
|
||||
PSConsoleReadLine.SetKeyHandler(Chord, keyHandler, BriefDescription, Description);
|
||||
}
|
||||
@@ -792,9 +762,7 @@ namespace Microsoft.PowerShell
|
||||
}
|
||||
private SwitchParameter? _unbound;
|
||||
|
||||
#if !CORECLR
|
||||
[ExcludeFromCodeCoverage]
|
||||
#endif
|
||||
protected override void EndProcessing()
|
||||
{
|
||||
bool bound = true;
|
||||
@@ -821,9 +789,7 @@ namespace Microsoft.PowerShell
|
||||
[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())
|
||||
|
||||
@@ -27,9 +27,7 @@ namespace Microsoft.PowerShell
|
||||
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 @@ namespace Microsoft.PowerShell
|
||||
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
|
||||
|
||||
@@ -6,7 +6,7 @@ using System;
|
||||
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 @@ namespace Microsoft.PowerShell
|
||||
{
|
||||
// default for unprintables and unhandled
|
||||
char keyChar = '\u0000';
|
||||
#if CORECLR
|
||||
#if LINUX
|
||||
Type keyType = typeof (Keys);
|
||||
FieldInfo[] keyFields = keyType.GetFields();
|
||||
|
||||
|
||||
@@ -227,9 +227,7 @@ namespace Microsoft.PowerShell.Internal
|
||||
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 @@ namespace Microsoft.PowerShell.Internal
|
||||
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 @@ namespace Microsoft.PowerShell.Internal
|
||||
|
||||
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 @@ namespace Microsoft.PowerShell.Internal
|
||||
{
|
||||
return UnicodeChar.GetHashCode() + Attributes.GetHashCode();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static class ConsoleKeyInfoExtension
|
||||
@@ -400,9 +383,10 @@ namespace Microsoft.PowerShell.Internal
|
||||
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 @@ namespace Microsoft.PowerShell.Internal
|
||||
|
||||
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 @@ namespace Microsoft.PowerShell.Internal
|
||||
ScrollBuffer(scrollCount);
|
||||
top -= scrollCount;
|
||||
}
|
||||
#if CORECLR
|
||||
#if LINUX
|
||||
ConsoleColor foregroundColor = Console.ForegroundColor;
|
||||
ConsoleColor backgroundColor = Console.BackgroundColor;
|
||||
|
||||
@@ -628,6 +609,7 @@ namespace Microsoft.PowerShell.Internal
|
||||
|
||||
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 @@ namespace Microsoft.PowerShell.Internal
|
||||
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 @@ namespace Microsoft.PowerShell.Internal
|
||||
|
||||
public void ScrollBuffer(int lines)
|
||||
{
|
||||
#if CORECLR
|
||||
#if LINUX
|
||||
for (int i=0; i<lines; ++i)
|
||||
{
|
||||
Console.SetCursorPosition(Console.BufferWidth, Console.BufferHeight - 1);
|
||||
@@ -690,7 +673,7 @@ namespace Microsoft.PowerShell.Internal
|
||||
public CHAR_INFO[] ReadBufferLines(int top, int count)
|
||||
{
|
||||
var result = new CHAR_INFO[BufferWidth * count];
|
||||
#if CORECLR
|
||||
#if LINUX
|
||||
for (int i=0; i<BufferWidth*count; ++i)
|
||||
{
|
||||
result[i].UnicodeChar = ' ';
|
||||
@@ -909,7 +892,7 @@ namespace Microsoft.PowerShell.Internal
|
||||
}
|
||||
}
|
||||
|
||||
#if CORECLR
|
||||
#if LINUX // TODO: this is not correct, PSReadline never clears the screen, it should only scroll
|
||||
public void Clear()
|
||||
{
|
||||
Console.Clear();
|
||||
@@ -917,5 +900,12 @@ namespace Microsoft.PowerShell.Internal
|
||||
#endif
|
||||
}
|
||||
|
||||
#if CORECLR // TODO: remove if CORECLR adds this attribute back
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event)]
|
||||
sealed class ExcludeFromCodeCoverageAttribute : Attribute
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
#pragma warning restore 1591
|
||||
}
|
||||
|
||||
@@ -6,12 +6,13 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#if CORECLR
|
||||
using Microsoft.PowerShell.Internal;
|
||||
#endif
|
||||
|
||||
namespace Microsoft.PowerShell
|
||||
{
|
||||
#if !CORECLR
|
||||
[ExcludeFromCodeCoverage]
|
||||
#endif
|
||||
[ExcludeFromCodeCoverage]
|
||||
internal sealed class QueueDebugView<T>
|
||||
{
|
||||
private readonly HistoryQueue<T> _queue;
|
||||
@@ -116,9 +117,7 @@ namespace Microsoft.PowerShell
|
||||
return result;
|
||||
}
|
||||
|
||||
#if !CORECLR
|
||||
[ExcludeFromCodeCoverage]
|
||||
#endif
|
||||
public T this[int index]
|
||||
{
|
||||
get
|
||||
|
||||
@@ -142,7 +142,7 @@ namespace Microsoft.PowerShell
|
||||
{ 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 @@ namespace Microsoft.PowerShell
|
||||
{ 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 @@ namespace Microsoft.PowerShell
|
||||
{ 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") },
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace Microsoft.PowerShell
|
||||
{ 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 @@ namespace Microsoft.PowerShell
|
||||
{ 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") },
|
||||
|
||||
@@ -290,10 +290,10 @@ namespace Microsoft.PowerShell
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ using System;
|
||||
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 @@ namespace Microsoft.PowerShell
|
||||
[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 @@ namespace Microsoft.PowerShell
|
||||
[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 @@ namespace Microsoft.PowerShell
|
||||
[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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -434,7 +434,7 @@ namespace Microsoft.PowerShell
|
||||
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();
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace Microsoft.PowerShell
|
||||
void StartRender();
|
||||
int LengthInBufferCells(char c);
|
||||
void EndRender();
|
||||
#if CORECLR
|
||||
#if LINUX
|
||||
void Clear();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Microsoft.PowerShell
|
||||
private IConsole _console;
|
||||
|
||||
private EngineIntrinsics _engineIntrinsics;
|
||||
#if !CORECLR
|
||||
#if !LINUX
|
||||
private static GCHandle _breakHandlerGcHandle;
|
||||
#endif
|
||||
private Thread _readKeyThread;
|
||||
@@ -43,7 +43,7 @@ namespace Microsoft.PowerShell
|
||||
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 @@ namespace Microsoft.PowerShell
|
||||
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 @@ namespace Microsoft.PowerShell
|
||||
{
|
||||
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 @@ namespace Microsoft.PowerShell
|
||||
}
|
||||
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 @@ namespace Microsoft.PowerShell
|
||||
|
||||
T CalloutUsingDefaultConsoleMode<T>(Func<T> 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 @@ namespace Microsoft.PowerShell
|
||||
_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<newPrompt.Length; ++i)
|
||||
{
|
||||
@@ -644,7 +644,7 @@ namespace Microsoft.PowerShell
|
||||
}
|
||||
}
|
||||
|
||||
#if CORECLR
|
||||
#if LINUX
|
||||
_historyFileMutex = new Mutex(false);
|
||||
#else
|
||||
_historyFileMutex = new Mutex(false, GetHistorySaveFileMutexName());
|
||||
@@ -681,7 +681,7 @@ namespace Microsoft.PowerShell
|
||||
_killIndex = -1; // So first add indexes 0.
|
||||
_killRing = new List<string>(Options.MaximumKillRingCount);
|
||||
|
||||
#if !CORECLR
|
||||
#if !LINUX
|
||||
_breakHandlerGcHandle = GCHandle.Alloc(new BreakHandler(_singleton.BreakHandler));
|
||||
NativeMethods.SetConsoleCtrlHandler((BreakHandler)_breakHandlerGcHandle.Target, true);
|
||||
#endif
|
||||
@@ -691,11 +691,11 @@ namespace Microsoft.PowerShell
|
||||
_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 @@ namespace Microsoft.PowerShell
|
||||
|
||||
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 @@ namespace Microsoft.PowerShell
|
||||
}
|
||||
});
|
||||
|
||||
#if !CORECLR
|
||||
thread.SetApartmentState(ApartmentState.STA);
|
||||
#endif
|
||||
thread.Start();
|
||||
thread.Join();
|
||||
|
||||
@@ -764,6 +763,7 @@ namespace Microsoft.PowerShell
|
||||
{
|
||||
throw exception;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#region Miscellaneous bindable functions
|
||||
@@ -899,7 +899,7 @@ namespace Microsoft.PowerShell
|
||||
|
||||
_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<newPrompt.Length; ++i)
|
||||
{
|
||||
_singleton._consoleBuffer[i].UnicodeChar = newPrompt[i];
|
||||
|
||||
@@ -100,10 +100,7 @@ namespace Microsoft.PowerShell
|
||||
|
||||
try
|
||||
{
|
||||
#if !CORECLR
|
||||
_console.StartRender();
|
||||
#endif
|
||||
|
||||
bufferLineCount = ConvertOffsetToCoordinates(text.Length).Y - _initialY + 1 + statusLineCount;
|
||||
if (_consoleBuffer.Length != bufferLineCount * bufferWidth)
|
||||
{
|
||||
@@ -231,16 +228,12 @@ namespace Microsoft.PowerShell
|
||||
else if (size > 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 @@ namespace Microsoft.PowerShell
|
||||
}
|
||||
finally
|
||||
{
|
||||
#if !CORECLR
|
||||
_console.EndRender();
|
||||
#endif
|
||||
}
|
||||
|
||||
for (; j < (_consoleBuffer.Length - (statusLineCount * _bufferWidth)); j++)
|
||||
@@ -319,7 +310,7 @@ namespace Microsoft.PowerShell
|
||||
|
||||
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 @@ namespace Microsoft.PowerShell
|
||||
// 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 @@ namespace Microsoft.PowerShell
|
||||
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 @@ namespace Microsoft.PowerShell
|
||||
// TODO: flash prompt? command line?
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -696,7 +683,7 @@ namespace Microsoft.PowerShell
|
||||
|
||||
#region Screen scrolling
|
||||
|
||||
#if !CORECLR
|
||||
#if !LINUX
|
||||
/// <summary>
|
||||
/// Scroll the display up one screen.
|
||||
/// </summary>
|
||||
|
||||
@@ -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 @@ namespace Microsoft.PowerShell
|
||||
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 @@ namespace Microsoft.PowerShell
|
||||
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 @@ namespace Microsoft.PowerShell
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,6 @@ namespace Microsoft.PowerShell
|
||||
private static string GetPreferredEditor()
|
||||
{
|
||||
string[] names = {"VISUAL", "EDITOR"};
|
||||
#if CORECLR
|
||||
foreach (string name in names)
|
||||
{
|
||||
string editor = Environment.GetEnvironmentVariable(name);
|
||||
@@ -105,24 +104,7 @@ namespace Microsoft.PowerShell
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,14 @@
|
||||
"warningsAsErrors": true
|
||||
},
|
||||
|
||||
"configurations": {
|
||||
"Linux": {
|
||||
"buildOptions": {
|
||||
"define": [ "LINUX" ]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
"dependencies": {
|
||||
"System.Management.Automation": "1.0.0-*"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user