Skip to content

Instantly share code, notes, and snippets.

@dylanbeattie
Last active August 18, 2024 22:12
Show Gist options
  • Save dylanbeattie/9ef91c6f3d6a23b5ea00a97d51a7b223 to your computer and use it in GitHub Desktop.
Save dylanbeattie/9ef91c6f3d6a23b5ea00a97d51a7b223 to your computer and use it in GitHub Desktop.
An ASCII progress bar using a raw carriage return character
Console.WriteLine("Progress bar demo using carriage returns");
const int STEPS = 40;
const string SPINNER = "|/-\\";
var random = new Random();
for (var i = 0; i <= STEPS; i++) {
Console.Write("\r");
Console.Write("Progress: ");
Console.Write(SPINNER[i%4]);
Console.Write(" [");
Console.Write(String.Empty.PadRight(i, '▓').PadRight(STEPS, ' '));
Console.Write("]");
Thread.Sleep(TimeSpan.FromMilliseconds(random.Next(200)));
}
Console.WriteLine();
Console.WriteLine("All done!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment