Esempio n. 1
0
        private static void WriteColorUsage(AnsiStringBuilder builder, XElement row, XNamespace nsSS)
        {
            var cells = row.Elements(nsSS + "Cell").ToList();

            builder.AppendLine(cells[0].Element(nsSS + "Data").Value);

            int index = 0;

            foreach (var cell in cells.Skip(1))
            {
                var attributeIndex = cell.Attribute(nsSS + "Index");
                if (attributeIndex != null && int.TryParse(attributeIndex.Value, out int excelIndex))
                {
                    index = excelIndex - 2;
                }

                if (index >= brands.Length)
                {
                    break;
                }

                builder.AppendForegroundFormat(ConsoleColor.Gray);
                builder.Append($"{brands[index++]}: ");
                builder.AppendFormattingReset();
                builder.AppendLine(cell.Element(nsSS + "Data").Value);
            }

            builder.AppendLine();
        }
Esempio n. 2
0
 private static void WriteLanguage(AnsiStringBuilder builder, string language, string value)
 {
     builder.AppendForegroundFormat(ConsoleColor.Gray);
     builder.Append($"{language}: ");
     builder.AppendFormattingReset();
     builder.AppendLine(value);
 }
Esempio n. 3
0
 private static void AddFunctionToList(AnsiStringBuilder builder, string function, string description)
 {
     builder.AppendBoldFormat();
     builder.Append(function);
     builder.AppendFormattingReset();
     builder.Append(": ");
     builder.AppendLine(description);
 }
Esempio n. 4
0
        private TextResult Get(CommandContext context)
        {
            string configPath = CombineWithSolutionPath(CONFIG_PATH);

            if (!File.Exists(configPath))
            {
                return("Configuration hasn't been found.");
            }

            Regex             filter  = context.GetFilterRegex();
            AnsiStringBuilder builder = new AnsiStringBuilder();

            string[] languages = new[] { "en", "sv", "de", "lv", "no", "fi", "fr", "nl", "cs", "da", "es", "it", "pl", "pt", "ru", "es-mx", "en-in", "hi" };

            using (FileStream configFile = File.OpenRead(configPath))
            {
                XDocument doc       = XDocument.Load(configFile);
                var       workbook  = doc.Root;
                var       nsSS      = workbook.GetNamespaceOfPrefix("ss");
                var       worksheet = workbook.Element(nsSS + "Worksheet");
                var       table     = worksheet.Element(nsSS + "Table");

                foreach (var row in table.Elements(nsSS + "Row").Skip(1))
                {
                    var    cells = row.Elements(nsSS + "Cell").ToList();
                    string name  = cells[0].Element(nsSS + "Data").Value;
                    string color = cells[1].Element(nsSS + "Data").Value;

                    if (!filter.IsMatch(name))
                    {
                        continue;
                    }

                    builder.AppendLine(name);

                    for (int i = 1; i < cells.Count; i++)
                    {
                        WriteLanguage(builder, languages[i - 1], cells[i].Element(nsSS + "Data").Value);
                    }

                    builder.AppendLine();
                }
            }

            return(builder.ToString());
        }
Esempio n. 5
0
        private static void WriteColor(AnsiStringBuilder builder, string colorName, string colorValue)
        {
            WriteColorPreview(builder, ReadColorFromText(colorValue));

            builder.Append(colorName);
            builder.AppendForegroundFormat(ConsoleColor.Gray);
            builder.Append(": ");
            builder.Append(colorValue);
            builder.AppendFormattingReset();
            builder.AppendLine();
        }
Esempio n. 6
0
        public string Number(CommandContext context)
        {
            AnsiStringBuilder result = new AnsiStringBuilder();

            foreach (string number in context.GetParameterValues("number"))
            {
                result.AppendLine(BuildNumberInfo(number));
            }

            RemoveLastLineEnd(result);
            return(result.ToString());
        }
Esempio n. 7
0
        public ICommandResult Execute(CommandContext context)
        {
            AnsiStringBuilder result = new AnsiStringBuilder();

            foreach (IHistoryItem historyItem in history.GetHistory())
            {
                string rawInput = historyItem.Input.ParsedInput.RawInput;
                result.AppendLink(rawInput, ActionBuilder.InputSetUri(rawInput));
                result.AppendLine();
            }

            return(new TextResult(result.ToString()));
        }
