Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
MshHostRawUserInterface.cs1916 linesDownload Raw Back to hostifaces
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System.Globalization;5 6#pragma warning disable 1634, 1691 // Stops compiler from warning about unknown warnings7 8namespace System.Management.Automation.Host9{10    #region Ancillary types.11 12    // I would have preferred to make these nested types within PSHostRawUserInterface, but that13    // is evidently discouraged by the .net design guidelines.14 15    /// <summary>16    /// Represents an (x,y) coordinate pair.17    /// </summary>18    public19    struct Coordinates20    {21        #region DO NOT REMOVE OR RENAME THESE FIELDS - it will break remoting compatibility with Windows PowerShell22 23        private int x;24        private int y;25 26        #endregion27 28        /// <summary>29        /// Gets and sets the X coordinate.30        /// </summary>31        public int X32        {33            get { return x; }34 35            set { x = value; }36        }37 38        /// <summary>39        /// Gets and sets the Y coordinate.40        /// </summary>41        public int Y42        {43            get { return y; }44 45            set { y = value; }46        }47 48        /// <summary>49        /// Initializes a new instance of the Coordinates class and defines the X and Y values.50        /// </summary>51        /// <param name="x">52        /// The X coordinate53        /// </param>54        /// <param name="y">55        /// The Y coordinate56        /// </param>57        public58        Coordinates(int x, int y)59        {60            this.x = x;61            this.y = y;62        }63 64        /// <summary>65        /// Overrides <see cref="object.ToString"/>66        /// </summary>67        /// <returns>68        /// "a,b" where a and b are the values of the X and Y properties.69        /// </returns>70        public override71        string72        ToString()73        {74            return string.Create(CultureInfo.InvariantCulture, $"{X},{Y}");75        }76 77        /// <summary>78        /// Overrides <see cref="object.Equals(object)"/>79        /// </summary>80        /// <param name="obj">81        /// object to be compared for equality.82        /// </param>83        /// <returns>84        /// True if <paramref name="objB"/> is Coordinates and its X and Y values are the same as those of this instance,85        /// false if not.86        /// </returns>87        public override88        bool89        Equals(object obj)90        {91            bool result = false;92 93            if (obj is Coordinates)94            {95                result = this == ((Coordinates)obj);96            }97 98            return result;99        }100 101        /// <summary>102        /// Overrides <see cref="object.GetHashCode"/>103        /// </summary>104        /// <returns>105        /// Hash code for this instance.106        /// </returns>107        public override108        int109        GetHashCode()110        {111            // idea: consider X the high-order part of a 64-bit in, and Y the lower order half.  Then use the int64.GetHashCode.112 113            UInt64 i64 = 0;114 115            if (X < 0)116            {117                if (X == Int32.MinValue)118                {119                    // add one and invert to avoid an overflow.120 121                    i64 = (UInt64)(-1 * (X + 1));122                }123                else124                {125                    i64 = (UInt64)(-X);126                }127            }128            else129            {130                i64 = (UInt64)X;131            }132 133            // rotate 32 bits to the left.134 135            i64 *= 0x100000000U;136 137            // mask in Y138 139            if (Y < 0)140            {141                if (Y == Int32.MinValue)142                {143                    i64 += (UInt64)(-1 * (Y + 1));144                }145                else146                {147                    i64 += (UInt64)(-Y);148                }149            }150            else151            {152                i64 += (UInt64)Y;153            }154 155            int result = i64.GetHashCode();156 157            return result;158        }159 160        /// <summary>161        /// Compares two instances for equality.162        /// </summary>163        /// <param name="first">164        /// The left side operand.165        /// </param>166        /// <param name="second">167        /// The right side operand.168        /// </param>169        /// <returns>170        /// true if the respective X and Y values are the same, false otherwise.171        /// </returns>172        public static173        bool174        operator ==(Coordinates first, Coordinates second)175        {176            bool result = first.X == second.X && first.Y == second.Y;177 178            return result;179        }180 181        /// <summary>182        /// Compares two instances for inequality.183        /// </summary>184        /// <param name="first">185        /// The left side operand.186        /// </param>187        /// <param name="second">188        /// The right side operand.189        /// </param>190        /// <returns>191        /// true if any of the respective either X or Y field is not the same, false otherwise.192        /// </returns>193        public static194        bool195        operator !=(Coordinates first, Coordinates second)196        {197            return !(first == second);198        }199    }200 201    /// <summary>202    /// Represents a width and height pair.203    /// </summary>204    public205    struct Size206    {207        #region DO NOT REMOVE OR RENAME THESE FIELDS - it will break remoting compatibility with Windows PowerShell208 209        private int width;210        private int height;211 212        #endregion213 214        /// <summary>215        /// Gets and sets the Width.216        /// </summary>217        public int Width218        {219            get { return width; }220 221            set { width = value; }222        }223 224        /// <summary>225        /// Gets and sets the Height.226        /// </summary>227        public int Height228        {229            get { return height; }230 231            set { height = value; }232        }233 234        /// <summary>235        /// Initialize a new instance of the Size class and defines the Width and Height values.236        /// </summary>237        /// <param name="width">238        /// The Width239        /// </param>240        /// <param name="height">241        /// The Height242        /// </param>243        public244        Size(int width, int height)245        {246            this.width = width;247            this.height = height;248        }249 250        /// <summary>251        /// Overloads <see cref="object.ToString"/>252        /// </summary>253        /// <returns>254        /// "a,b" where a and b are the values of the Width and Height properties.255        /// </returns>256        public override257        string258        ToString()259        {260            return string.Create(CultureInfo.InvariantCulture, $"{Width},{Height}");261        }262 263        /// <summary>264        /// Overrides <see cref="object.Equals(object)"/>265        /// </summary>266        /// <param name="obj">267        /// object to be compared for equality.268        /// </param>269        /// <returns>270        /// True if <paramref name="obj"/> is Size and its Width and Height values are the same as those of this instance,271        /// false if not.272        /// </returns>273        public override274        bool275        Equals(object obj)276        {277            bool result = false;278 279            if (obj is Size)280            {281                result = this == ((Size)obj);282            }283 284            return result;285        }286 287        /// <summary>288        /// Overrides <see cref="object.GetHashCode"/>289        /// </summary>290        /// <returns>291        /// Hash code for this instance.292        /// <!--293        /// consider Width the high-order part of a 64-bit in, and294        /// Height the lower order half.  Then use the int64.GetHashCode.-->295        /// </returns>296        public override297        int298        GetHashCode()299        {300            // idea: consider Width the high-order part of a 64-bit in, and Height the lower order half.  Then use the int64.GetHashCode.301 302            UInt64 i64 = 0;303 304            if (Width < 0)305            {306                if (Width == Int32.MinValue)307                {308                    // add one and invert to avoid an overflow.309 310                    i64 = (UInt64)(-1 * (Width + 1));311                }312                else313                {314                    i64 = (UInt64)(-Width);315                }316            }317            else318            {319                i64 = (UInt64)Width;320            }321 322            // rotate 32 bits to the left.323 324            i64 *= 0x100000000U;325 326            // mask in Height327 328            if (Height < 0)329            {330                if (Height == Int32.MinValue)331                {332                    i64 += (UInt64)(-1 * (Height + 1));333                }334                else335                {336                    i64 += (UInt64)(-Height);337                }338            }339            else340            {341                i64 += (UInt64)Height;342            }343 344            int result = i64.GetHashCode();345 346            return result;347        }348 349        /// <summary>350        /// Compares two instances for equality.351        /// </summary>352        /// <param name="first">353        /// The left side operand.354        /// </param>355        /// <param name="second">356        /// The right side operand.357        /// </param>358        /// <returns>359        /// true if the respective Width and Height fields are the same, false otherwise.360        /// </returns>361        public static362        bool363        operator ==(Size first, Size second)364        {365            bool result = first.Width == second.Width && first.Height == second.Height;366 367            return result;368        }369 370        /// <summary>371        /// Compares two instances for inequality.372        /// </summary>373        /// <param name="first">374        /// The left side operand.375        /// </param>376        /// <param name="second">377        /// The right side operand.378        /// </param>379        /// <returns>380        /// true if any of the respective Width and Height fields are not the same, false otherwise.381        /// </returns>382        public static383        bool384        operator !=(Size first, Size second)385        {386            return !(first == second);387        }388    }389 390    /// <summary>391    /// Governs the behavior of <see cref="System.Management.Automation.Host.PSHostRawUserInterface.ReadKey()"/>392    /// and <see cref="System.Management.Automation.Host.PSHostRawUserInterface.ReadKey(System.Management.Automation.Host.ReadKeyOptions)"/>393    /// </summary>394    [Flags]395    public396    enum397    ReadKeyOptions398    {399        /// <summary>400        /// Allow Ctrl-C to be processed as a keystroke, as opposed to causing a break event.401        /// </summary>402        AllowCtrlC = 0x0001,403 404        /// <summary>405        /// Do not display the character for the key in the window when pressed.406        /// </summary>407        NoEcho = 0x0002,408 409        /// <summary>410        /// Include key down events.  Either one of IncludeKeyDown and IncludeKeyUp or both must be specified.411        /// </summary>412        IncludeKeyDown = 0x0004,413 414        /// <summary>415        /// Include key up events.  Either one of IncludeKeyDown and IncludeKeyUp or both must be specified.416        /// </summary>417        IncludeKeyUp = 0x0008418    }419 420    /// <summary>421    /// Defines the states of Control Key.422    /// </summary>423    [Flags]424    public425    enum ControlKeyStates426    {427        /// <summary>428        /// The right alt key is pressed.429        /// </summary>430        RightAltPressed = 0x0001,431 432        /// <summary>433        /// The left alt key is pressed.434        /// </summary>435        LeftAltPressed = 0x0002,436 437        /// <summary>438        /// The right ctrl key is pressed.439        /// </summary>440        RightCtrlPressed = 0x0004,441 442        /// <summary>443        /// The left ctrl key is pressed.444        /// </summary>445        LeftCtrlPressed = 0x0008,446 447        /// <summary>448        /// The shift key is pressed.449        /// </summary>450        ShiftPressed = 0x0010,451 452        /// <summary>453        /// The numlock light is on.454        /// </summary>455        NumLockOn = 0x0020,456 457        /// <summary>458        /// The scrolllock light is on.459        /// </summary>460        ScrollLockOn = 0x0040,461 462        /// <summary>463        /// The capslock light is on.464        /// </summary>465        CapsLockOn = 0x0080,466 467        /// <summary>468        /// The key is enhanced.469        /// </summary>470        EnhancedKey = 0x0100471    }472 473    /// <summary>474    /// Represents information of a keystroke.475    /// </summary>476    public477    struct KeyInfo478    {479        #region DO NOT REMOVE OR RENAME THESE FIELDS - it will break remoting compatibility with Windows PowerShell480 481        private int virtualKeyCode;482        private char character;483        private ControlKeyStates controlKeyState;484        private bool keyDown;485 486        #endregion487 488        /// <summary>489        /// Gets and set device-independent key.490        /// </summary>491        public int VirtualKeyCode492        {493            get { return virtualKeyCode; }494 495            set { virtualKeyCode = value; }496        }497 498        /// <summary>499        /// Gets and set unicode Character of the key.500        /// </summary>501        public char Character502        {503            get { return character; }504 505            set { character = value; }506        }507 508        /// <summary>509        /// State of the control keys.510        /// </summary>511        public ControlKeyStates ControlKeyState512        {513            get { return controlKeyState; }514 515            set { controlKeyState = value; }516        }517 518        /// <summary>519        /// Gets and set the status of whether this instance is generated by a key pressed or released.520        /// </summary>521        public bool KeyDown522        {523            get { return keyDown; }524 525            set { keyDown = value; }526        }527 528        /// <summary>529        /// Initialize a new instance of the KeyInfo class and defines the VirtualKeyCode,530        /// Character, ControlKeyState and KeyDown values.531        /// </summary>532        /// <param name="virtualKeyCode">533        /// The virtual key code534        /// </param>535        /// <param name="ch">536        /// The character537        /// </param>538        /// <param name="controlKeyState">539        /// The control key state540        /// </param>541        /// <param name="keyDown">542        /// Whether the key is pressed or released543        /// </param>544        public545        KeyInfo546        (547            int virtualKeyCode,548            char ch,549            ControlKeyStates controlKeyState,550            bool keyDown551        )552        {553            this.virtualKeyCode = virtualKeyCode;554            this.character = ch;555            this.controlKeyState = controlKeyState;556            this.keyDown = keyDown;557        }558 559        /// <summary>560        /// Overloads <see cref="object.ToString"/>561        /// </summary>562        /// <returns>563        /// "a,b,c,d" where a, b, c, and d are the values of the VirtualKeyCode, Character, ControlKeyState, and KeyDown properties.564        /// </returns>565        public override566        string567        ToString()568        {569            return string.Create(CultureInfo.InvariantCulture, $"{VirtualKeyCode},{Character},{ControlKeyState},{KeyDown}");570        }571        /// <summary>572        /// Overrides <see cref="object.Equals(object)"/>573        /// </summary>574        /// <param name="obj">575        /// object to be compared for equality.576        /// </param>577        /// <returns>578        /// True if <paramref name="obj"/> is KeyInfo and its VirtualKeyCode, Character, ControlKeyState, and KeyDown values are the579        /// same as those of this instance, false if not.580        /// </returns>581        public override582        bool583        Equals(object obj)584        {585            bool result = false;586 587            if (obj is KeyInfo)588            {589                result = this == ((KeyInfo)obj);590            }591 592            return result;593        }594 595        /// <summary>596        /// Overrides <see cref="object.GetHashCode"/>597        /// </summary>598        /// <returns>599        /// Hash code for this instance.600        /// <!--consider KeyDown (true == 1, false == 0) the highest-order nibble,601        ///                ControlKeyState the second to fourth highest-order nibbles602        ///                VirtualKeyCode the lower-order nibbles of a 32-bit int,603        ///       Then use the UInt32.GetHashCode.-->604        /// </returns>605        public override606        int607        GetHashCode()608        {609            // idea: consider KeyDown (true == 1, false == 0) the highest-order nibble,610            //                ControlKeyState the second to fourth highest-order nibbles611            //                VirtualKeyCode the lower-order nibbles of a 32-bit int,612            //       Then use the UInt32.GetHashCode.613 614            UInt32 i32 = KeyDown ? 0x10000000U : 0;615 616            // mask in ControlKeyState617            i32 |= ((uint)ControlKeyState) << 16;618 619            // mask in the VirtualKeyCode620            i32 |= (UInt32)VirtualKeyCode;621 622            return i32.GetHashCode();623        }624 625        /// <summary>626        /// Compares two instances for equality.627        /// </summary>628        /// <param name="first">629        /// The left side operand.630        /// </param>631        /// <param name="second">632        /// The right side operand.633        /// </param>634        /// <returns>635        /// true if the respective Character, ControlKeyStates , KeyDown, and VirtualKeyCode fields636        /// are the same, false otherwise.637        /// </returns>638        /// <exception/>639        public static640        bool641        operator ==(KeyInfo first, KeyInfo second)642        {643            bool result = first.Character == second.Character && first.ControlKeyState == second.ControlKeyState &&644                          first.KeyDown == second.KeyDown && first.VirtualKeyCode == second.VirtualKeyCode;645 646            return result;647        }648 649        /// <summary>650        /// Compares two instances for inequality.651        /// </summary>652        /// <param name="first">653        /// The left side operand.654        /// </param>655        /// <param name="second">656        /// The right side operand.657        /// </param>658        /// <returns>659        /// true if any of the respective Character, ControlKeyStates , KeyDown, or VirtualKeyCode fields660        /// are the different, false otherwise.661        /// </returns>662        /// <exception/>663        public static664        bool665        operator !=(KeyInfo first, KeyInfo second)666        {667            return !(first == second);668        }669    }670 671    /// <summary>672    /// Represents a rectangular region of the screen.673    /// <!--We use this structure instead of System.Drawing.Rectangle because S.D.R674    /// is way overkill and would bring in another assembly.-->675    /// </summary>676    public677    struct Rectangle678    {679        #region DO NOT REMOVE OR RENAME THESE FIELDS - it will break remoting compatibility with Windows PowerShell680 681        private int left;682        private int top;683        private int right;684        private int bottom;685 686        #endregion687 688        /// <summary>689        /// Gets and sets the left side of the rectangle.690        /// </summary>691        public int Left692        {693            get { return left; }694 695            set { left = value; }696        }697 698        /// <summary>699        /// Gets and sets the top of the rectangle.700        /// </summary>701        public int Top702        {703            get { return top; }704 705            set { top = value; }706        }707 708        /// <summary>709        /// Gets and sets the right side of the rectangle.710        /// </summary>711        public int Right712        {713            get { return right; }714 715            set { right = value; }716        }717 718        /// <summary>719        /// Gets and sets the bottom of the rectangle.720        /// </summary>721        public int Bottom722        {723            get { return bottom; }724 725            set { bottom = value; }726        }727 728        /// <summary>729        /// Initialize a new instance of the Rectangle class and defines the Left, Top, Right, and Bottom values.730        /// </summary>731        /// <param name="left">732        /// The left side of the rectangle733        /// </param>734        /// <param name="top">735        /// The top of the rectangle736        /// </param>737        /// <param name="right">738        /// The right side of the rectangle739        /// </param>740        /// <param name="bottom">741        /// The bottom of the rectangle742        /// </param>743        /// <exception cref="ArgumentException">744        /// <paramref name="right"/> is less than <paramref name="left"/>;745        /// <paramref name="bottom"/> is less than <paramref name="top"/>746        /// </exception>747        public748        Rectangle(int left, int top, int right, int bottom)749        {750            if (right < left)751            {752                // "right" and "left" are not localizable753                throw PSTraceSource.NewArgumentException(nameof(right), MshHostRawUserInterfaceStrings.LessThanErrorTemplate, "right", "left");754            }755 756            if (bottom < top)757            {758                // "bottom" and "top" are not localizable759                throw PSTraceSource.NewArgumentException(nameof(bottom), MshHostRawUserInterfaceStrings.LessThanErrorTemplate, "bottom", "top");760            }761 762            this.left = left;763            this.top = top;764            this.right = right;765            this.bottom = bottom;766        }767 768        /// <summary>769        /// Initializes a new instance of the Rectangle class and defines the Left, Top, Right, and Bottom values770        /// by <paramref name="upperLeft"/>, the upper left corner and <paramref name="lowerRight"/>, the lower771        /// right corner.772        /// <!--773        /// Added based on feedback from review with BCL PM.774        /// -->775        /// </summary>776        /// <param name="upperLeft">777        /// The Coordinates of the upper left corner of the Rectangle778        /// </param>779        /// <param name="lowerRight">780        /// The Coordinates of the lower right corner of the Rectangle781        /// </param>782        /// <exception/>783        public784        Rectangle(Coordinates upperLeft, Coordinates lowerRight)785            : this(upperLeft.X, upperLeft.Y, lowerRight.X, lowerRight.Y)786        {787        }788 789        /// <summary>790        /// Overloads <see cref="object.ToString"/>791        /// </summary>792        /// <returns>793        /// "a,b ; c,d" where a, b, c, and d are values of the Left, Top, Right, and Bottom properties.794        /// </returns>795        public override796        string797        ToString()798        {799            return string.Create(CultureInfo.InvariantCulture, $"{Left},{Top} ; {Right},{Bottom}");800        }801 802        /// <summary>803        /// Overrides <see cref="object.Equals(object)"/>804        /// </summary>805        /// <param name="obj">806        /// object to be compared for equality.807        /// </param>808        /// <returns>809        /// True if <paramref name="obj"/> is Rectangle and its Left, Top, Right, and Bottom values are the same as those of this instance,810        /// false if not.811        /// </returns>812        public override813        bool814        Equals(object obj)815        {816            bool result = false;817 818            if (obj is Rectangle)819            {820                result = this == ((Rectangle)obj);821            }822 823            return result;824        }825 826        /// <summary>827        /// Overrides <see cref="object.GetHashCode"/>828        /// </summary>829        /// <returns>830        /// Hash code for this instance.831        /// <!-- consider (Top XOR Bottom) the high-order part of a 64-bit int,832        ///                (Left XOR Right) the lower order half.  Then use the int64.GetHashCode.-->833        /// </returns>834        /// <exception/>835        public override836        int837        GetHashCode()838        {839            // idea: consider (Top XOR Bottom) the high-order part of a 64-bit int,840            //                (Left XOR Right) the lower order half.  Then use the int64.GetHashCode.841 842            UInt64 i64 = 0;843 844            int upper = Top ^ Bottom;845            if (upper < 0)846            {847                if (upper == Int32.MinValue)848                {849                    // add one and invert to avoid an overflow.850 851                    i64 = (UInt64)(-1 * (upper + 1));852                }853                else854                {855                    i64 = (UInt64)(-upper);856                }857            }858            else859            {860                i64 = (UInt64)upper;861            }862 863            // rotate 32 bits to the left.864 865            i64 *= 0x100000000U;866 867            // mask in lower868 869            int lower = Left ^ Right;870            if (lower < 0)871            {872                if (lower == Int32.MinValue)873                {874                    i64 += (UInt64)(-1 * (lower + 1));875                }876                else877                {878                    i64 += (UInt64)(-upper);879                }880            }881            else882            {883                i64 += (UInt64)lower;884            }885 886            int result = i64.GetHashCode();887 888            return result;889        }890 891        /// <summary>892        /// Compares two instances for equality.893        /// </summary>894        /// <param name="first">895        /// The left side operand.896        /// </param>897        /// <param name="second">898        /// The right side operand.899        /// </param>900        /// <returns>901        /// true if the respective Top, Left, Bottom, and Right fields are the same, false otherwise.902        /// </returns>903        public static904        bool905        operator ==(Rectangle first, Rectangle second)906        {907            bool result = first.Top == second.Top && first.Left == second.Left &&908             first.Bottom == second.Bottom && first.Right == second.Right;909 910            return result;911        }912 913        /// <summary>914        /// Compares two instances for inequality.915        /// </summary>916        /// <param name="first">917        /// The left side operand.918        /// </param>919        /// <param name="second">920        /// The right side operand.921        /// </param>922        /// <returns>923        /// true if any of the respective Top, Left, Bottom, and Right fields are not the same, false otherwise.924        /// </returns>925        /// <exception/>926        public static927        bool928        operator !=(Rectangle first, Rectangle second)929        {930            return !(first == second);931        }932    }933 934    /// <summary>935    /// Represents a character, a foregroundColor color, and background color.936    /// </summary>937    public938    struct BufferCell939    {940        #region DO NOT REMOVE OR RENAME THESE FIELDS - it will break remoting compatibility with Windows PowerShell941 942        private char character;943        private ConsoleColor foregroundColor;944        private ConsoleColor backgroundColor;945        private BufferCellType bufferCellType;946 947        #endregion948 949        /// <summary>950        /// Gets and sets the character value.951        /// </summary>952        public char Character953        {954            get { return character; }955 956            set { character = value; }957        }958 959        // we reuse System.ConsoleColor - it's in the core assembly, and I think it would be confusing to create another960        // essentially identical enum961 962        /// <summary>963        /// Gets and sets the foreground color.964        /// </summary>965        public ConsoleColor ForegroundColor966        {967            get { return foregroundColor; }968 969            set { foregroundColor = value; }970        }971 972        /// <summary>973        /// Gets and sets the background color.974        /// </summary>975        public ConsoleColor BackgroundColor976        {977            get { return backgroundColor; }978 979            set { backgroundColor = value; }980        }981 982        /// <summary>983        /// Gets and sets the type value.984        /// </summary>985        public BufferCellType BufferCellType986        {987            get { return bufferCellType; }988 989            set { bufferCellType = value; }990        }991 992        /// <summary>993        /// Initializes a new instance of the BufferCell class and defines the994        /// Character, ForegroundColor, BackgroundColor and Type values.995        /// </summary>996        /// <param name="character">997        /// The character in this BufferCell object998        /// </param>999        /// <param name="foreground">1000        /// The foreground color of this BufferCell object1001        /// </param>1002        /// <param name="background">1003        /// The foreground color of this BufferCell object1004        /// </param>1005        /// <param name="bufferCellType">1006        /// The type of this BufferCell object1007        /// </param>1008        public1009        BufferCell(char character, ConsoleColor foreground, ConsoleColor background, BufferCellType bufferCellType)1010        {1011            this.character = character;1012            this.foregroundColor = foreground;1013            this.backgroundColor = background;1014            this.bufferCellType = bufferCellType;1015        }1016 1017        /// <summary>1018        /// Overloads <see cref="object.ToString"/>1019        /// </summary>1020        /// <returns>1021        /// "'a' b c d" where a, b, c, and d are the values of the Character, ForegroundColor, BackgroundColor, and Type properties.1022        /// </returns>1023        public override1024        string1025        ToString()1026        {1027            return string.Create(CultureInfo.InvariantCulture, $"'{Character}' {ForegroundColor} {BackgroundColor} {BufferCellType}");1028        }1029 1030        /// <summary>1031        /// Overrides <see cref="object.Equals(object)"/>1032        /// </summary>1033        /// <param name="obj">1034        /// object to be compared for equality.1035        /// </param>1036        /// <returns>1037        /// True if <paramref name="obj"/> is BufferCell and its Character, ForegroundColor, BackgroundColor, and BufferCellType values1038        /// are the same as those of this instance, false if not.1039        /// </returns>1040        public override1041        bool1042        Equals(object obj)1043        {1044            bool result = false;1045 1046            if (obj is BufferCell)1047            {1048                result = this == ((BufferCell)obj);1049            }1050 1051            return result;1052        }1053 1054        /// <summary>1055        /// Overrides <see cref="object.GetHashCode"/>1056        /// <!-- consider (ForegroundColor XOR BackgroundColor) the high-order part of a 32-bit int,1057        ///      and Character the lower order half.  Then use the int32.GetHashCode.-->1058        /// </summary>1059        /// <returns>1060        /// Hash code for this instance.1061        ///1062        /// </returns>1063        public override1064        int1065        GetHashCode()1066        {1067            // idea: consider (ForegroundColor XOR BackgroundColor) the high-order part of a 32-bit int,1068            //                and Character the lower order half.  Then use the int32.GetHashCode.1069 1070            UInt32 i32 = ((uint)(ForegroundColor ^ BackgroundColor)) << 16;1071 1072            // mask in Height1073 1074            i32 |= (UInt16)Character;1075            int result = i32.GetHashCode();1076 1077            return result;1078        }1079 1080        /// <summary>1081        /// Compares two instances for equality.1082        /// </summary>1083        /// <param name="first">1084        /// The left side operand.1085        /// </param>1086        /// <param name="second">1087        /// The right side operand.1088        /// </param>1089        /// <returns>1090        /// true if the respective Character, ForegroundColor, BackgroundColor, and BufferCellType values are the same, false otherwise.1091        /// </returns>1092        public static1093        bool1094        operator ==(BufferCell first, BufferCell second)1095        {1096            bool result = first.Character == second.Character &&1097                          first.BackgroundColor == second.BackgroundColor &&1098                          first.ForegroundColor == second.ForegroundColor &&1099                          first.BufferCellType == second.BufferCellType;1100 1101            return result;1102        }1103 1104        /// <summary>1105        /// Compares two instances for inequality.1106        /// </summary>1107        /// <param name="first">1108        /// The left side operand.1109        /// </param>1110        /// <param name="second">1111        /// The right side operand.1112        /// </param>1113        /// <returns>1114        /// true if any of the respective Character, ForegroundColor, BackgroundColor, and BufferCellType values are not the same,1115        /// false otherwise.1116        /// </returns>1117        public static1118        bool1119        operator !=(BufferCell first, BufferCell second)1120        {1121            return !(first == second);1122        }1123 1124        private const string StringsBaseName = "MshHostRawUserInterfaceStrings";1125    }1126 1127    /// <summary>1128    /// Defines three types of BufferCells to accommodate for hosts that use up to two cells1129    /// to display a character in some languages such as Chinese and Japanese.1130    /// </summary>1131    public enum1132    BufferCellType1133    {1134        /// <summary>1135        /// Character occupies one BufferCell.1136        /// </summary>1137        Complete,1138 1139        /// <summary>1140        /// Character occupies two BufferCells and this is the leading one.1141        /// </summary>1142        Leading,1143 1144        /// <summary>1145        /// Preceded by a Leading BufferCell.1146        /// </summary>1147        Trailing1148    }1149 1150    #endregion Ancillary types1151 1152    /// <summary>1153    /// Defines the lowest-level user interface functions that an interactive application hosting PowerShell1154    /// <see cref="System.Management.Automation.Runspaces.Runspace"/> can choose to implement if it wants to1155    /// support any cmdlet that does character-mode interaction with the user.1156    /// </summary>1157    /// <remarks>1158    /// It models an 2-dimensional grid of cells called a Buffer.  A buffer has a visible rectangular region, called a window.1159    /// Each cell of the grid has a character, a foreground color, and a background color.  When the buffer has input focus, it1160    /// shows a cursor positioned in one cell.  Keystrokes can be read from the buffer and optionally echoed at the current1161    /// cursor position.1162    /// </remarks>1163    /// <seealso cref="System.Management.Automation.Host.PSHost"/>1164    /// <seealso cref="System.Management.Automation.Host.PSHostUserInterface"/>1165    public abstract1166    class PSHostRawUserInterface1167    {1168        /// <summary>1169        /// Protected constructor which does nothing.  Provided per .Net design guidelines section 4.3.1.1170        /// </summary>1171        protected1172        PSHostRawUserInterface()1173        {1174            // do nothing1175        }1176 1177        /// <summary>1178        /// Gets or sets the color used to render characters on the screen buffer. Each character cell in the screen buffer can1179        /// have a separate foreground color.1180        /// </summary>1181        /// <!--Design note: we separate Foreground and Background colors into separate properties rather than having a single1182        /// property that is a ColorAttribute.  While a single property that takes a struct is consistent with all of our1183        /// other properties that take structs (e.g. -Position, -Size), I anticipate that the more common use-case for color1184        /// is to just change the foreground color.-->1185        /// <seealso cref="System.Management.Automation.Host.PSHostRawUserInterface.BackgroundColor"/>1186        public abstract1187        ConsoleColor1188        ForegroundColor1189        {1190            get;1191            set;1192        }1193 1194        /// <summary>1195        /// Gets or sets the color used to render the background behind characters on the screen buffer.  Each character cell in1196        /// the screen buffer can have a separate background color.1197        /// </summary>1198        /// <seealso cref="System.Management.Automation.Host.PSHostRawUserInterface.ForegroundColor"/>1199        public abstract1200        ConsoleColor

Showing the first 1,200 of 1916 lines. Download the file for the rest.