Posted By

novalis78 on 10/16/09


Tagged

bar ascii progress


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

khouser


ascii progress bar


 / Published in: C#
 

Main shows how to use the AsciiProgressBar. Enjoy!

  1. /// <summary>
  2. /// Paints an ascii progress bar based on the two input values
  3. /// </summary>
  4. /// <param name="total_size"></param>
  5. /// <param name="current_size"></param>
  6. public void AsciiProgressBar(int total_size, int current_size)
  7. {
  8. double percent = 0.0;
  9. int count = current_size;
  10. string output = "";
  11. double onePercent = (total_size / 100.0);
  12. percent = System.Math.Round(current_size / onePercent, 2);
  13.  
  14. if (percent >= upping)
  15. {
  16. upping += 2;
  17. }
  18. else if(percent < stepsOnScreen)
  19. {
  20. output = "\r" + percent + "%\t[";
  21. for (int f = upping; f < sizeOfBar; f++)
  22. output += "_";
  23. output += "]";
  24. Console.Write("\r + " + output);
  25. }
  26. else if (percent >= 99.99)
  27. {
  28. output = "\r" + "DONE!" + "%\t[";
  29. for (int i = 0; i <= upping / 2; i++)
  30. output += "=";
  31. output += ">";
  32. output += "]";
  33. Console.Write("\r + " + output);
  34. }
  35. else
  36. {
  37. output = "\r" + percent + "%\t[";
  38. for (int i = 0; i <= upping / 2; i++)
  39. output += "=";
  40. output += ">";
  41. for (int f = upping / 2; f < sizeOfBar; f++)
  42. output += "_";
  43. output += "]";
  44. Console.Write("\r + " + output);
  45. }
  46.  
  47. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: novalis78 on September 15, 2010

newer version:

=== how to use: AsciiBar bar = new AsciiBar(1); int cnter = 0; foreach(Item i in items) { cnter++; bar.AsciiProgressBar2(litems.Count, cnter);

}

/// /// Paints an ascii progress bar based on the two input values /// /// /// public void AsciiProgressBar(int totalsize, int currentsize) { double percent = 0.0; int count = currentsize; string output = ""; double onePercent = (totalsize / 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

You need to login to post a comment.