/// <summary>
 /// Take the color of the given string to produce a new one, but with the given
 /// content.
 /// </summary>
 /// <param name="s">The input string.</param>
 /// <param name="newContent">The new content to use.</param>
 /// <returns>The generated string.</returns>
 /// <exception cref="ArgumentNullException">Thrown when <paramref name="newContent"/>
 /// is null.</exception>
 public static ColoredString WithContent(this ColoredString s, string newContent)
 {
     if (newContent == null)
     {
         throw new ArgumentNullException(nameof(newContent));
     }
     return(s.Transform(_ => newContent));
 }
Example #2
0
 /// <summary>
 /// Append a colored string followed by a newline.
 /// </summary>
 /// <param name="value">The colored string to append.</param>
 public void AppendLine(ColoredString value)
 {
     Append(value);
     Append(value.Transform(content => Environment.NewLine));
 }
Example #3
0
 /// <summary>
 /// Wrap the provided text at the given width, indenting it with the
 /// given indentation width.
 /// </summary>
 /// <param name="text">Text to wrap.</param>
 /// <param name="width">Maximum width of the text, in number of
 /// characters.</param>
 /// <param name="blockIndent">The number of characters to block-indent
 /// all lines. Use 0 to indicate no block indentation should occur.</param>
 /// <param name="hangingIndent">The number of characters to hanging-indent
 /// the text; all lines after the first line are affected, and the first
 /// line is left unmodified.  Use 0 to indicate no hanging indentation
 /// should occur.</param>
 /// <returns>The wrapped text.</returns>
 public static ColoredString Wrap(this ColoredString text, int width, int blockIndent = 0, int hangingIndent = 0) =>
 text.Transform(content => Wrap(content, width, blockIndent, hangingIndent));
 /// <summary>
 /// Returns a new string containing a substring of the given string.
 /// </summary>
 /// <param name="s">The string.</param>
 /// <param name="startIndex">The 0-based index to start from.</param>
 /// <param name="length">The length of the substring, expressed as
 /// a count of characters.</param>
 /// <returns>The new string.</returns>
 public static ColoredString Substring(this ColoredString s, int startIndex, int length) =>
 s.Transform(content => content.Substring(startIndex, length));