Return to Snippet

Revision: 19186
at September 15, 2010 04:51 by novalis78


Updated Code
/// <summary>
        /// Paints an ascii progress bar based on the two input values
        /// </summary>
        /// <param name="total_size"></param>
        /// <param name="current_size"></param>
        public void AsciiProgressBar(int total_size, int current_size)
        {
            double percent = 0.0;
            int count = current_size;
            string output = "";
            double onePercent = (total_size / 100.0);
            percent = System.Math.Round(current_size / onePercent, 2);

            if (percent >= upping)
            {
                upping += 2;
            }
            else if(percent < stepsOnScreen)
            {
                output = "\r" + percent + "%\t[";
                for (int f = upping; f < sizeOfBar; f++)
                    output += "_";
                output += "]";
                Console.Write("\r + " + output);
            }
            else if (percent >= 99.99)
            {
                output = "\r" + "DONE!" + "%\t[";
                for (int i = 0; i <= upping / 2; i++)
                    output += "=";
                output += ">";
                output += "]";
                Console.Write("\r + " + output);
            }
            else
            {
                output = "\r" + percent + "%\t[";
                for (int i = 0; i <= upping / 2; i++)
                    output += "=";
                output += ">";
                for (int f = upping / 2; f < sizeOfBar; f++)
                    output += "_";
                output += "]";
                Console.Write("\r + " + output);
            }
            
        }

Revision: 19185
at October 16, 2009 22:52 by novalis78


Initial Code
static void Main(string[] args)
        {
            Console.WriteLine("Console Ascii Bar");
            for (int x = 1; x <= 100; x++)
            {
                AsciiProgressBar(100, x);
                System.Threading.Thread.Sleep(100);
            }
            Console.ReadLine();
        }

        static void AsciiProgressBar(int total_size, int current_size)
        {
            int percent = 0;
            int count = current_size;
            string output = "";

            if (count % 10 == 0) 
            {
               percent = count * (total_size / 100);
               percent = percent / 2;
               output = "\r"+percent*2+"% [";
               for (int i=0;i<=percent;i++)
                  output += "=";
               output += ">";
               for (int f=percent;f<50;f++)
                  output += "_";
               output += "]";
               Console.Write("\r + " + output);
            }

Initial URL

                                

Initial Description
Main shows how to use the AsciiProgressBar. Enjoy!

Initial Title
ascii progress bar

Initial Tags

                                

Initial Language
C#