mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Merge pull request #934 from PowerShell/psreadline4
A number of PSReadLine changes
This commit is contained in:
@@ -72,6 +72,20 @@ namespace Microsoft.PowerShell
|
||||
|
||||
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 @@ namespace Microsoft.PowerShell
|
||||
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;
|
||||
|
||||
@@ -166,7 +180,8 @@ namespace Microsoft.PowerShell
|
||||
{
|
||||
HistorySavePath = System.IO.Path.Combine(
|
||||
Environment.GetEnvironmentVariable("HOME"),
|
||||
".psreadline",
|
||||
".powershell",
|
||||
"PSReadLine",
|
||||
hostName + "_history.txt");
|
||||
}
|
||||
#else
|
||||
|
||||
@@ -908,6 +908,13 @@ namespace Microsoft.PowerShell.Internal
|
||||
NativeMethods.ReleaseDC(_hwnd, _hDC);
|
||||
}
|
||||
}
|
||||
|
||||
#if CORECLR
|
||||
public void Clear()
|
||||
{
|
||||
Console.Clear();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#pragma warning restore 1591
|
||||
|
||||
@@ -181,10 +181,12 @@ namespace Microsoft.PowerShell
|
||||
{ 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<ConsoleKeyInfo, Dictionary<ConsoleKeyInfo, KeyHandler>>();
|
||||
@@ -267,13 +269,13 @@ namespace Microsoft.PowerShell
|
||||
{ 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<ConsoleKeyInfo, Dictionary<ConsoleKeyInfo, KeyHandler>>();
|
||||
|
||||
@@ -3,9 +3,6 @@ Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
#if CORECLR
|
||||
using System.Runtime.InteropServices;
|
||||
#endif
|
||||
|
||||
namespace Microsoft.PowerShell
|
||||
{
|
||||
|
||||
@@ -6,7 +6,9 @@ using System;
|
||||
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
|
||||
{
|
||||
|
||||
@@ -434,6 +434,11 @@ namespace Microsoft.PowerShell
|
||||
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 @@ namespace Microsoft.PowerShell
|
||||
{
|
||||
console.SetWindowPosition(0, _singleton._initialY);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Try to convert the arg to a char, return 0 for failure
|
||||
|
||||
@@ -54,6 +54,9 @@ namespace Microsoft.PowerShell
|
||||
void StartRender();
|
||||
int LengthInBufferCells(char c);
|
||||
void EndRender();
|
||||
#if CORECLR
|
||||
void Clear();
|
||||
#endif
|
||||
}
|
||||
|
||||
#pragma warning restore 1591
|
||||
|
||||
@@ -472,8 +472,14 @@ 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
|
||||
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;
|
||||
@@ -690,6 +696,7 @@ namespace Microsoft.PowerShell
|
||||
|
||||
#region Screen scrolling
|
||||
|
||||
#if !CORECLR
|
||||
/// <summary>
|
||||
/// Scroll the display up one screen.
|
||||
/// </summary>
|
||||
@@ -808,6 +815,7 @@ namespace Microsoft.PowerShell
|
||||
console.SetWindowPosition(0, newTop);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endregion Screen scrolling
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,16 @@ 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);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,6 @@ namespace Microsoft.PowerShell
|
||||
_singleton.ClearStatusMessage(render: false);
|
||||
}
|
||||
_singleton._edits[_singleton._undoEditIndex - 1].Undo();
|
||||
_singleton._edits.RemoveAt(_singleton._undoEditIndex - 1);
|
||||
_singleton._undoEditIndex--;
|
||||
if (_singleton._options.EditMode == EditMode.Vi && _singleton._current >= _singleton._buffer.Length)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user