Esempio n. 8
0
        public string Guid(CommandContext context)
        {
            Guid guid = System.Guid.NewGuid();
            AnsiStringBuilder builder = new AnsiStringBuilder();
            bool isLetter             = false;

            foreach (char character in guid.ToString("N").ToUpperInvariant())
            {
                if (char.IsDigit(character))
                {
                    if (isLetter)
                    {
                        builder.AppendFormattingReset();
                        isLetter = false;
                    }
                }
                else if (!isLetter)
                {
                    builder.AppendForegroundFormat(ConsoleColor.Yellow);
                    isLetter = true;
                }

                builder.Append(character.ToString());
            }

            if (isLetter)
            {
                builder.AppendFormattingReset();
            }

            builder.AppendLine();
            builder.AppendLine(guid.ToString());
            builder.AppendLine(guid.ToString("B").ToUpperInvariant());
            builder.Append(guid.ToString("X"));

            return(builder.ToString());
        }
Esempio n. 9
0
        public string ColorFunction(CommandContext context)
        {
            AnsiStringBuilder result = new AnsiStringBuilder();
            var   parValues          = context.GetParameterValues("color");
            Color color;

            if (parValues.Count == 4 && parValues.All(par => int.TryParse(par, out _)))
            {
                color = Color.FromArgb(int.Parse(parValues[0]), int.Parse(parValues[1]), int.Parse(parValues[2]), int.Parse(parValues[3]));
                result.AppendLine(BuildColorInfo(color));
            }
            else if (parValues.Count == 3 && parValues.All(par => int.TryParse(par, out _)))
            {
                color = Color.FromArgb(255, int.Parse(parValues[0]), int.Parse(parValues[1]), int.Parse(parValues[2]));
                result.AppendLine(BuildColorInfo(color));
            }
            else
            {
                foreach (string textPar in parValues.Select(par => par.ToString()))
                {
                    color = ReadColorFromText(textPar);

                    if (color.IsEmpty)
                    {
                        result.AppendLine($"\"{textPar}\": invalid format");
                    }
                    else
                    {
                        result.AppendLine(BuildColorInfo(color));
                    }
                }
            }

            RemoveLastLineEnd(result);
            return(result.ToString());
        }
Esempio n. 10
0
        // TODO: [P3] Change how the help works and automatically generate nice help per command
        public TextResult BuildCommandHelp()
        {
            AnsiStringBuilder builder = new AnsiStringBuilder();

            builder.Append("usage: ");
            builder.AppendForegroundFormat(System.ConsoleColor.Gray);
            builder.Append("texo [--version] <command> [<args>]");
            builder.AppendFormattingReset();
            builder.AppendLine();

            builder.AppendLine();
            builder.AppendForegroundFormat(System.ConsoleColor.Yellow);
            builder.Append("commands");
            builder.AppendFormattingReset();
            builder.AppendLine();

            builder.Append($"{EnvironmentNames.QUERY_ENVIRONMENT,-15}");
            builder.AppendForegroundFormat(System.ConsoleColor.Gray);
            builder.Append("Management of environment variables.");
            builder.AppendFormattingReset();
            builder.AppendLine();

            builder.Append($"{HistoryNames.QUERY_HISTORY,-15}");
            builder.AppendForegroundFormat(System.ConsoleColor.Gray);
            builder.Append("History of commands.");
            builder.AppendFormattingReset();
            builder.AppendLine();

            builder.AppendLine();
            builder.AppendForegroundFormat(System.ConsoleColor.Yellow);
            builder.Append("options");
            builder.AppendFormattingReset();
            builder.AppendLine();

            builder.Append($"{"-v--version",-15}");
            builder.AppendForegroundFormat(System.ConsoleColor.Gray);
            builder.Append("Prints out the version of the Texo UI in use.");
            builder.AppendFormattingReset();
            builder.AppendLine();

            return(builder.ToString());
        }
