コード例 #1
0
        /// <summary>
        /// Adds columnar content for a <see cref="HelpItem"/> using the current indentation
        /// for the line, and adding the appropriate padding between the columns
        /// </summary>
        /// <param name="helpItem">
        /// Current <see cref="HelpItem" /> to write to the console
        /// </param>
        /// <param name="maxInvocationWidth">
        /// Maximum number of characters accross all <see cref="HelpItem">help items</see>
        /// occupied by the invocation text
        /// </param>
        protected void AppendHelpItem(HelpItem helpItem, int maxInvocationWidth)
        {
            if (helpItem == null)
            {
                throw new ArgumentNullException(nameof(helpItem));
            }

            AppendText(helpItem.Invocation, CurrentIndentation);

            var offset              = maxInvocationWidth + ColumnGutter - helpItem.Invocation.Length;
            var availableWidth      = GetAvailableWidth();
            var maxDescriptionWidth = availableWidth - maxInvocationWidth - ColumnGutter;

            var descriptionLines = SplitText(helpItem.Description, maxDescriptionWidth);
            var lineCount        = descriptionLines.Count;

            AppendLine(descriptionLines.FirstOrDefault(), offset);

            if (lineCount == 1)
            {
                return;
            }

            offset = CurrentIndentation + maxInvocationWidth + ColumnGutter;

            foreach (var descriptionLine in descriptionLines.Skip(1))
            {
                AppendLine(descriptionLine, offset);
            }
        }
コード例 #2
0
        /// <summary>
        /// Adds columnar content for a <see cref="HelpItem"/> using the current indentation
        /// for the line, and adding the appropriate padding between the columns
        /// </summary>
        /// <param name="helpItem">
        /// Current <see cref="HelpItem" /> to write to the console
        /// </param>
        /// <param name="maxInvocationWidth">
        /// Maximum number of characters accross all <see cref="HelpItem">help items</see>
        /// occupied by the invocation text
        /// </param>
        protected void AppendHelpItem(
            HelpItem helpItem,
            int maxInvocationWidth)
        {
            if (helpItem is null)
            {
                throw new ArgumentNullException(nameof(helpItem));
            }

            AppendText(helpItem.Invocation, CurrentIndentation);

            var offset              = maxInvocationWidth + ColumnGutter - helpItem.Invocation.Length;
            var availableWidth      = GetAvailableWidth();
            var maxDescriptionWidth = availableWidth - maxInvocationWidth - ColumnGutter;
            var descriptionColumn   = helpItem.Description;

            if (helpItem.HasDefaultValueHint)
            {
                var postfix = string.IsNullOrEmpty(helpItem.Description) ? string.Empty : " ";
                descriptionColumn += postfix + helpItem.DefaultValueHint;
            }
            var descriptionLines = SplitText(descriptionColumn, maxDescriptionWidth);
            var lineCount        = descriptionLines.Count;

            AppendLine(descriptionLines.FirstOrDefault(), offset);

            if (lineCount == 1)
            {
                return;
            }

            offset = CurrentIndentation + maxInvocationWidth + ColumnGutter;

            foreach (var descriptionLine in descriptionLines.Skip(1))
            {
                AppendLine(descriptionLine, offset);
            }
        }
コード例 #3
0
 protected bool Equals(HelpItem other) =>
 (Invocation, Description) == (other.Invocation, other.Description);
コード例 #4
0
        /// <summary>
        /// Adds columnar content for a <see cref="HelpItem"/> using the current indentation
        /// for the line, and adding the appropriate padding between the columns
        /// </summary>
        /// <param name="helpItem">
        /// Current <see cref="HelpItem" /> to write to the console
        /// </param>
        /// <param name="maxInvocationWidth">
        /// Maximum number of characters accross all <see cref="HelpItem">help items</see>
        /// occupied by the invocation text
        /// </param>
        protected void AppendHelpItem(HelpItem helpItem, int maxInvocationWidth)
        {
            if (helpItem == null)
            {
                throw new ArgumentNullException(nameof(helpItem));
            }

            var availableHalfWidth = GetAvailableHalfWidth();

            var invocationWidth = maxInvocationWidth < availableHalfWidth ? maxInvocationWidth : availableHalfWidth;

            var invocationLines     = SplitInvocation(helpItem.Invocation, invocationWidth);
            var invocationLineCount = invocationLines.Count;

            AppendText(invocationLines.FirstOrDefault(), CurrentIndentation);

            //var maxInvocationWidth = availableHalfWidth;


            //var descriptionLines = SplitText(helpItem.Invocation, maxDescriptionWidth);



            //AppendText(helpItem.Invocation, CurrentIndentation);

            var offset              = maxInvocationWidth + ColumnGutter - helpItem.Invocation.Length;
            var availableWidth      = GetAvailableWidth();
            var maxDescriptionWidth = availableWidth - maxInvocationWidth - ColumnGutter;

            var descriptionLines     = SplitText(helpItem.Description, maxDescriptionWidth);
            var descriptionLineCount = descriptionLines.Count;

            AppendLine(descriptionLines.FirstOrDefault(), offset);

            if (descriptionLineCount == 1 && invocationLineCount == 1)
            {
                return;
            }

            var maxLineCount = descriptionLineCount > invocationLineCount ? descriptionLineCount : invocationLineCount;

            for (int i = 1; i < maxLineCount; i++)
            {
                if (invocationLineCount > i)
                {
                    AppendText(invocationLines.ElementAt(i), CurrentIndentation);
                    offset = CurrentIndentation + invocationWidth + ColumnGutter - invocationLines.ElementAt(i).Length;
                }
                else
                {
                    offset = CurrentIndentation + invocationWidth + ColumnGutter;
                }

                if (descriptionLineCount > i)
                {
                    AppendLine(descriptionLines.ElementAt(i), offset);
                }
                else
                {
                    Console.Out.WriteLine(string.Empty);
                }
            }


            //foreach (var descriptionLine in descriptionLines.Skip(1))
            //{
            //    AppendLine(descriptionLine, offset);
            //}
        }