public void TestSubstring() { ConsoleString orig = new ConsoleString("0123456789"); ConsoleString sub = orig.Substring(5); ConsoleString sub2 = orig.Substring(5,1); Assert.AreEqual("56789", sub.ToString()); Assert.AreEqual("5", sub2.ToString()); }
/// <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 TestReplaceRegex() { ConsoleString orig = new ConsoleString("Credit Card: 1234-5678-9876-5432 - VISA"); ConsoleString cleaned = orig.ReplaceRegex(@"\d\d\d\d-\d\d\d\d-\d\d\d\d-\d\d\d\d", "xxxx-xxxx-xxxx-xxxx", ConsoleColor.White); Assert.AreEqual("Credit Card: xxxx-xxxx-xxxx-xxxx - VISA", cleaned.ToString()); ConsoleString hasPhoneNumber = new ConsoleString("Number: 222-333-4444"); hasPhoneNumber = hasPhoneNumber.ReplaceRegex(@"\d{3}-\d{3}-\d{4}", null, ConsoleColor.Green); Assert.AreEqual("Number: 222-333-4444", hasPhoneNumber.ToString()); Assert.AreEqual(new ConsoleString("222-333-4444", ConsoleColor.Green), hasPhoneNumber.Substring(8)); }
/// <summary> /// Asks the user if they are sure about performing some operation and returns true if they indicate yes and /// false if they indicate no. /// </summary> /// <param name="about">The message to display. 'Are you sure?' will be apended.</param> /// <returns>true if they indicate yes and false if they indicate no.</returns> public bool IsUserSure(ConsoleString about) { if (about.EndsWith(".")) { about = about.Substring(0, about.Length - 1); } var response = Prompt(about + ". Are you sure?", "y", "n"); if (response.Equals("y", StringComparison.InvariantCultureIgnoreCase) == true) { return true; } else { return false; } }
/// <summary> /// Asks the user if they are sure about performing some operation and returns true if they indicate yes and /// false if they indicate no. /// </summary> /// <param name="about">The message to display. 'Are you sure?' will be apended.</param> /// <returns>true if they indicate yes and false if they indicate no.</returns> public bool IsUserSure(ConsoleString about) { if (about.EndsWith(".")) { about = about.Substring(0, about.Length - 1); } var response = Prompt(about + ". Are you sure?", "y", "n"); if (response.Equals("y", StringComparison.InvariantCultureIgnoreCase) == true) { return(true); } else { return(false); } }