Esempio n. 11
0
        private static string BuildColorInfo(Color color)
        {
            Color blendedColor = color;

            if (color.A < 255)
            {
                blendedColor = Blend(color, Color.Black, color.A / 255.0);
            }

            AnsiStringBuilder builder = new AnsiStringBuilder();

            builder.AppendForegroundFormat(blendedColor.R, blendedColor.G, blendedColor.B);
            builder.Append(new string('█', 7));
            builder.AppendFormattingReset();
            builder.Append(" ");
            builder.Append($"#{GetHexColorPart(color.A)}{GetHexColorPart(color.R)}{GetHexColorPart(color.G)}{GetHexColorPart(color.B)} ");
            builder.Append($"#{GetHexColorPart(blendedColor.R)}{GetHexColorPart(blendedColor.G)}{GetHexColorPart(blendedColor.B)} ");
            builder.Append(string.Format("{0,-22} ", $"argb({color.A},{color.R},{color.G},{color.B})"));
            builder.Append(string.Format("{0,-17}", $"rgb({blendedColor.R},{blendedColor.G},{blendedColor.B})"));
            builder.AppendLine();
            return(builder.ToString());
        }
Esempio n. 12
0
        public string Random(CommandContext context)
        {
            AnsiStringBuilder builder = new AnsiStringBuilder();
            Faker             faker   = new Faker("en");

            // Text
            builder.AppendForegroundFormat(ConsoleColor.Gray);
            builder.Append("text");
            builder.AppendFormattingReset();
            builder.AppendLine();
            builder.AppendLine(faker.Lorem.Paragraph(6));

            // Numbers
            builder.AppendLine();
            builder.AppendForegroundFormat(ConsoleColor.Gray);
            builder.Append("numbers");
            builder.AppendFormattingReset();
            builder.AppendLine();
            int    integer    = faker.Random.Int(0, int.MaxValue);
            double fractional = faker.Random.Double();
            double @decimal   = integer + fractional;

            builder.AppendLine($"integer: {integer}    fractional: {fractional}    decimal: {@decimal}");

            // Person
            builder.AppendLine();
            builder.AppendForegroundFormat(ConsoleColor.Gray);
            builder.Append("person");
            builder.AppendFormattingReset();
            builder.AppendLine();
            Person person = faker.Person;

            builder.AppendLine($"{person.FullName} ({person.UserName})");
            builder.AppendLine($"DOB: {person.DateOfBirth.ToShortDateString()}");
            builder.AppendLine($"Phone: {person.Phone}");
            builder.AppendLine($"Email: {person.Email}");
            builder.AppendLine($"Website: {person.Website}");

            // Address
            builder.AppendLine();
            builder.AppendForegroundFormat(ConsoleColor.Gray);
            builder.Append("address");
            builder.AppendFormattingReset();
            builder.AppendLine();
            builder.AppendLine(faker.Address.FullAddress());

            // GPS
            builder.AppendLine();
            builder.AppendForegroundFormat(ConsoleColor.Gray);
            builder.Append("gps");
            builder.AppendFormattingReset();
            builder.AppendLine();
            double latittude = faker.Address.Latitude();
            double longitude = faker.Address.Longitude();

            builder.Append($"{latittude}, {longitude}");

            return(builder.ToString());
        }
