Exemple #1
0
        private void AddCommandList(Document doc, CommandGroup group)
        {
            ParagraphStyle style = new ParagraphStyle
            {
                Indent = 3,
                Tabs = new[] { 22 }
            };

            // TODO - add option to show ALL commands/groups
            const bool showHidden = false;

            var commands = GetExpandedCommandNodes(group, showHidden)
                .Select(x => new { x.Node, x.Depth, Verb = VerbPath(x.Node, x.Depth - 1) });

            foreach (var entry in commands.OrderBy(x => x.Verb))
            {
                if (entry.Node.Hidden)
                {
                    continue;
                }

                var para = doc.AddParagraph(new Paragraph(style));

                // TODO - highlight the command by setting span style?
                para.AddSpan(new Span(entry.Verb));
                para.AddTab();

                if (!string.IsNullOrEmpty(entry.Node.Summary))
                {
                    para.AddSpan(new Span(entry.Node.Summary));
                }
            }
        }
Exemple #2
0
        public static IEnumerable<Paragraph> Parse(string content, ParagraphStyle style = null)
        {
            if (string.IsNullOrEmpty(content))
            {
                yield break;
            }

            if (style == null)
            {
                style = new ParagraphStyle();
            }

            // TODO - this is a HACK! Make this work right! (A blank line should start a new paragraph, for a start)

            StringBuilder builder = new StringBuilder();
            Paragraph para;
            int returnCount = 0;

            foreach (var c in content)
            {
                switch (c)
                {
                    case '\n':
                        break;

                    case '\r':
                        returnCount += 1;
                        if (returnCount > 1)
                        {
                            para = new Paragraph(style);
                            para.AddSpan(builder.ToString().Trim());
                            yield return para;
                            builder.Clear();
                        }
                        else
                        {
                            builder.Append(' ');
                        }
                        break;

                    default:
                        builder.Append(c);
                        returnCount = 0;
                        break;
                }
            }

            para = new Paragraph(style);
            para.AddSpan(builder.ToString().Trim());
            yield return para;
        }
Exemple #3
0
 public Paragraph(ParagraphStyle style)
 {
     Style = style;
 }
Exemple #4
0
        private void AddName(Command command, Document doc, ParagraphStyle headerStyle)
        {
            var para = doc.AddParagraph(new Paragraph(headerStyle));
            para.AddSpan("NAME");
            // TODO - rather than drawing dashes, make the prior span a different color or some such
            para = doc.AddParagraph(new Paragraph());
            para.AddSpan("----");

            para = doc.AddParagraph(new Paragraph());
            para.AddSpan(VerbPath(command));
            para.AddSpan("-");
            para.AddSpan(command.Summary);
        }
Exemple #5
0
        private Document CommandHelp(Command command)
        {
            Document doc = new Document();

            // TODO - create a "style sheet" that can be passed around
            var headerStyle = new ParagraphStyle { LinesBefore = 1 };

            AddName(command, doc, headerStyle);
            AddSynopsis(command, doc, headerStyle);

            // TODO - add long description

            AddOptions(command, doc, headerStyle);

            return doc;
        }
Exemple #6
0
        private void AddSynopsis(Command command, Document doc, ParagraphStyle headerStyle)
        {
            var para = doc.AddParagraph(new Paragraph(headerStyle));
            para.AddSpan("SYNOPSIS");
            para = doc.AddParagraph(new Paragraph());
            para.AddSpan("--------");

            para = doc.AddParagraph(new Paragraph());
            para.AddSpan(VerbPath(command));

            foreach (var named in command.NamedParameters)
            {
                para.AddSpan(named.Usage);
            }

            // TODO - pick up any positional parameters on prior verbs
            foreach (var pos in command.PositionalParameters)
            {
                para.AddSpan(pos.Usage);
            }
        }
Exemple #7
0
        private void AddOptions(Command command, Document doc, ParagraphStyle headerStyle)
        {
            var para = doc.AddParagraph(new Paragraph(headerStyle));
            para.AddSpan("OPTIONS");
            para = doc.AddParagraph(new Paragraph());
            para.AddSpan("-------");

            var descStyle = new ParagraphStyle
            {
                Indent = 3,
                LinesAfter = 1
            };

            foreach (var named in command.NamedParameters)
            {
                para = doc.AddParagraph(new Paragraph());
                para.AddSpan(named.Usage);

                foreach (var p in MarkLeft.Parse(named.Description, descStyle))
                {
                    doc.AddParagraph(p);
                }
            }

            // TODO - add positional parameters from prior verbs
            foreach (var pos in command.PositionalParameters)
            {
                para = doc.AddParagraph(new Paragraph());
                para.AddSpan(pos.Usage);

                foreach (var p in MarkLeft.Parse(pos.Description, descStyle))
                {
                    doc.AddParagraph(p);
                }
            }
        }