/// <summary> /// Reads a key stroke from the keyboard device, blocking until a keystroke is typed. /// Either one of ReadKeyOptions.IncludeKeyDown and ReadKeyOptions.IncludeKeyUp or both must be specified. /// </summary> /// <param name="options"> /// A bit mask of the options to be used to read the keyboard. Constants defined by /// <see cref="T:System.Management.Automation.Host.ReadKeyOptions" /> /// </param> /// <returns> /// Key stroke depending on the value of <paramref name="options" />. /// </returns> /// <exception cref="T:System.ArgumentException"> /// Neither ReadKeyOptions.IncludeKeyDown nor ReadKeyOptions.IncludeKeyUp is specified. /// </exception> /// <example> /// <MSH> /// $option = [System.Management.Automation.Host.ReadKeyOptions]"IncludeKeyDown"; /// $host.UI.RawUI.ReadKey($option) /// </MSH> /// </example> /// <seealso cref="T:System.Management.Automation.Host.ReadKeyOptions" /> /// <seealso cref="M:System.Management.Automation.Host.PSHostRawUserInterface.ReadKey" /> /// <seealso cref="M:System.Management.Automation.Host.PSHostRawUserInterface.ReadKey(System.Management.Automation.Host.ReadKeyOptions)" /> /// <seealso cref="M:System.Management.Automation.Host.PSHostRawUserInterface.FlushInputBuffer" /> /// <seealso cref="P:System.Management.Automation.Host.PSHostRawUserInterface.KeyAvailable" /> public override KeyInfo ReadKey(ReadKeyOptions options) { var ch = TermInterface.ReadKey((int)options); return(new KeyInfo() { Character = ch, KeyDown = true }); }
/// <summary> /// Copies the <see cref="T:System.Manageent.Automation.Host.BufferCell" /> array into the screen buffer at the /// given origin, clipping such that cells in the array that would fall outside the screen buffer are ignored. /// </summary> /// <param name="origin"> /// The top left corner of the rectangular screen area to which <paramref name="contents" /> is copied. /// </param> /// <param name="contents"> /// A rectangle of <see cref="T:System.Management.Automation.Host.BufferCell" /> objects to be copied to the /// screen buffer. /// </param> /// <seealso cref="M:System.Management.Automation.Host.PSHostRawUserInterface.NewBufferCellArray(System.Int32,System.Int32,System.Management.Automation.Host.BufferCell)" /> /// <seealso cref="M:System.Management.Automation.Host.PSHostRawUserInterface.NewBufferCellArray(System.Management.Automation.Host.Size,System.Management.Automation.Host.BufferCell)" /> /// <seealso cref="M:System.Management.Automation.Host.PSHostRawUserInterface.NewBufferCellArray(System.String[],System.ConsoleColor,System.ConsoleColor)" /> /// <seealso cref="M:System.Management.Automation.Host.PSHostRawUserInterface.LengthInBufferCells(System.Char)" /> /// <seealso cref="M:System.Management.Automation.Host.PSHostRawUserInterface.LengthInBufferCells(System.String)" /> /// <seealso cref="M:System.Management.Automation.Host.PSHostRawUserInterface.SetBufferContents(System.Management.Automation.Host.Rectangle,System.Management.Automation.Host.BufferCell)" /> /// <seealso cref="M:System.Management.Automation.Host.PSHostRawUserInterface.GetBufferContents(System.Management.Automation.Host.Rectangle)" /> /// <seealso cref="M:System.Management.Automation.Host.PSHostRawUserInterface.ScrollBufferContents(System.Management.Automation.Host.Rectangle,System.Management.Automation.Host.Coordinates,System.Management.Automation.Host.Rectangle,System.Management.Automation.Host.BufferCell)" /> public override void SetBufferContents(Coordinates origin, BufferCell[,] contents) { Trace.WriteLine($"set buffer {contents.Length}"); Logger.Debug($"SetBufferContents {origin} ({contents.Length})"); var length = contents.GetLength(1); var g = new ushort[length]; var advanceWidths = new double[length]; Debug.WriteLine(nameof(SetBufferContents)); var k = 0; var l = contents.GetLength(0); try { for (var i = origin.Y; k < l; i++, k++) { var z = 0; var bound = contents.GetLength(1); for (var j = origin.X; z < bound; j++, z++) { try { var bufferCell = contents[k, z]; //buf.Buf[i, j] = bufferCell; var bufferCellCharacter = bufferCell.Character; var bufferCellBackgroundColor = bufferCell.BackgroundColor; var bufferCellForegroundColor = bufferCell.ForegroundColor; TermInterface.Dispatcher.Invoke(() => { try { var xx = bound; TermInterface.SetCellCharacter(i, j, bufferCellCharacter, bufferCellForegroundColor, bufferCellBackgroundColor, false, true); } catch (Exception ex) { throw; } }); } catch (Exception ex) { } } } } catch (Exception ex) { Debug.WriteLine(ex); } }
/// <summary> /// Copies a given character to all of the character cells in the screen buffer with the indicated colors. /// </summary> /// <param name="rectangle"> /// The rectangle on the screen buffer to which <paramref name="fill" /> is copied. /// If all elements are -1, the entire screen buffer will be copied with <paramref name="fill" />. /// </param> /// <param name="fill"> /// The character and attributes used to fill <paramref name="rectangle" />. /// </param> /// <remarks> /// Provided for clearing regions -- less chatty than passing an array of cells. /// </remarks> /// <example> /// <snippet Code="C#"> /// using System; /// using System.Management.Automation; /// using System.Management.Automation.Host; /// namespace Microsoft.Samples.MSH.Cmdlet /// { /// [Cmdlet("Clear","Screen")] /// public class ClearScreen : PSCmdlet /// { /// protected override void BeginProcessing() /// { /// Host.UI.RawUI.SetBufferContents(new Rectangle(-1, -1, -1, -1), /// new BufferCell(' ', Host.UI.RawUI.ForegroundColor, Host.UI.RawUI.BackgroundColor)) /// } /// } /// } /// </snippet> /// </example> /// <seealso cref="M:System.Management.Automation.Host.PSHostRawUserInterface.NewBufferCellArray(System.Int32,System.Int32,System.Management.Automation.Host.BufferCell)" /> /// <seealso cref="M:System.Management.Automation.Host.PSHostRawUserInterface.NewBufferCellArray(System.Management.Automation.Host.Size,System.Management.Automation.Host.BufferCell)" /> /// <seealso cref="M:System.Management.Automation.Host.PSHostRawUserInterface.NewBufferCellArray(System.String[],System.ConsoleColor,System.ConsoleColor)" /> /// <seealso cref="M:System.Management.Automation.Host.PSHostRawUserInterface.LengthInBufferCells(System.Char)" /> /// <seealso cref="M:System.Management.Automation.Host.PSHostRawUserInterface.LengthInBufferCells(System.String)" /> /// <seealso cref="M:System.Management.Automation.Host.PSHostRawUserInterface.SetBufferContents(System.Management.Automation.Host.Coordinates,System.Management.Automation.Host.BufferCell[0:,0:])" /> /// <seealso cref="M:System.Management.Automation.Host.PSHostRawUserInterface.GetBufferContents(System.Management.Automation.Host.Rectangle)" /> /// <seealso cref="M:System.Management.Automation.Host.PSHostRawUserInterface.ScrollBufferContents(System.Management.Automation.Host.Rectangle,System.Management.Automation.Host.Coordinates,System.Management.Automation.Host.Rectangle,System.Management.Automation.Host.BufferCell)" /> public override void SetBufferContents(Rectangle rectangle, BufferCell fill) { for (int j = rectangle.Top; j < rectangle.Bottom; j++) { for (int i = rectangle.Left; i < rectangle.Right; i++) { buf.Buf[j, i] = fill; TermInterface.Dispatcher.Invoke(() => TermInterface.SetCellCharacter(j, i, fill.Character, ConsoleColor.White, ConsoleColor.Black, false, true)); } } }