Exemple #1
0
        private bool ParseSingleColor(string color, string[] particles, ref ConfigCollection data)
        {
            if (data.Name != "colors" || particles[0] != color)
            {
                return(false);
            }

            if (particles.Length != 2)
            {
                AddError($"Invalid command \"{string.Join(' ', particles)}\". should be: \"{color} #0055aa\"");
                return(true);
            }

            var regex = new Regex(@"^#([0-9a-fA-F]{6}|[0-9a-fA-F]{8})$", RegexOptions.Compiled);

            if (regex.IsMatch(particles[1]) == false)
            {
                AddError($"bar:colors should be of format #00aaFF or #00aaFFbb (\"{string.Join(' ', particles)}\" is not)");
                return(true);
            }

            data.AddData(color, particles[1]);
            FetchResult = new ParseInstructionResult(FileParserStateResult.None, "", this);
            return(true);
        }
Exemple #2
0
        public bool Parse(string[] particles, ref ConfigCollection data)
        {
            FetchResult = null;

            // Try parse outer "colors {}" command and return if it was a success
            if (ParseColors(particles, ref data))
            {
                return(true);
            }

            // Try parse colors that has only one color on them (and located inside colors mode)
            foreach (var color in _validSingleColors)
            {
                if (ParseSingleColor(color, particles, ref data))
                {
                    return(true);
                }
            }

            // Try parse colors that got three colors on them (and located inside colors mode)
            foreach (var color in _validColorClass)
            {
                if (ParseColorClass(color, particles, ref data))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #3
0
        private bool ParseColorClass(string color, string[] particles, ref ConfigCollection data)
        {
            if (data.Name != "colors" || particles[0] != color)
            {
                return(false);
            }

            if (particles.Length != 4)
            {
                AddError($"Invalid command \"{string.Join(' ', particles)}\". should be: \"{color} #0055aa #ffaa00 #bbccdd\"");
                return(true);
            }

            var regex = new Regex(@"^#([0-9a-fA-F]{6}|[0-9a-fA-F]{8})$", RegexOptions.Compiled);

            for (int i = 1; i < particles.Length; i++)
            {
                if (regex.IsMatch(particles[i]) == false)
                {
                    AddError($"bar:colors should be of format #00aaFF or #00aaFFbb (\"{particles[i]}\" is not)");
                    return(true);
                }
            }

            // Add this type of colors as modes
            var newData = new ConfigCollection(color, data);

            data.Modes.Add(color, newData);
            newData.AddData("border", particles[1]);
            newData.AddData("background", particles[2]);
            newData.AddData("text", particles[3]);

            FetchResult = new ParseInstructionResult(FileParserStateResult.None, "", this);
            return(true);
        }
Exemple #4
0
        private bool ParseColors(string[] particles, ref ConfigCollection data)
        {
            if (data.Name != "bar" || particles[0] != Instruction)
            {
                return(false);
            }

            if (particles[1].StartsWith('{') == false)
            {
                AddError("Invalid value for bar:colors. It should be followed by an {");
                FetchResult = null;
                return(true);
            }

            var remaining = string.Join(' ', particles.Skip(1)).Substring(1);

            FetchResult = new ParseInstructionResult(FileParserStateResult.OpenBracket, remaining, this);
            return(true);
        }
Exemple #5
0
        public bool Parse(string[] particles, ref ConfigCollection data)
        {
            FetchResult = null;

            if (data.Name != "bar" || particles[0] != Instruction)
            {
                return(false);
            }

            var positions = new[] { "top", "bottom", "left", "right" };

            if (!positions.Contains(particles[1]))
            {
                AddError($"Unkown bar:position value \"{particles[1]}\"");
                return(true);
            }

            data.AddData(Instruction, particles[1]);
            FetchResult = new ParseInstructionResult(FileParserStateResult.None, "", this);
            return(true);
        }
        public bool Parse(string[] particles, ref ConfigCollection data)
        {
            if (particles[0] != Instruction)
            {
                FetchResult = null;
                return(false);
            }

            if (bool.TryParse(particles[1], out bool val))
            {
                data.AddData(Instruction, val);
            }
            else
            {
                AddError("Invalid value for disable_win_key. Should be true or false");
                FetchResult = null;
                return(true);
            }

            FetchResult = new ParseInstructionResult(FileParserStateResult.None, "", this);
            return(true);
        }