Пример #1
0
            public IEnumerable <string> GetDocStrings(CommandHomeDocFormatOption formatOption)
            {
                string indent    = formatOption.GetIndentString();
                int    indentLen = ConsoleText.CalcStringLength(indent);

                if (formatOption.IsSummary)
                {
                }
                else
                {
                    // description
                    yield return($"{Name}:");

                    foreach (string line in ClipString(Description, formatOption.BoundaryWidth - indentLen))
                    {
                        yield return($"{indent}{line}");
                    }
                    yield return(Environment.NewLine);

                    // commands
                    DocFormatOption cmdHomeFormatOption = new DocFormatOption()
                    {
                        IsSummary     = true,
                        BoundaryWidth = formatOption.Indent - indentLen
                    };
                    foreach (CommandHomeDoc cmdhomedoc in CommandHostDocs)
                    {
                        foreach (string line in cmdhomedoc.GetDocStrings(cmdHomeFormatOption))
                        {
                        }
                    }
                }
            }
Пример #2
0
            public static IEnumerable <string> ClipJoinString(IEnumerable <string> src, string separator, int width)
            {
                if (width <= 0)
                {
                    foreach (string str in src)
                    {
                        yield return(str);
                    }
                    yield break;
                }

                IEnumerator <string> enumerator = src.GetEnumerator();
                StringBuilder        sb         = new StringBuilder();
                int separatorLen = ConsoleText.CalcStringLength(separator);
                int curLineLen = 0, curLen;

                if (!enumerator.MoveNext())
                {
                    yield break;
                }

                sb.Append(enumerator.Current);

                foreach (string i in src)
                {
                    curLen = ConsoleText.CalcStringLength(i) + separatorLen;

                    if (curLineLen + curLen > width)
                    {
                        yield return(sb.ToString());

                        sb.Clear();
                        sb.Append(i);
                        curLineLen = curLen;
                    }
                    else
                    {
                        sb.Append(i);
                        curLineLen += curLen;
                    }
                }

                if (sb.Length > 0)
                {
                    yield return(sb.ToString());
                }
            }
Пример #3
0
 public static string PadStringLeft(string src, int width)
 {
     return(PadStringLeft(src, ConsoleText.CalcStringLength(src), width));
 }