MegaBites-AI/Windows-powershell
0372
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System;5using System.Collections.Generic;6 7namespace System.Management.Automation8{9 /// <summary>10 /// Class to help with VT escape sequences.11 /// </summary>12 [Obsolete("This class is deprecated. Use 'System.Management.Automation.PSStyle' instead.", error: true)]13 public sealed class VTUtility14 {15 /// <summary>16 /// Available VT escape codes other than colors.17 /// </summary>18 public enum VT19 {20 /// <summary>Reset the text style.</summary>21 Reset,22 23 /// <summary>Invert the foreground and background colors.</summary>24 Inverse25 }26 27 private static readonly Dictionary<ConsoleColor, string> ForegroundColorMap = new Dictionary<ConsoleColor, string>28 {29 { ConsoleColor.Black, "\x1b[30m" },30 { ConsoleColor.Gray, "\x1b[37m" },31 { ConsoleColor.Red, "\x1b[91m" },32 { ConsoleColor.Green, "\x1b[92m" },33 { ConsoleColor.Yellow, "\x1b[93m" },34 { ConsoleColor.Blue, "\x1b[94m" },35 { ConsoleColor.Magenta, "\x1b[95m" },36 { ConsoleColor.Cyan, "\x1b[96m" },37 { ConsoleColor.White, "\x1b[97m" },38 { ConsoleColor.DarkRed, "\x1b[31m" },39 { ConsoleColor.DarkGreen, "\x1b[32m" },40 { ConsoleColor.DarkYellow, "\x1b[33m" },41 { ConsoleColor.DarkBlue, "\x1b[34m" },42 { ConsoleColor.DarkMagenta, "\x1b[35m" },43 { ConsoleColor.DarkCyan, "\x1b[36m" },44 { ConsoleColor.DarkGray, "\x1b[90m" },45 };46 47 private static readonly Dictionary<VT, string> VTCodes = new Dictionary<VT, string>48 {49 { VT.Reset, "\x1b[0m" },50 { VT.Inverse, "\x1b[7m" }51 };52 53 /// <summary>54 /// Return the VT escape sequence for a ConsoleColor.55 /// </summary>56 /// <param name="color">57 /// The ConsoleColor to return the equivalent VT escape sequence.58 /// </param>59 /// <returns>60 /// The requested VT escape sequence.61 /// </returns>62 public static string GetEscapeSequence(ConsoleColor color)63 {64 string value = string.Empty;65 ForegroundColorMap.TryGetValue(color, out value);66 return value;67 }68 69 /// <summary>70 /// Return the VT escape sequence for a supported VT enum value.71 /// </summary>72 /// <param name="vt">73 /// The VT code to return the VT escape sequence.74 /// </param>75 /// <returns>76 /// The requested VT escape sequence.77 /// </returns>78 public static string GetEscapeSequence(VT vt)79 {80 string value = string.Empty;81 VTCodes.TryGetValue(vt, out value);82 return value;83 }84 }85}86 