Create a responsive progress bar in CMD with Progress by Kvc.
Professional applications use progress bars to assure the user that the program is working as expected. It gives users the ability visualize a tasks execution, and is especially useful in applications that are not intended to be real time. This plugin, created by Karanveer Chouhan (Kvc), allows you to create a custom, responsive and workload-aware progress bar using only Batch. In this article, we will discuss the syntax and use cases of this plugin.
SETTING UP OUR PROGRESS BAR
You can download the Progress plugin on our GitHub page. It is a single Batch file, so it simply needs to be in a directory accessible to your program, or in the PATH. The syntax for the plugin is very simple. The official demonstration seen on the help menu is here:
Progress [BarLength] [CurrentValue] [MaxValue] -- Where: -- ver : Displays version of program help : Displays help for the program BarLength : The Total Length of the Progress-bar on the CMD Screen CurrentValue : Current Progress Step, out of the total Steps MaxValue : Max number of Steps needed to get to the Task Completion -- Example: -- Call progress 75 45 68 The total length of the bar is 75 cells, the current progress is 45 steps, and the maximum steps to completion is 68.
USING PROGRESS IN A FOR LOOP
Let’s create a simple script that simply runs the plugin in a loop. To make things easy, it does nothing but increase the bar:
@echo off Mode 82,25 For /l %%A in (0,1,250) do (Call Progress 50 %%A 250) pause
The syntax of the function is easily demonstrated here. 250 is our maximum progress (how many iterations we have to do). 50 is the width of our bar (in character cells), and the plugin will create the bar based on this width. %%a is the current step we are on (as given by the FOR loop). Using the FOR Loop allows us to run work that requires iteration like this, and then report the progress on each iteration. With some additional nesting, it is possible to create progress bars for any task. The output of our example program is seen below:
As you can see, this plugin can very easily improve your application. It’s simple nature allows you to chain multiple progress bars together, which is very powerful for scripts with complex workflows. Kvc has exceeded my expectations with this plugin, and hopefully updates will come in the future. Thank you for reading this article. If you have any comments or suggestions, feel free to leave them below. We are always open to improving our platform and articles.
I am a programmer and a computer hobbyist in the United States. I make articles about a variety of topics.