Example #1
0
 public static string FormatAsRtf(string buffer, ConsoleColorTheme theme)
 {
     StringBuilder builder = new StringBuilder();
     Stack<ConsoleColorExt> stack = new Stack<ConsoleColorExt>();
     foreach (Match match in FormatRegex.Matches(buffer))
     {
         if (match.Groups["Tag"].Success)
         {
             ConsoleColorExt item = ParseColour(match.Groups["Inner"].Value, theme);
             stack.Push(item);
             builder.Append(@"\cf" + ((((int) item) + 1)).ToString() + @"\ulnone ");
         }
         else if (match.Groups["EndTag"].Success)
         {
             if (stack.Count < 0)
             {
                 throw new Exception(string.Format(Strings.ConsoleInterpreter_UnexpectedEndTag, match.Index));
             }
             builder.Append(@"\cf" + ((int) (((ConsoleColorExt) stack.Pop()) + (int)ConsoleColorExt.DarkBlue)).ToString() + @"\ulnone ");
         }
         else if (match.Groups["Text"].Success)
         {
             string str = UnescapeString(match.Value);
             builder.Append(ReplaceLineEnds(str));
         }
     }
     return builder.ToString();
 }
 public ConsoleColorTheme this[System.ConsoleColor background]
 {
     get
     {
         ConsoleColorTheme theme = new ConsoleColorTheme();
         
         //int num = (int) (background * ((System.ConsoleColor) 0x20));
         int num = (int) (((int)background) * 0x20);
         for (int i = 0; i < 0x20; i++)
         {
             theme.Mappings[i] = (ConsoleColorExt) this.m_RawBytes[num++];
         }
         return theme;
     }
     set
     {
         //int num = (int) (background * ((System.ConsoleColor) 0x20));
         int num = (int) (((int)background) * 0x20);
         for (int i = 0; i < 0x20; i++)
         {
             this.m_RawBytes[num++] = (byte) value.Mappings[i];
         }
     }
 }
Example #3
0
        public ConsoleColorTheme this[System.ConsoleColor background]
        {
            get
            {
                ConsoleColorTheme theme = new ConsoleColorTheme();

                //int num = (int) (background * ((System.ConsoleColor) 0x20));
                int num = (int)(((int)background) * 0x20);
                for (int i = 0; i < 0x20; i++)
                {
                    theme.Mappings[i] = (ConsoleColorExt)this.m_RawBytes[num++];
                }
                return(theme);
            }
            set
            {
                //int num = (int) (background * ((System.ConsoleColor) 0x20));
                int num = (int)(((int)background) * 0x20);
                for (int i = 0; i < 0x20; i++)
                {
                    this.m_RawBytes[num++] = (byte)value.Mappings[i];
                }
            }
        }
Example #4
0
 public static ConsoleColorExt ParseColour(string tagInner, ConsoleColorTheme theme)
 {
     string str = tagInner.Trim();
     int index = str.IndexOf(':');
     if ((index == 1) && (str[0] == 'c'))
     {
         string s = str.Substring(2);
         int result = 0;
         if (int.TryParse(s, out result))
         {
             return (ConsoleColorExt) result;
         }
         try
         {
             return (ConsoleColorExt) Enum.Parse(typeof(ConsoleColorExt), s, true);
         }
         catch (Exception exception)
         {
             throw new Exception(string.Format(Strings.ConsoleInterpreter_ParseColour_Error, str), exception);
         }
     }
     if ((index == 1) && (str[0] == 't'))
     {
         string str3 = str.Substring(2);
         int num3 = 0;
         if (int.TryParse(str3, out num3))
         {
             return theme[(ConsoleThemeColor) num3];
         }
         try
         {
             return theme[(ConsoleThemeColor) Enum.Parse(typeof(ConsoleThemeColor), str3, true)];
         }
         catch (Exception exception2)
         {
             throw new Exception(string.Format(Strings.ConsoleInterpreter_ParseColour_Error, str), exception2);
         }
     }
     throw new Exception(string.Format(Strings.ConsoleInterpreter_ParseColour_Error, str));
 }