Search code examples
c++casciisublimetext

ASCII Art comments in C/C++ headers and code files


I watched with great interest the Mojang "Mojam" for Humble Bundle (link might not be valid for a long time), and throughout the video, I saw some great things on how these guys use their code.

One of these things was that one of the developer use ascii art comments in his code to better navigate around.

This gives something like this:

/////////////////////////////////////////////
//      ___  ___       ___   _   __   _    //
//     /   |/   |     /   | | | |  \ | |   //
//    / /|   /| |    / /| | | | |   \| |   //
//   / / |__/ | |   / / | | | | | |\   |   //
//  / /       | |  / /  | | | | | | \  |   //
// /_/        |_| /_/   |_| |_| |_|  \_|   //
//                                         //
/////////////////////////////////////////////
int main()
{
    // do some stuff
    return 0;
}

This may look bad right there, but associated with editors like Sublime, it becomes powerful, because the "zoomed out" view that Sublime exposes lets you read that text and navigate in your code like a breeze.

Now, there are plenty of cool ascii art text generators out there. But none of these (at least those I looked at) generate C++/C compliant text.

Meaning: I have to manually add the comment slashes (//) all around to make it go along in the code.

Do you guys use this trick?
If yes, do you have a tool to generate these "comments" around the text?


Solution

  • Yes I use to add those kinds of "nav" cues. Specially in communication parts which has many similar parts but handle i.e. different message types.

    I work on a Mac so here goes my setup.

    Previously I used a dashboard widget http://memention.com/figlet/

    But my latest thing is to create a Service with Automator and install figlet with homebrew. Then in the Service I have this one-liner (also clicked "Output replaces selected text")

    /usr/local/bin/figlet -f smslant -w 132
    

    Now in any App I can have figlets just by right-clicking some text.

    My preferred font is smslant

    Then I usually just add /* and */ after.

    Edit

    Well, I just updated my Service to add that C comment

    ( echo "/*" ; /usr/local/bin/figlet -f smslant -w 132 ; echo " */" )