mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 04:36:39 +00:00
238 lines
9.3 KiB
C#
238 lines
9.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Management.Automation;
|
|
using System.Management.Automation.Runspaces;
|
|
using System.Management.Automation.Host;
|
|
using System.Globalization;
|
|
using System.Reflection;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace Microsoft.PowerShell.CoreConsoleHost
|
|
{
|
|
// this is all from https://msdn.microsoft.com/en-us/library/ee706570%28v=vs.85%29.aspx
|
|
|
|
internal class MyRawUserInterface : PSHostRawUserInterface
|
|
{
|
|
/// <summary>
|
|
/// Gets or sets the background color of the displayed text.
|
|
/// This maps to the corresponding Console.Background property.
|
|
/// </summary>
|
|
public override ConsoleColor BackgroundColor
|
|
{
|
|
get { return Console.BackgroundColor; }
|
|
set { Console.BackgroundColor = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the size of the host buffer. In this example the
|
|
/// buffer size is adapted from the Console buffer size members.
|
|
/// </summary>
|
|
public override Size BufferSize
|
|
{
|
|
get { return new Size(Console.BufferWidth, Console.BufferHeight); }
|
|
set { Console.SetBufferSize(value.Width, value.Height); }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the cursor position. In this example this
|
|
/// functionality is not needed so the property throws a
|
|
/// NotImplementException exception.
|
|
/// </summary>
|
|
public override Coordinates CursorPosition
|
|
{
|
|
get { return new Coordinates(Console.CursorLeft, Console.CursorTop); }
|
|
set { Console.SetCursorPosition(value.X, value.Y); }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the size of the displayed cursor. In this example
|
|
/// the cursor size is taken directly from the Console.CursorSize
|
|
/// property.
|
|
/// </summary>
|
|
public override int CursorSize
|
|
{
|
|
get { return Console.CursorSize; }
|
|
set { Console.CursorSize = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the foreground color of the displayed text.
|
|
/// This maps to the corresponding Console.ForgroundColor property.
|
|
/// </summary>
|
|
public override ConsoleColor ForegroundColor
|
|
{
|
|
get { return Console.ForegroundColor; }
|
|
set { Console.ForegroundColor = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets a value indicating whether the user has pressed a key. This maps
|
|
/// to the corresponding Console.KeyAvailable property.
|
|
/// </summary>
|
|
public override bool KeyAvailable
|
|
{
|
|
get { return Console.KeyAvailable; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the dimensions of the largest window that could be
|
|
/// rendered in the current display, if the buffer was at the least
|
|
/// that large. This example uses the Console.LargestWindowWidth and
|
|
/// Console.LargestWindowHeight properties to determine the returned
|
|
/// value of this property.
|
|
/// </summary>
|
|
public override Size MaxPhysicalWindowSize
|
|
{
|
|
get { return new Size(Console.LargestWindowWidth, Console.LargestWindowHeight); }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the dimentions of the largest window size that can be
|
|
/// displayed. This example uses the Console.LargestWindowWidth and
|
|
/// console.LargestWindowHeight properties to determine the returned
|
|
/// value of this property.
|
|
/// </summary>
|
|
public override Size MaxWindowSize
|
|
{
|
|
get { return new Size(Console.LargestWindowWidth, Console.LargestWindowHeight); }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the position of the displayed window. This example
|
|
/// uses the Console window position APIs to determine the returned
|
|
/// value of this property.
|
|
/// </summary>
|
|
public override Coordinates WindowPosition
|
|
{
|
|
get { return new Coordinates(Console.WindowLeft, Console.WindowTop); }
|
|
set { Console.SetWindowPosition(value.X, value.Y); }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the size of the displayed window. This example
|
|
/// uses the corresponding Console window size APIs to determine the
|
|
/// returned value of this property.
|
|
/// </summary>
|
|
public override Size WindowSize
|
|
{
|
|
get { return new Size(Console.WindowWidth, Console.WindowHeight); }
|
|
set { Console.SetWindowSize(value.Width, value.Height); }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Cached Window Title, for systems that needs it
|
|
/// </summary>
|
|
private string title = String.Empty;
|
|
|
|
/// <summary>
|
|
/// Gets or sets the title of the displayed window. The example
|
|
/// maps the Console.Title property to the value of this property.
|
|
/// </summary>
|
|
public override string WindowTitle
|
|
{
|
|
get
|
|
{
|
|
// In Unix/Linux systems, Console.Title current results in a not-implemented
|
|
// exception. In that case, we return a cached copy of title that was set earlier.
|
|
// Obviously, this will not work if: 1) Title was never set in PowerShell, or 2)
|
|
// one sets the windows's title outside of PowerShell.
|
|
string result;
|
|
try
|
|
{
|
|
result = Console.Title;
|
|
}
|
|
catch (PlatformNotSupportedException)
|
|
{
|
|
return title;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
set
|
|
{
|
|
Console.Title = value;
|
|
title = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// This API resets the input buffer. In this example this
|
|
/// functionality is not needed so the method returns nothing.
|
|
/// </summary>
|
|
public override void FlushInputBuffer()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// This API returns a rectangular region of the screen buffer. In
|
|
/// this example this functionality is not needed so the method throws
|
|
/// a NotImplementException exception.
|
|
/// </summary>
|
|
/// <param name="rectangle">Defines the size of the rectangle.</param>
|
|
/// <returns>Throws a NotImplementedException exception.</returns>
|
|
public override BufferCell[,] GetBufferContents(Rectangle rectangle)
|
|
{
|
|
throw new NotImplementedException(
|
|
"The method or operation is not implemented.");
|
|
}
|
|
|
|
/// <summary>
|
|
/// This API reads a pressed, released, or pressed and released keystroke
|
|
/// from the keyboard device, blocking processing until a keystroke is
|
|
/// typed that matches the specified keystroke options.
|
|
/// </summary>
|
|
/// <param name="options">Unused</param>
|
|
public override KeyInfo ReadKey(ReadKeyOptions options)
|
|
{
|
|
ConsoleKeyInfo key = Console.ReadKey();
|
|
return new KeyInfo((int)key.Key, key.KeyChar, new ControlKeyStates(), true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// This API crops a region of the screen buffer. In this example
|
|
/// this functionality is not needed so the method throws a
|
|
/// NotImplementException exception.
|
|
/// </summary>
|
|
/// <param name="source">The region of the screen to be scrolled.</param>
|
|
/// <param name="destination">The region of the screen to receive the
|
|
/// source region contents.</param>
|
|
/// <param name="clip">The region of the screen to include in the operation.</param>
|
|
/// <param name="fill">The character and attributes to be used to fill all cell.</param>
|
|
public override void ScrollBufferContents(Rectangle source, Coordinates destination, Rectangle clip, BufferCell fill)
|
|
{
|
|
throw new NotImplementedException(
|
|
"The method or operation is not implemented.");
|
|
}
|
|
|
|
/// <summary>
|
|
/// This method copies an array of buffer cells into the screen buffer
|
|
/// at a specified location. In this example this functionality is
|
|
/// not needed so the method throws a NotImplementedException exception.
|
|
/// </summary>
|
|
/// <param name="origin">The parameter is not used.</param>
|
|
/// <param name="contents">The parameter is not used.</param>
|
|
public override void SetBufferContents(Coordinates origin,
|
|
BufferCell[,] contents)
|
|
{
|
|
throw new NotImplementedException(
|
|
"The method or operation is not implemented.");
|
|
}
|
|
|
|
/// <summary>
|
|
/// This method copies a given character, foreground color, and background
|
|
/// color to a region of the screen buffer. In this example this
|
|
/// functionality is not needed so the method throws a
|
|
/// NotImplementException exception./// </summary>
|
|
/// <param name="rectangle">Defines the area to be filled. </param>
|
|
/// <param name="fill">Defines the fill character.</param>
|
|
public override void SetBufferContents(Rectangle rectangle, BufferCell fill)
|
|
{
|
|
throw new NotImplementedException(
|
|
"The method or operation is not implemented.");
|
|
}
|
|
}
|
|
}
|