Exemplo n.º 1
0
 private static void AddFunctionToList(AnsiStringBuilder builder, string function, string description)
 {
     builder.AppendBoldFormat();
     builder.Append(function);
     builder.AppendFormattingReset();
     builder.Append(": ");
     builder.AppendLine(description);
 }
Exemplo n.º 2
0
        private string ReplaceHelpWithAction(Match match)
        {
            AnsiStringBuilder builder = new AnsiStringBuilder();

            builder.Append("\"");
            string helpCommand = match.Groups["help"].Value;

            builder.AppendLink(helpCommand, ActionBuilder.InputSetUri(helpCommand));
            builder.Append("\"");
            return(builder.ToString());
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
0
 private static void WriteLanguage(AnsiStringBuilder builder, string language, string value)
 {
     builder.AppendForegroundFormat(ConsoleColor.Gray);
     builder.Append($"{language}: ");
     builder.AppendFormattingReset();
     builder.AppendLine(value);
 }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
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());
        }
Exemplo n.º 7
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());
        }
Exemplo 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());
        }
Exemplo n.º 9
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}");
            }
        }
Exemplo n.º 10
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());
        }
Exemplo n.º 11
0
        public Task <OutputModel> ProcessAsync(OutputModel data)
        {
            if (!data.Flags.Contains(TransformationFlags.GIT_STATUS))
            {
                return(Task.FromResult(data));
            }

            string line = data.Output;
            Match  match;

            if (data.Flags.Contains(TransformationFlags.GIT_UNTRACKED))
            {
                match = untrackedFileRegex.Match(line);
            }
            else
            {
                if (line.StartsWith("Untracked files", StringComparison.OrdinalIgnoreCase))
                {
                    data.Flags.Add(TransformationFlags.GIT_UNTRACKED);
                    return(Task.FromResult(data));
                }

                match = fileRegex.Match(line);
            }

            if (!match.Success)
            {
                return(Task.FromResult(data));
            }

            Group  fileGroup = match.Groups["path"];
            string path      = fileGroup.Value;

            if (!path.IsValidPath())
            {
                return(Task.FromResult(data));
            }

            Func <string, bool> pathCheckFunc = path.EndsWith("/") ? (Func <string, bool>)Directory.Exists : File.Exists;
            string fullPath = Path.Combine(PathConstants.RELATIVE_CURRENT_DIRECTORY, path);

            if (!pathCheckFunc(fullPath))
            {
                return(Task.FromResult(data));
            }

            fullPath = fullPath.GetFullConsolidatedPath();
            AnsiStringBuilder builder = new AnsiStringBuilder();

            builder.Append(line.Substring(0, fileGroup.Index));
            builder.AppendLink(path, ActionBuilder.PathUri(fullPath));

            int endIndex = fileGroup.Index + fileGroup.Length;

            if (endIndex < line.Length)
            {
                builder.Append(line.Substring(endIndex));
            }

            data.Output = builder.ToString();
            return(Task.FromResult(data));
        }
Exemplo n.º 12
0
        public Task <OutputModel> ProcessAsync(OutputModel data)
        {
            if (!data.Flags.Contains(TransformationFlags.GET_CHILD_ITEM))
            {
                return(Task.FromResult(data));
            }

            string text = data.Output;
            string itemPath;
            int    index;

            if (data.Flags.Contains(TransformationFlags.GET_CHILD_ITEM_NAME))
            {
                itemPath = text.TrimEnd();
                index    = 0;
            }
            else if (data.Properties.TryGetValue(TransformationProperties.INDEX, out object value))
            {
                index = (int)value;

                if (text.Length <= index)
                {
                    return(Task.FromResult(data));
                }

                itemPath = text.Substring(index).TrimEnd();
            }
            else
            {
                if (text.StartsWith("Mode", StringComparison.OrdinalIgnoreCase) &&
                    text.Contains("Name"))
                {
                    int indexOfName = text.LastIndexOf("Name");
                    data.Properties[TransformationProperties.INDEX] = indexOfName;
                }

                return(Task.FromResult(data));
            }

            if (string.IsNullOrWhiteSpace(itemPath))
            {
                return(Task.FromResult(data));
            }

            string parentPath = data.Input.ParsedInput.Tokens
                                .Skip(1)
                                .FirstOrDefault(t => !string.Equals(t, "-name", StringComparison.OrdinalIgnoreCase));

            if (string.IsNullOrEmpty(parentPath))
            {
                parentPath = PathConstants.RELATIVE_CURRENT_DIRECTORY;
            }

            string path = Path.Combine(parentPath, itemPath);

            if (path.GetPathType() == PathTypeEnum.NonExistent)
            {
                return(Task.FromResult(data));
            }

            string            fullPath = path.GetFullConsolidatedPath();
            AnsiStringBuilder builder  = new AnsiStringBuilder();

            builder.Append(text.Substring(0, index));
            builder.AppendLink(itemPath, ActionBuilder.PathUri(fullPath));

            int endIndex = index + itemPath.Length;

            if (endIndex < text.Length)
            {
                builder.Append(text.Substring(endIndex));
            }

            data.Output = builder.ToString();
            return(Task.FromResult(data));
        }