示例#1
0
        /// <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();
        }
示例#2
0
        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)));
        }
示例#3
0
        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);
            }
        }
示例#4
0
        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)));
        }
示例#5
0
        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);
            }
        }
示例#6
0
        /// <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();
        }