Exemplo n.º 1
0
        static TextColorPalettes()
        {
            var hexColors = new string[] {
                "#000000",
                "#800000",
                "#008000",
                "#808000",
                "#000080",
                "#800080",
                "#008080",
                "#c0c0c0",
                "#808080",
                "#ff0000",
                "#00ff00",
                "#ffff00",
                "#0000ff",
                "#ff00ff",
                "#00ffff",
                "#ffffff"
            };

            LinuxConsole = new List <TextColor>(16);
            foreach (var hexColor in hexColors)
            {
                LinuxConsole.Add(TextColor.Parse(hexColor));
            }

            Xterm = new List <TextColor>(256);
            Xterm.AddRange(LinuxConsole);
            // TODO: add all xterm colors
            // http://www.calmar.ws/vim/256-xterm-24bit-rgb-color-chart.html
        }
Exemplo n.º 2
0
        public void ApplyConfig(UserConfig userConfig)
        {
            if (userConfig == null)
            {
                throw new ArgumentNullException("userConfig");
            }

            NickColors       = (bool)userConfig["Interface/Notebook/Channel/NickColors"];
            StripColors      = (bool)userConfig["Interface/Notebook/StripColors"];
            StripFormattings = (bool)userConfig["Interface/Notebook/StripFormattings"];
            HighlightColor   = TextColor.Parse(
                (string)userConfig["Interface/Notebook/Tab/HighlightColor"]
                );
            HighlightWords = new List <string>(
                (string[])userConfig["Interface/Chat/HighlightWords"]
                );

            var patternController = new MessagePatternListController(userConfig);
            var userPatterns      = patternController.GetList();
            var builtinPatterns   = BuiltinPatterns;
            var patterns          = new List <MessagePatternModel>(builtinPatterns.Count +
                                                                   userPatterns.Count);

            // No need to lock BuiltinPatterns as List<T> is thread-safe for
            // multiple readers as long as there is no writer at the same time.
            // BuiltinPatterns is only written once before the first instance
            // of MessageBuilderSettings is created via the static initializer.
            patterns.AddRange(builtinPatterns);
            patterns.AddRange(userPatterns);
            Patterns     = patterns;
            UserPatterns = userPatterns;
        }
Exemplo n.º 3
0
        public virtual void ApplyConfig(UserConfig userConfig)
        {
            if (userConfig == null)
            {
                throw new ArgumentNullException("userConfig");
            }

            NickColors       = (bool)userConfig["Interface/Notebook/Channel/NickColors"];
            StripColors      = (bool)userConfig["Interface/Notebook/StripColors"];
            StripFormattings = (bool)userConfig["Interface/Notebook/StripFormattings"];
            HighlightColor   = TextColor.Parse(
                (string)userConfig["Interface/Notebook/Tab/HighlightColor"]
                );
            HighlightWords = new List <string>(
                (string[])userConfig["Interface/Chat/HighlightWords"]
                );
        }
Exemplo n.º 4
0
        public void ApplyConfig(UserConfig userConfig)
        {
            if (userConfig == null)
            {
                throw new ArgumentNullException("userConfig");
            }

            NickColors       = (bool)userConfig["Interface/Notebook/Channel/NickColors"];
            StripColors      = (bool)userConfig["Interface/Notebook/StripColors"];
            StripFormattings = (bool)userConfig["Interface/Notebook/StripFormattings"];
            HighlightColor   = TextColor.Parse(
                (string)userConfig["Interface/Notebook/Tab/HighlightColor"]
                );
            HighlightWords = new List <string>(
                (string[])userConfig["Interface/Chat/HighlightWords"]
                );
            Emojis = (bool)userConfig["Interface/Chat/Emojis"];

            var patternController = new MessagePatternListController(userConfig);
            var userPatterns      = patternController.GetList();
            var builtinPatterns   = BuiltinPatterns;
            var patterns          = new List <MessagePatternModel>(builtinPatterns.Count +
                                                                   userPatterns.Count);

            // No need to lock BuiltinPatterns as List<T> is thread-safe for
            // multiple readers as long as there is no writer at the same time.
            // BuiltinPatterns is only written once before the first instance
            // of MessageBuilderSettings is created via the static initializer.
            patterns.AddRange(builtinPatterns);
            patterns.AddRange(userPatterns);
            if (Emojis)
            {
                // Emoji
                var regex = new Regex(@":(\w+):", RegexOptions.Compiled);
                patterns.Add(new MessagePatternModel(regex)
                {
                    MessagePartType = typeof(ImageMessagePartModel),
                    LinkFormat      = "smuxi-emoji://{1}",
                });
            }
            Patterns     = patterns;
            UserPatterns = userPatterns;
        }
