Progress Being Had

Adobe AIR™ loading... I occasionally get the opportunity to revisit code and rewrite applications i’ve written previously. Without fail i can always tell which of the applications was being used by me directly and how often i was running it, if not by the quality of the code… by the progress monitor i implemented. There are usually three monitors, and i can see each of them standing as a checkpoint to the next.

  1. DONE!
  2. Iterate through with some character dropped on the screen
  3. A Percentage completed bar that updates

Each one has its benefits and usefulness, so i figured id take a moment to step through each of them and where i use it, as well as how i coded it for the latter two.


This is really only useful for short running processes as it conveys no progress other than steps being completed. Printing out DONE, Loading, Processing or any other progress hiding moniker when you have completed tasks is really only beneficial when you are working on step by step tasks that are hard to either get updates to the user about or are too quick to bother with one of the other two methods.

If you have ever loaded Linux and then loaded windows in safe-mode you should be able to see the next. They ignore pain and time and vomit nearly every detail of setting up the operating system to the screen.


Starting windows typically is really more of an iteration based process, albeit more of a waiting game than knowing that anything is actually going on behind the curtain of the windows load screen. You are given a simple iterating

One thing that comes up a lot when I’m working on Watir or file parsing is that i have 430 links to touch and some further work to do within each one. The problem is that these situations require output to the user because otherwise it is not saying anything to the user for 45 minutes or an hour and they will likely assume the computer is hung up or think that its a good idea to turn it off, saving power and all this.

In order to avoid this situation you may want to print something to the console to show that the processor is being used. Typical characters are the pipe (|) or a dot (.). The problem is that if you are doing this with lots of things to do it will overrun the typical 80 character buffer. Some OS’s may wrap to the next line, but others wont and that’s just no good. A second thing to keep in mind is that your processing may have issues so you should try to catch them

Here is my solution:

counter = 1

print "Beginning"

testCases.each { |k|
		print "."
	rescue StandardError => bang
		print "#"
		## Catalog Errors in an array or hash here

	if (counter % 80) = 0
		print "n"

	counter += 1

print "nn"

As i mentioned above though, this is really quite crude and if you are only doing a couple things that take a second, don’t even bother with this. It will print out a (.) character on success and a (#) character if there are any issues in the testing and with the use of a counter you can move to the next character.

Percentage Counter

When you get into using something on a regular basis and need to keep track of the progress so you know when you can take a bio-break or read a book while it processes you can turn to a visual read out and get a more visual progress monitor. For whatever this is worth, i absolutely love this solution and since it is written as a function here you can use it as easy as i can.

# current and total are integers
def printPercentage(current, total)
	width 		= 80	# Screenwidth to use in characters
	charIteration 	= "="	# Each step along the percentage counter is a ...
	charRest	= " "	# All other space is a ...

	charBeginning 	= "["
	charEnd		= "]"

	print "r" + charBeginning

	percentCompleted = [((current * 1.0 / total) * width).to_i, width].min
	percentCompleted.times {print charIteration}

	if (width - percentCompleted) >= 5
		(width - percentCompleted - 5).times {print charRest}
		print " " + (current * 100.0 / total).to_i.to_s + "% "
		(width - percentCompleted).times{print charRest}

	print charEnd + " " + current.to_s + "/" + total.to_s

This option is definitely more complicated, and it requires even less knowledge of the world. All you have to pass into this function is the two values you are trying to print as a ratio, beyond that everything is on auto pilot.

The output is something to the tune of the following and is quite nice to watch as it takes advantage of the r character resetting the cursor to the beginning of the line and redrawing the progress bar.

Mind you, i realize this is just console level. In all of the modern GUI options they implement Progress bars that work like this one does and you can even make them meaningless so they operate like the “.” option described above. One other note is that output buffering may be enabled on the language you choose to implement this in. I know that Perl’s needs a change of a parameter ($| = “3”) but you should look around

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.