/*** * BaCon does not support Write (as opposed to WriteLine) because BaCon needs to have full control over the line * that it is printing on in order for line wrapping to work correctly. */ /// <summary> /// Writes the value to the console using the given options. /// </summary> /// <param name="value">The value to write.</param> /// <param name="color">The color to print the value in. Only works when using the Console.</param> /// <param name="indent1">Number of spaces to put in front of first line of text.</param> /// <param name="indentN">Number of spaces to put in front of following lines of text if the value must be wrapped to additional lines.</param> public static void WriteLine(string value = null, ConsoleColor?color = null, string indent1 = "", string indentN = "") { if (value.IsEmpty()) { (Out ?? Console.Out).WriteLine(); return; } using (var clr = new BaConColor(color ?? Console.ForegroundColor)) { var displayVal = value; if (indent1.HasValue()) { displayVal = indent1 + displayVal; } var options = new StringWrapOptions() { MaxWidth = ConsoleWidth, TabWidth = ConsoleTabWidth, Prefix = indentN }; displayVal = displayVal.Wrap(options); (Out ?? Console.Out).WriteLine(displayVal); } }
public void WrapWithTabTest() { var options = new StringWrapOptions() { MaxWidth = 12, TabWidth = 4 }; var actual = "\tWhat about this?".Wrap(options); Assert.AreEqual("\tWhat\r\nabout this?", actual); options.Prefix = "\t"; actual = "\tWhat about this?".Wrap(options); Assert.AreEqual("\tWhat\r\n\tabout\r\n\tthis?", actual); options = new StringWrapOptions() { MaxWidth = 20, TabWidth = 4 }; actual = "Do\tsomething\twith\tinternal\ttabs.".Wrap(options); Assert.AreEqual("Do\tsomething\twith\r\ninternal\ttabs.", actual); options = new StringWrapOptions() { MaxWidth = 9, TabWidth = 8 }; actual = "123456789\n1\t9 123456789".Wrap(options); Assert.AreEqual("123456789\r\n1\t9\r\n123456789", actual); }
public void WrapWithPrefixTest() { var options = new StringWrapOptions() { MaxWidth = 10, TabWidth = 4, Prefix = " >> " }; var expected = "This is a\r\n >> test\r\n >> of the\r\n >> emerge\r\n >> ncy\r\n >> broadc\r\n >> ast\r\n >> system\r\n >> ."; var actual = "This is a test of the emergency broadcast system.".Wrap(options); Assert.AreEqual(expected, actual); }
public void BaConErrorTest() { // This is an error we are getting in the help for the sample console app. // It was adding an extra, blank line to the output. var str = @"/Name <String> REQUIRED The name of the person. The field Name must be a string with a minimum length of 2 and a maximum length of 20." ; var expected = Normalize(@"/Name <String> REQUIRED The name of the person. The field Name must be a string with a minimum length of 2 and a maximum length of 20." ); var options = new StringWrapOptions() { MaxWidth = 59, TabWidth = 8, Prefix = "\t" }; var actual = Normalize(str.Wrap(options)); Assert.AreEqual(expected, actual); }