/// <summary> /// Returns a formatted string describing this option and its aliases. /// </summary> /// <param name="indent">The indentation to use.</param> /// <param name="nameColumnWidth">Width of the name column.</param> /// <param name="descriptionColumnWidth">Width of the description column.</param> /// <returns>a formatted string describing this option and its aliases that is suitable for displaying /// as a help message.</returns> public string ToString(int indent, int nameColumnWidth, int descriptionColumnWidth) { if (nameColumnWidth < 1) { throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, Crisis.Resources.CommandLineStrings.ArgMustBeGreaterThanZero, "nameColumnWidth"), "nameColumnWidth"); } if (descriptionColumnWidth < 1) { throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, Crisis.Resources.CommandLineStrings.ArgMustBeGreaterThanZero, "descriptionColumnWidth"), "descriptionColumnWidth"); } if (indent < 0) { throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, Crisis.Resources.CommandLineStrings.ArgMustBeNonNegative, "indent"), "indent"); } StringBuilder names = new StringBuilder(); names.Append(Name); foreach (string alias in mOption.Aliases) { names.Append(", "); names.Append(OptionStyleManager.PrefixOptionForDescription(mOptionStyles, alias)); } ColumnInfo nameColumn = new ColumnInfo(nameColumnWidth, names.ToString(), Alignment.Left); ColumnInfo descColumn = new ColumnInfo(descriptionColumnWidth, Description ?? "e", Alignment.Left, VerticalAlignment.Bottom); return(StringFormatter.FormatInColumns(indent, mUsageInfo.ColumnSpacing, nameColumn, descColumn)); }
/// <summary> /// Gets the list of errors as a formatted string. /// </summary> /// <param name="width">The width of the field in which to format the error list.</param> /// <returns>The list of errors formatted inside a field of the specified <paramref name="width"/></returns> public string GetErrorsAsString(int width) { if (width < IndentWidth + 7) { throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, CommandLineStrings.Arg0MustNotBeLessThan1, "width", IndentWidth + 7), "width"); } StringBuilder result = new StringBuilder(); result.Append(StringFormatter.WordWrap("Errors:", width)); result.Append(Environment.NewLine); StringBuilder errors = new StringBuilder(); foreach (ErrorInfo error in mParser.Errors) { errors.Append(error.Message); if (error.FileName != null) { errors.Append(String.Format(CultureInfo.CurrentUICulture, CommandLineStrings.OnLine0InFile1, error.Line, error.FileName)); } result.Append(StringFormatter.FormatInColumns(IndentWidth, 1, new ColumnInfo(1, "*"), new ColumnInfo(width - 1 - IndentWidth - 1, errors.ToString()))); result.Append('\n'); errors.Length = 0; } return(result.ToString()); }
private static void WriteAdditionalErrors(IList <string> additionalErrors) { var indentWidth = 3; Console.WriteLine("Errors:"); foreach (var message in additionalErrors) { Console.WriteLine(StringFormatter.FormatInColumns(indentWidth, 1, new ColumnInfo(1, "*"), new ColumnInfo(_consoleFormatWidth - 1 - indentWidth - 1, message))); } }
private void WriteMessage(ConsoleColor color, string label, string message, params object[] args) { if (IsWordWrapEnabled) { int col1Width = label.Length; int col2Width = Math.Max(1, Console.WindowWidth - col1Width - 2); string text = StringFormatter.FormatInColumns(m_indent, 1, new StringFormatter.ColumnInfo(col1Width, label), new StringFormatter.ColumnInfo(col2Width, String.Format(message, args))); WriteLine(color, text); } else { WriteLine(color, label + " " + String.Format(message, args)); } }
public void WriteTable(StringTable table, int columnSpacing = 3, bool addVerticalSeparation = false) { if (table == null) { throw new ArgumentNullException("table", "table is null."); } if (IsWordWrapEnabled) { int indent = m_indent; if (indent >= Console.WindowWidth - columnSpacing - 2) { indent = 0; } int maxWidth = Console.WindowWidth - indent; int col1Width = Math.Min(table.Labels.Max(text => text.Length), maxWidth / 2); int colSpacing = columnSpacing; int col2Width = maxWidth - col1Width - colSpacing - 1; for (int i = 0; i < table.Count; i++) { if (i > 0 && addVerticalSeparation) { Console.WriteLine(); } Console.WriteLine( StringFormatter.FormatInColumns(indent, colSpacing, new StringFormatter.ColumnInfo(col1Width, table.Labels[i]), new StringFormatter.ColumnInfo(col2Width, table.Values[i]))); } } else { for (int i = 0; i < table.Count; i++) { Console.WriteLine("{0}{1}{2}{3}", new String(' ', m_indent), table.Labels[i], new String(' ', columnSpacing), table.Values[i]); } } }
/// <summary> /// Retrieves a formatted string describing this option group and its options, suitable for displaying /// to the user as a help message. /// </summary> /// <param name="indent">The indentation to use.</param> /// <param name="nameColumnWidth">Width of the name column.</param> /// <param name="descriptionColumnWidth">Width of the description column.</param> /// <returns>a formatted string describing this option group and its options, suitable for displaying /// to the user as a help message.</returns> public string ToString(int indent, int nameColumnWidth, int descriptionColumnWidth) { if (nameColumnWidth < 1) { throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, Crisis.Resources.CommandLineStrings.ArgMustBeGreaterThanZero, "nameColumnWidth"), "nameColumnWidth"); } if (nameColumnWidth < 1) { throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, Crisis.Resources.CommandLineStrings.ArgMustBeGreaterThanZero, "descriptionColumnWidth"), "descriptionColumnWidth"); } if (indent < 0) { throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, Crisis.Resources.CommandLineStrings.ArgMustBeNonNegative, "indent"), "indent"); } StringBuilder result = new StringBuilder(); result.Append(StringFormatter.FormatInColumns(indent, 0, new ColumnInfo(nameColumnWidth + descriptionColumnWidth + mUsageInfo.ColumnSpacing, Name + ":"))); result.Append(Environment.NewLine); int newIndent = mUsageInfo.IndentWidth; if (Description != null) { result.Append(StringFormatter.FormatInColumns(newIndent + indent, 0, new ColumnInfo(nameColumnWidth + descriptionColumnWidth, Description, Alignment.Left, VerticalAlignment.Top, WordWrappingMethod.Optimal))); result.Append(Environment.NewLine); newIndent += mUsageInfo.IndentWidth; } foreach (KeyValuePair <string, OptionInfo> entry in mOptions) { result.Append(entry.Value.ToString(indent + newIndent, nameColumnWidth, descriptionColumnWidth - newIndent)); result.Append(Environment.NewLine); } return(result.ToString()); }