Created
August 18, 2009 08:36
-
-
Save slashdotdash/169620 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Draw a progress bar at the current cursor position. | |
/// Be careful not to Console.WriteLine or anything whilst using this to show progress! | |
/// </summary> | |
/// <param name="progress">The position of the bar</param> | |
/// <param name="total">The amount it counts</param> | |
private static void DrawTextProgressBar(int progress, int total) | |
{ | |
//draw empty progress bar | |
Console.CursorLeft = 0; | |
Console.Write("["); //start | |
Console.CursorLeft = 32; | |
Console.Write("]"); //end | |
Console.CursorLeft = 1; | |
float onechunk = 30.0f / total; | |
//draw filled part | |
int position = 1; | |
for (int i = 0; i < onechunk * progress; i++) | |
{ | |
Console.BackgroundColor = ConsoleColor.Gray; | |
Console.CursorLeft = position++; | |
Console.Write(" "); | |
} | |
//draw unfilled part | |
for (int i = position; i <= 31; i++) | |
{ | |
Console.BackgroundColor = ConsoleColor.Black; | |
Console.CursorLeft = position++; | |
Console.Write(" "); | |
} | |
//draw totals | |
Console.CursorLeft = 35; | |
Console.BackgroundColor = ConsoleColor.Black; | |
Console.Write(progress.ToString() + " of " + total.ToString()+" "); //blanks at the end remove any excess | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment