/ Published in: C#
Main shows how to use the AsciiProgressBar. Enjoy!
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/// <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); } }