/// <summary> /// Renders the middle portion of the progress bar that contains the message and progress fill. You must have called Render() ahead of time for this /// to make sense. /// </summary> public void Update() { var maxMessageLength = Width - 4; renderedMessage = Message; renderedMessage = renderedMessage.Replace("{%}", Math.Round(Progress * 100, 1) + " %"); if (renderedMessage.Length > maxMessageLength) { renderedMessage = renderedMessage.Substring(0, maxMessageLength - 3) + "..."; } while (renderedMessage.Length < maxMessageLength) { renderedMessage += " "; } if (indeterminateHighlightIndex < 0) { int toHighlight = (int)Math.Round(Progress * renderedMessage.Length); renderedMessage = renderedMessage.HighlightSubstring(0, toHighlight, MessageFillColor, FillColor); } else { renderedMessage = renderedMessage.HighlightSubstring(indeterminateHighlightIndex, 1, MessageFillColor, FillColor); } messageStart.Restore(); Console.Write(renderedMessage); wiper.MoveCursorToLineAfterBottom(); }
public void TestReplaceMultiple() { ConsoleString orig = new ConsoleString("WRedWBlueW"); ConsoleString white = orig.Replace("W", "White", ConsoleColor.White); Assert.AreEqual("WRedWBlueW", orig.ToString()); Assert.AreEqual("WhiteRedWhiteBlueWhite", white.ToString()); Assert.AreEqual("WhiteWhiteWhite", string.Join("", white.Where(c => c.ForegroundColor == ConsoleColor.White).Select(c => c.Value))); }
public void TestReplaceCharByChar() { var testString = "Some Test String"; for (int i = 0; i < testString.Length; i++) { ConsoleString orig = new ConsoleString(testString); ConsoleString replaced = orig.Replace(testString[i] + "", testString[i] + "", ConsoleColor.Red); Assert.AreEqual(ConsoleColor.Gray, orig[i].ForegroundColor); Assert.AreEqual(ConsoleColor.Red, replaced[i].ForegroundColor); } }
public void TestReplaceOtherCases() { ConsoleString orig = new ConsoleString("RedWBlue"); ConsoleString white = orig.Replace("W", "White", ConsoleColor.White); Assert.AreEqual("RedWBlue", orig.ToString()); Assert.AreEqual("RedWhiteBlue", white.ToString()); Assert.AreEqual("White", string.Join("",white.Where(c => c.ForegroundColor == ConsoleColor.White).Select(c=> c.Value))); }
public void TestReplaceCharByChar() { var testString = "Some Test String"; for (int i = 0; i < testString.Length; i++) { ConsoleString orig = new ConsoleString(testString); ConsoleString replaced = orig.Replace(testString[i]+"", testString[i]+"", ConsoleColor.Red); Assert.AreEqual(ConsoleColor.Gray, orig[i].ForegroundColor); Assert.AreEqual(ConsoleColor.Red, replaced[i].ForegroundColor); } }