Last active
August 18, 2024 22:12
-
-
Save dylanbeattie/9ef91c6f3d6a23b5ea00a97d51a7b223 to your computer and use it in GitHub Desktop.
An ASCII progress bar using a raw carriage return character
This file contains hidden or 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
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