示例#1
0
 public ContentWriterOptions(
     OutputDisplayFormat format,
     GroupDefinition?groupDefinition   = null,
     OutputSymbols?symbols             = null,
     HighlightOptions highlightOptions = HighlightOptions.Match | HighlightOptions.Replacement,
     string?indent = null)
 {
     Format           = format;
     GroupDefinition  = groupDefinition;
     Symbols          = symbols ?? OutputSymbols.Empty;
     HighlightOptions = highlightOptions;
     Indent           = indent ?? OutputDisplayFormat.DefaultIndent;
 }
示例#2
0
        private static void WriteDisplayFormat(string name, OutputDisplayFormat format)
        {
            WriteName(name);

            if (format == null)
            {
                WriteNullValue();
                WriteLine();
                return;
            }

            WriteLine();
            WriteIndent();
            WriteOption("content display", format.ContentDisplayStyle);
            WriteIndent();
            WriteOption("display parts", format.DisplayParts);
            WriteIndent();
            WriteOption("file properties", format.FileProperties);
            WriteIndent();
            WriteOption("indent", format.Indent, replaceAllSymbols: true);
            WriteIndent();
            WriteOption("line options", format.LineOptions);

            if (format.LineContext.Before == format.LineContext.After)
            {
                WriteIndent();
                WriteOption("context", format.LineContext.Before);
            }
            else
            {
                WriteIndent();
                WriteOption("context before", format.LineContext.Before);
                WriteIndent();
                WriteOption("context after", format.LineContext.After);
            }

            WriteIndent();
            WriteOption("path display", format.PathDisplayStyle);
            WriteIndent();

            WriteName("separator");
            WriteValue(format.Separator, replaceAllSymbols: true);

            if (format.Separator?.EndsWith("\n") != true)
            {
                WriteLine();
            }

            WriteOption("no align", !format.AlignColumns);
        }
示例#3
0
        public bool TryParse(FindCommandOptions options)
        {
            var baseOptions = (CommonFindCommandOptions)options;

            if (!TryParse(baseOptions))
            {
                return(false);
            }

            options = (FindCommandOptions)baseOptions;

            if (!TryParseModifyOptions(Modify, OptionNames.Modify, out ModifyOptions? modifyOptions, out bool aggregateOnly))
            {
                return(false);
            }

            OutputDisplayFormat format = options.Format;
            ContentDisplayStyle contentDisplayStyle = format.ContentDisplayStyle;
            PathDisplayStyle    pathDisplayStyle    = format.PathDisplayStyle;

            if (modifyOptions.HasAnyFunction &&
                contentDisplayStyle == ContentDisplayStyle.ValueDetail)
            {
                contentDisplayStyle = ContentDisplayStyle.Value;
            }

            if (aggregateOnly)
            {
                ConsoleOut.Verbosity = Orang.Verbosity.Minimal;
                pathDisplayStyle     = PathDisplayStyle.Omit;
            }

            options.ModifyOptions = modifyOptions;

            options.Format = new OutputDisplayFormat(
                contentDisplayStyle: contentDisplayStyle,
                pathDisplayStyle: pathDisplayStyle,
                lineOptions: format.LineOptions,
                lineContext: format.LineContext,
                displayParts: format.DisplayParts,
                fileProperties: format.FileProperties,
                indent: format.Indent,
                separator: format.Separator,
                includeBaseDirectory: format.IncludeBaseDirectory);

            return(true);
        }
示例#4
0
        public bool TryParse(FindCommandOptions options)
        {
            if (!TryParseAsEnum(
                    Pipe,
                    OptionNames.Pipe,
                    out PipeMode pipeMode,
                    PipeMode.None,
                    OptionValueProviders.PipeMode))
            {
                return(false);
            }

            if (pipeMode == PipeMode.None)
            {
                if (Console.IsInputRedirected)
                {
                    PipeMode = PipeMode.Text;
                }
            }
            else
            {
                if (!Console.IsInputRedirected)
                {
                    WriteError("Redirected/piped input is required "
                               + $"when option '{OptionNames.GetHelpText(OptionNames.Pipe)}' is specified.");

                    return(false);
                }

                PipeMode = pipeMode;
            }

            var baseOptions = (CommonFindCommandOptions)options;

            if (!TryParse(baseOptions))
            {
                return(false);
            }

            options = (FindCommandOptions)baseOptions;

            if (!TryParseProperties(Ask, Name, options))
            {
                return(false);
            }

            string?input = null;

            if (pipeMode != PipeMode.Paths &&
                Console.IsInputRedirected)
            {
                if (options.ContentFilter == null)
                {
                    WriteError($"Option '{OptionNames.GetHelpText(OptionNames.Content)}' is required "
                               + "when redirected/piped input is used as a text to be searched.");

                    return(false);
                }

                input = ConsoleHelpers.ReadRedirectedInput();
            }

            EnumerableModifier <string>?modifier = null;

#if DEBUG // --modifier
            if (Modifier.Any() &&
                !TryParseModifier(Modifier, OptionNames.Modifier, out modifier))
            {
                return(false);
            }
#endif
            if (!TryParseModifyOptions(
                    Modify,
                    OptionNames.Modify,
                    modifier,
                    out ModifyOptions? modifyOptions,
                    out bool aggregateOnly))
            {
                return(false);
            }

            OutputDisplayFormat format = options.Format;
            ContentDisplayStyle contentDisplayStyle = format.ContentDisplayStyle;
            PathDisplayStyle    pathDisplayStyle    = format.PathDisplayStyle;

            if (modifyOptions.HasAnyFunction &&
                contentDisplayStyle == ContentDisplayStyle.ValueDetail)
            {
                contentDisplayStyle = ContentDisplayStyle.Value;
            }

            options.Input         = input;
            options.ModifyOptions = modifyOptions;
            options.AggregateOnly = aggregateOnly;
            options.Split         = Split;

            options.Format = new OutputDisplayFormat(
                contentDisplayStyle: contentDisplayStyle,
                pathDisplayStyle: pathDisplayStyle,
                lineOptions: format.LineOptions,
                lineContext: format.LineContext,
                displayParts: format.DisplayParts,
                fileProperties: format.FileProperties,
                indent: format.Indent,
                separator: format.Separator,
                alignColumns: format.AlignColumns,
                includeBaseDirectory: format.IncludeBaseDirectory);

            return(true);
        }