Exemplo n.º 5
0
        public void GetNearestColor()
        {
            var palette = new List <TextColor>();

            palette.Add(TextColor.Parse("#000000"));
            palette.Add(TextColor.Parse("#FF0000"));
            palette.Add(TextColor.Parse("#00FF00"));
            palette.Add(TextColor.Parse("#0000FF"));
            palette.Add(TextColor.Parse("#FF00FF"));
            palette.Add(TextColor.Parse("#FFFF00"));
            palette.Add(TextColor.Parse("#FFFFFF"));

            var expected = TextColor.Parse("#FF0000");
            var actual   = TextColorTools.GetNearestColor(TextColor.Parse("#FF1111"), palette);

            Assert.AreEqual(expected, actual);

            expected = TextColor.Parse("#FFFFFF");
            actual   = TextColorTools.GetNearestColor(TextColor.Parse("#FF9999"), palette);
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 6
0
        void ParseStyle(XmlNode style, TextMessagePartModel submodel)
        {
            if (style == null)
            {
                return;
            }
            var properties = style.InnerText.Split(';');

            foreach (string property in properties)
            {
                var colonpos = property.IndexOf(':');
                if (colonpos == -1)
                {
                    continue;
                }
                string name  = property.Substring(0, colonpos).Trim();
                string value = property.Substring(colonpos + 1).Trim();
                switch (name)
                {
                case "background":
                    value = value.Split(' ')[0];
                    submodel.BackgroundColor = TextColor.Parse(value);
                    break;

                case "background-color":
                    submodel.BackgroundColor = TextColor.Parse(value);
                    break;

                case "color":
                    submodel.ForegroundColor = TextColor.Parse(value);
                    break;

                case "font-style":
                    if (value == "normal")
                    {
                        submodel.Italic = false;
                    }
                    else if (value == "inherit")
                    {
                    }
                    else
                    {
                        submodel.Italic = true;
                    }
                    break;

                case "font-weight":
                    if (value == "normal")
                    {
                        submodel.Bold = false;
                    }
                    else if (value == "inherit")
                    {
                    }
                    else
                    {
                        submodel.Bold = true;
                    }
                    break;

                case "text-decoration":
                {
                    foreach (string val in value.Split(' '))
                    {
                        if (val == "underline")
                        {
                            submodel.Underline = true;
                        }
                    }
                }
                break;

                case "font-family":
                case "font-size":
                case "text-align":
                case "margin-left":
                case "margin-right":
                default:
                    // ignore formatting
                    break;
                }
            }
        }
Exemplo n.º 7
0
        public void GetBestTextColorPerformance()
        {
            var colors = new List <TextColor>();

            colors.Add(TextColor.Parse("#000000"));
            colors.Add(TextColor.Parse("#000000"));
            colors.Add(TextColor.Parse("#FF0000"));
            colors.Add(TextColor.Parse("#00FF00"));
            colors.Add(TextColor.Parse("#0000FF"));
            colors.Add(TextColor.Parse("#FF00FF"));
            colors.Add(TextColor.Parse("#FFFF00"));
            colors.Add(TextColor.Parse("#FFFFFF"));
            colors.Add(TextColor.Parse("#1E0DD6"));
            colors.Add(TextColor.Parse("#1E0DD6"));
            colors.Add(TextColor.Parse("#219207"));
            colors.Add(TextColor.Parse("#429FB0"));
            colors.Add(TextColor.Parse("#352878"));
            colors.Add(TextColor.Parse("#52248B"));
            colors.Add(TextColor.Parse("#603D40"));
            colors.Add(TextColor.Parse("#872F56"));
            colors.Add(TextColor.Parse("#97608C"));
            colors.Add(TextColor.Parse("#055A4F"));
            colors.Add(TextColor.Parse("#05730C"));
            colors.Add(TextColor.Parse("#A45DDA"));
            colors.Add(TextColor.Parse("#279C2A"));
            colors.Add(TextColor.Parse("#D24F81"));
            colors.Add(TextColor.Parse("#45D6FA"));
            colors.Add(TextColor.Parse("#31DD0B"));
            colors.Add(TextColor.Parse("#429FB0"));
            colors.Add(TextColor.Parse("#05FC8F"));
            colors.Add(TextColor.Parse("#C1FFEF"));
            colors.Add(TextColor.Parse("#C1FFEF"));
            colors.Add(TextColor.Parse("#E4DA22"));

            var colorCombinations = new List <KeyValuePair <TextColor, TextColor> >();
            // bright background
            var bgBright = TextColor.Parse("#EBEBEB");

            foreach (var color in colors)
            {
                colorCombinations.Add(
                    new KeyValuePair <TextColor, TextColor>(color, bgBright)
                    );
            }

            // dark background
            var bgDark = TextColor.Parse("#2E3436");

            foreach (var color in colors)
            {
                colorCombinations.Add(
                    new KeyValuePair <TextColor, TextColor>(color, bgDark)
                    );
            }

            // warmup the TextColorTools cache (trigger static ctors)
            TextColorTools.GetBestTextColor(TextColor.Black, TextColor.Black);

            DateTime dstart = DateTime.UtcNow;
            DateTime dstop  = DateTime.UtcNow;

            Console.WriteLine("DateTime took: " + (dstop - dstart).TotalMilliseconds + " ms");
            int i = 0;

            foreach (var colorCombination in colorCombinations)
            {
                DateTime start, stop;
                start = DateTime.UtcNow;
                var best = TextColorTools.GetBestTextColor(
                    colorCombination.Key, colorCombination.Value
                    );
                stop = DateTime.UtcNow;
                Console.WriteLine(
                    "GetBestTextColor(): #{0:00} {1}|{2}={3}  took: {4:0.00} ms",
                    i++, colorCombination.Key, colorCombination.Value, best,
                    (stop - start).TotalMilliseconds
                    );
            }
        }