Esempio n. 13
0
        // TODO: [P3] Refarctor this and make it generic
        private TextResult Set(CommandContext context)
        {
            string configPath = CombineWithSolutionPath(CONFIG_PATH);

            if (!File.Exists(configPath))
            {
                return("Configuration hasn't been found.");
            }

            string            name    = context.GetParameterValue(SpinSportConstants.PARAMETER_NAME);
            AnsiStringBuilder builder = new AnsiStringBuilder();

            string[]  languages = new[] { "en", "sv", "de", "lv", "no", "fi", "fr", "nl" };
            XElement  targetRow = null;
            XDocument doc;

            using (FileStream configFile = File.OpenRead(configPath))
            {
                doc = XDocument.Load(configFile);
            }

            var workbook  = doc.Root;
            var nsSS      = workbook.GetNamespaceOfPrefix("ss");
            var worksheet = workbook.Element(nsSS + "Worksheet");
            var table     = worksheet.Element(nsSS + "Table");

            foreach (var row in table.Elements(nsSS + "Row").Skip(1))
            {
                string rowName = row.Element(nsSS + "Cell").Element(nsSS + "Data").Value;

                if (string.Equals(rowName, name, StringComparison.OrdinalIgnoreCase))
                {
                    targetRow = row;
                    break;
                }
            }

            if (targetRow != null)
            {
                var cells = targetRow.Elements(nsSS + "Cell").ToList();
                builder.AppendLine(name);

                for (int i = 1; i < cells.Count; i++)
                {
                    var    cell          = cells[i];
                    string languageCode  = languages[i - 1];
                    string languageValue = context.GetParameterFromOption(languageCode) ?? string.Empty;
                    cell.Element(nsSS + "Data").Value = languageValue;
                    WriteLanguage(builder, languageCode, languageValue);
                }
            }
            else
            {
                XElement newRow = new XElement(nsSS + "Row",
                                               new XElement(nsSS + "Cell", new XElement(nsSS + "Data", new XAttribute(nsSS + "Type", "String"), name)),
                                               new XElement(nsSS + "Cell", new XElement(nsSS + "Data", new XAttribute(nsSS + "Type", "String"), context.GetParameterFromOption(SpinSportConstants.OPTION_EN) ?? string.Empty)),
                                               new XElement(nsSS + "Cell", new XElement(nsSS + "Data", new XAttribute(nsSS + "Type", "String"), context.GetParameterFromOption(SpinSportConstants.OPTION_SV) ?? string.Empty)),
                                               new XElement(nsSS + "Cell", new XElement(nsSS + "Data", new XAttribute(nsSS + "Type", "String"), context.GetParameterFromOption(SpinSportConstants.OPTION_DE) ?? string.Empty)),
                                               new XElement(nsSS + "Cell", new XElement(nsSS + "Data", new XAttribute(nsSS + "Type", "String"), context.GetParameterFromOption(SpinSportConstants.OPTION_LV) ?? string.Empty)),
                                               new XElement(nsSS + "Cell", new XElement(nsSS + "Data", new XAttribute(nsSS + "Type", "String"), context.GetParameterFromOption(SpinSportConstants.OPTION_NO) ?? string.Empty)),
                                               new XElement(nsSS + "Cell", new XElement(nsSS + "Data", new XAttribute(nsSS + "Type", "String"), context.GetParameterFromOption(SpinSportConstants.OPTION_FI) ?? string.Empty)),
                                               new XElement(nsSS + "Cell", new XElement(nsSS + "Data", new XAttribute(nsSS + "Type", "String"), context.GetParameterFromOption(SpinSportConstants.OPTION_FR) ?? string.Empty)),
                                               new XElement(nsSS + "Cell", new XElement(nsSS + "Data", new XAttribute(nsSS + "Type", "String"), context.GetParameterFromOption(SpinSportConstants.OPTION_NL) ?? string.Empty)));

                table.Add(newRow);

                builder.AppendLine(name);
                WriteLanguage(builder, SpinSportConstants.OPTION_EN, context.GetParameterFromOption(SpinSportConstants.OPTION_EN) ?? string.Empty);
                WriteLanguage(builder, SpinSportConstants.OPTION_SV, context.GetParameterFromOption(SpinSportConstants.OPTION_SV) ?? string.Empty);
                WriteLanguage(builder, SpinSportConstants.OPTION_DE, context.GetParameterFromOption(SpinSportConstants.OPTION_DE) ?? string.Empty);
                WriteLanguage(builder, SpinSportConstants.OPTION_LV, context.GetParameterFromOption(SpinSportConstants.OPTION_LV) ?? string.Empty);
                WriteLanguage(builder, SpinSportConstants.OPTION_NO, context.GetParameterFromOption(SpinSportConstants.OPTION_NO) ?? string.Empty);
                WriteLanguage(builder, SpinSportConstants.OPTION_FI, context.GetParameterFromOption(SpinSportConstants.OPTION_FI) ?? string.Empty);
                WriteLanguage(builder, SpinSportConstants.OPTION_FR, context.GetParameterFromOption(SpinSportConstants.OPTION_FR) ?? string.Empty);
                WriteLanguage(builder, SpinSportConstants.OPTION_NL, context.GetParameterFromOption(SpinSportConstants.OPTION_NL) ?? string.Empty);
            }

            using (FileStream configFile = File.OpenWrite(configPath))
            {
                doc.Save(configFile);
            }

            return(builder.ToString());
        }