Skip to content

Instantly share code, notes, and snippets.

@bond-
Last active January 25, 2024 15:42
Show Gist options
  • Save bond-/c6d25a99ce345c75d8a4934e62f9a0f0 to your computer and use it in GitHub Desktop.
Save bond-/c6d25a99ce345c75d8a4934e62f9a0f0 to your computer and use it in GitHub Desktop.
Command line progress bar in Groovy
int spaces = 20
int progress = 100
(progress + 1).times {
// String * int is a shortcut to repeat string that many times
String hash = "#" * Math.ceil((it*spaces)/100.0);
// Carraige return (\r) returns the cursor to first character in line, overwriting other characters
print(String.format("[%-" + spaces + "s] %d%s\r", hash, it, '%'))
// Wait for 100 milli seconds to seem like an animation
Thread.sleep(100)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment