コード例 #1
0
        public void TestProgressBarDeterminateSanity()
        {
            var bar = new CliProgressBar("", 10);
            bar.Progress = .5;
            bar.Render();
            Assert.AreEqual(6, bar.renderedMessage.Length);

            for(int i = 0; i < bar.renderedMessage.Length; i++)
            {
                if(i < 3)
                {
                    // the first three characters should be filled since the progress is .5
                    Assert.AreEqual(bar.renderedMessage[i].ForegroundColor, bar.MessageFillColor);
                    Assert.AreEqual(bar.renderedMessage[i].BackgroundColor, bar.FillColor);
                }
                else
                {
                    // the final three characters should NOT BE FILLED since the progress is .5
                    Assert.AreEqual(bar.renderedMessage[i].ForegroundColor, ConsoleString.DefaultForegroundColor);
                    Assert.AreEqual(bar.renderedMessage[i].BackgroundColor, ConsoleString.DefaultBackgroundColor);
                }
            }
        }
コード例 #2
0
        public void TestProgressBarDeterminateSanity()
        {
            var bar = new CliProgressBar("", 10);

            bar.Progress = .5;
            bar.Render();
            Assert.AreEqual(6, bar.renderedMessage.Length);

            for (int i = 0; i < bar.renderedMessage.Length; i++)
            {
                if (i < 3)
                {
                    // the first three characters should be filled since the progress is .5
                    Assert.AreEqual(bar.renderedMessage[i].ForegroundColor, bar.MessageFillColor);
                    Assert.AreEqual(bar.renderedMessage[i].BackgroundColor, bar.FillColor);
                }
                else
                {
                    // the final three characters should NOT BE FILLED since the progress is .5
                    Assert.AreEqual(bar.renderedMessage[i].ForegroundColor, ConsoleString.DefaultForegroundColor);
                    Assert.AreEqual(bar.renderedMessage[i].BackgroundColor, ConsoleString.DefaultBackgroundColor);
                }
            }
        }
コード例 #3
0
        public static void RenderConsoleProgress(int percentage)
        {
            if (Progress == percentage)
            {
                return;
            }

            CursorVisible = false;
            const int BarHeight = 3;
            var       BarStart  = (WindowTop + WindowHeight - 1) - BarHeight;

            CursorTop = BarStart;

            if (!DisableProgressBar)
            {
                Bar.Progress = percentage / 100.00;
                Bar.Message  = BaseMessage.AppendUsingCurrentFormat($".  {percentage} %");
                Bar.Render();
            }
            else if (TextInfo && percentage != Progress)
            {
                ForegroundColor = ConsoleColor.DarkBlue;
                BackgroundColor = ConsoleColor.Yellow;
                WriteLine($" {percentage} % ");
            }

            CursorTop = BarStart - 1;

            Progress = percentage;


            /*
             * Progress = percentage;
             * CursorVisible = false;
             *
             * var BottomOfCon = WindowTop + WindowHeight - 1;
             * var BottomOfBuffer = BufferHeight - WindowHeight - BarHeight;
             * SavePos = CursorTop;
             * var MaxText = (WindowTop + WindowHeight - 1) - BarHeight;
             * var BarLine = MaxText + 1;
             * while (SavePos-- >= MaxText)
             *  WriteLine("\t\t\t\t\t".PadRight(WindowWidth));
             * SavePos = CursorTop;
             *
             * //if (LastProgLine != SavePos && CursorTop + BarHeight >= BufferHeight)
             * //WriteLine();
             *
             * var originalColor = ForegroundColor;
             * var origback = BackgroundColor;
             * ForegroundColor = pBarColor;
             * CursorLeft = 0;
             *
             * //LastProgLine = CursorTop = BottomOfCon - BarHeight;
             * var width = Console.WindowWidth - 4;
             * var newWidth = ((width * percentage) / 100);  // incase some change happened
             *
             * CursorTop = BarLine;
             * Bar.Width = newWidth;
             * Bar.Progress = percentage / 100.00;
             * Bar.Render();
             *
             * //            var progBar = new StringBuilder(new string(progressBarCharacter, newWidth)).Append(new string(' ', width - newWidth));
             * //            Write(progBar.ToString());
             *
             * CursorLeft = 0;
             * ForegroundColor = originalColor;
             * CursorTop = SavePos;
             * CursorVisible = true;
             */
        }