示例#1
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());
        }
示例#2
0
        private static string BuildNumberInfo(string value)
        {
            value = value.Trim();

            try
            {
                string @decimal, hex, binary;
                int    number = 0;

                if (Regex.IsMatch(value, "^(0|b|0b)[01]+$"))
                {
                    value  = value.Substring(value.IndexOf('b') + 1);
                    number = Convert.ToInt32(value, 2);
                }
                else if (Regex.IsMatch(value, "^(x|0x)[0-9A-Fa-f]+$") ||
                         Regex.IsMatch(value, "[A-Fa-f]+"))
                {
                    value  = value.Substring(value.IndexOf('x') + 1);
                    number = Convert.ToInt32(value, 16);
                }
                else
                {
                    number = Convert.ToInt32(value);
                }

                AnsiStringBuilder builder = new AnsiStringBuilder();
                @decimal = Convert.ToString(number, 10);
                hex      = Convert.ToString(number, 16);
                binary   = Convert.ToString(number, 2);
                builder.AppendForegroundFormat(ConsoleColor.Gray);
                builder.Append("dec:");
                builder.AppendFormattingReset();
                builder.Append($" {@decimal,-10} ");
                builder.AppendForegroundFormat(ConsoleColor.Gray);
                builder.Append("hex:");
                builder.AppendFormattingReset();
                builder.Append($" {hex,7} ");
                builder.AppendForegroundFormat(ConsoleColor.Gray);
                builder.Append("bin:");
                builder.AppendFormattingReset();
                builder.Append($" {binary,22}");
                return(builder.ToString());
            }
            catch (FormatException)
            {
                return($"\"{value}\": invalid format; [0|b|0b]0101; [x|0x]0A2F");
            }
            catch (Exception anyException)
            {
                return($"\"{value}\": {anyException.Message}");
            }
        }
示例#3
0
 private static void WriteLanguage(AnsiStringBuilder builder, string language, string value)
 {
     builder.AppendForegroundFormat(ConsoleColor.Gray);
     builder.Append($"{language}: ");
     builder.AppendFormattingReset();
     builder.AppendLine(value);
 }
示例#4
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();
        }
示例#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();
        }
示例#6
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());
        }
示例#7
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());
        }
示例#8
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());
        }