Example #1
0
        private string UrlReplacement(Match match)
        {
            AnsiStringBuilder builder = new AnsiStringBuilder();

            builder.AppendLink(match.Value, match.Value);
            return(builder.ToString());
        }
Example #2
0
        private string ReplaceBranchName(Match match)
        {
            AnsiStringBuilder builder     = new AnsiStringBuilder();
            string            helpCommand = $"git checkout {match.Value}";

            builder.AppendLink(match.Value, ActionBuilder.InputSetUri(helpCommand));
            return(builder.ToString());
        }
Example #3
0
        private string ReplaceHelpCommand(Match match)
        {
            string            help    = match.Value.TrimEnd();
            AnsiStringBuilder builder = new AnsiStringBuilder();

            builder.AppendLink(help, ActionBuilder.InputSetUri(help));
            return(builder.ToString());
        }
Example #4
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());
        }
Example #5
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()));
        }
Example #6
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));
        }
Example #7
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));
        }