Making Debugging more Fun with CoronaSDK

Any developer that has ever written software has at some point or the other had to run the app to test, and while doing so, must have also dumped a whole lot of data to the console/output window. It is fine to see a whole lot of data being dumped to the terminal, but then it all looks the same...

It would perhaps be a lot more work if one had to output using the print statements including the text to help identify the data. So, while some developers just like to use
 a = myImage.contentWidth
 print(a)

some might want it a bit more verbose

 a = myImage.contentWidth
 print("my image width is ", a)

this works fine, but then all of the text line by line just gets a bit too much and... the point of the exercise to dump to the terminal window is lost. It is then a lot of hard work to scroll through and find the data.

What if we wanted to check for a condition and have a Warning or an Error or a message? I was for some strange reason (for another article) looking up ncurses, for those that do not know what this is, that's fine you are not missing much. That somehow led me to ASCII Art and also ANSI Art, now if you do not know what that it, you are definitely missing out much. So, while I was looking up this (distraction) it came to me that most of the terminal windows supported ANSI. (Windows, there was an ansi.sys file that had to be installed in the startup file).

For any framework that outputted data to the Terminal, this would still be valid, so I tested it out and ... it was most pleasing.


This does not add much value to the app, but it definitely makes it more interesting while debugging and in helping find certain debug data that you might have printed to the consoles.

So how do you get that, it is very simple, ANSI codes use an escape sequence, so it is very simple. The format to change colors is
 Esc + [ + ColourValue

Where ESC is the escape character, the [ is the [ and the ColourValue is the value of the colour you want to set, more details can be found here on wikipedia http://en.wikipedia.org/wiki/ANSI_escape_code#Colors

Let me know if you found this helpful in anyways, and as I mentioned earlier, it has nothing to do with the actual app that gets installed on the device.

So have fun, colourful output will not only help to visually determine what's happening but also be helpful to track down certain errors or warnings that you need to look at, you can print the FPS in RED if it goes below a certain number, or the memory, etc. Though without the colour it is just another piece of information dumped to the terminal.

Please note: This is untested with Windows and it might or might not work with windows. It will definitely work with Mac OS and Linux.

Comments

  1. That's fine but I think you should have written a number of clear examples of what one has to write in print command in order to change colors. Anyway, thanks.
    Michael

    ReplyDelete
  2. Hi Michael,
    I have the link where there is a comprehensive list of all the colour codes and attributes that can be used http://en.wikipedia.org/wiki/ANSI_escape_code#Colors

    hope that helps

    ReplyDelete

Post a Comment

Popular Posts