C/C++ Strings Output Support

Home Forums PabloDraw Feature Requests C/C++ Strings Output Support

This topic is: not resolved

This topic contains 0 replies, has 1 voice, and was last updated by  Jonathan Rumion 6 years, 3 months ago.

Viewing 1 post (of 1 total)
  • Author
  • #2310 Reply

    Jonathan Rumion

    I’d like to suggest adding a new output mode for text-console developers using C++.

    After adapting a few changes to the output for ansi (.ans) mode, I’ve been able to easily import the colored images into the C++ strings class, and I figured that even if the feature isn’t included in pablodraw, that someone will find this of use.

    After drawing an image in PabloDraw, I save it an ansi .ans file. I then open the file up in a Text editor, TextEdit for OSX being the most generic one I have, and save the output as a .txt file. This is because I get weird behavior opening the .ans files in Xcode, my IDE, directly.

    Anyways, I replace the ansi escape characters with the C++ hex statements with a quick Find and Replace like so:

    Find all “[” (or whatever the Escape Characters show up for you as, and replace with “\x1b[“. So that:
    I then close off the end with a newline “\n”, and surround the line with quotation marks “.

    Do this for every line in the file, and use the finished product as a string:


    std::string world(“\x1b[2J\x1b[H\x1b[7h\x1b[0;1;40;37m\x1b[?33h\n”

    “\x1b[18C\x1b[5m..\x1b[25m\x1b[10C\x1b[0m\x1b[7C\x1b[34m€€€€€€€€€€€\x1b[37m\x1b[19C\x1b[1m   \x1b[5m..\x1b[25m\n”

    “\x1b[18C\x1b[5m..\x1b[25m\x1b[10C\x1b[0m    \x1b[34m€€€\x1b[37m \x1b[34m.,;;;;;,.\x1b[37m \x1b[34m€€€\n”

    “\x1b[1;37m\x1b[30C\x1b[0m  \x1b[34m€€\x1b[37m \x1b[34m.,%!&&!%;%%%,.\x1b[37m  \x1b[34m€€\x1b[37m\x1b[14C\x1b[1m\x1b[6C.,,;%\n”

    “\x1b[29C\x1b[0m \x1b[34m€€.,\x1b[32m%!&\x1b[34m###&!!&@@@&&!;.\x1b[37m \x1b[34m€€\x1b[37m\x1b[10C\x1b[1m…,,;!!%!&!%\n”

    “\x1b[24C\x1b[0m\x1b[5C\x1b[34m€.\x1b[32m;&#@@@\x1b[34m@\x1b[32m@@@@@\x1b[34m@@@@@@@\x1b[32m@@&;\x1b[37m \x1b[34m€\x1b[37m   \x1b[1m.,,.,;%!!###@@!;%,\n”

    “\x1b[25C\x1b[0m   \x1b[34m€\x1b[32m.;&@@@@@@@@@@@\x1b[34m@@@@@@\x1b[32m@@@@@\x1b[34m;.€\x1b[37m  \x1b[1m,%%;%!%%!#&%!&;\n”

    “\x1b[7C\x1b[5m..\x1b[25m\x1b[16C\x1b[0m  \x1b[34m€\x1b[32m,!#@@@@@@@@@@@@\x1b[34m@@@@@@\x1b[32m@@@@\x1b[34m@#;\x1b[37m \x1b[34m€\x1b[37m \x1b[1m.;%;;%%%%%,  \x1b[5m..\x1b[25m\n”

    “\x1b[7C\x1b[5m..\x1b[25m\x1b[16C\x1b[0m  \x1b[34m€\x1b[32m;#@@@@@@@@@@@@\x1b[34m@@@@@@@@@@@@@%\x1b[37m \x1b[34m€\x1b[37m \x1b[1m,;%%,,;%;;;.\n”

    “\x1b[17C\x1b[5m..\x1b[25m\x1b[7C\x1b[0m \x1b[34m€\x1b[32m%@@#@\x1b[34m@\x1b[32m@@@@@\x1b[34m@@#@@@@@@@@@@@@#%\x1b[37m \x1b[34m€\x1b[37m \x1b[1m;;;%.    .,.\n”

    “\x1b[17C\x1b[5m..\x1b[25m\x1b[7C\x1b[0m \x1b[34m€,\x1b[32m%#&&\x1b[34m@@@#######@@@@@\x1b[32m@@@\x1b[34m@@\x1b[32m@#%\x1b[37m \x1b[34m€\x1b[37m \x1b[1m….\n”

    “\x1b[26C\x1b[0m \x1b[34m€.,%!!##@@@@@#@#@@\x1b[32m@@@@@@@@@#;\x1b[37m \x1b[34m€\n”

    “\x1b[1;37m\x1b[24C.,,.\x1b[0;34m€\x1b[37m \x1b[34m.;%&&#&#&##@@\x1b[32m@@@@@@@@@@#%\x1b[34m.€\n”

    “\x1b[1;37m\x1b[21C;!%%%&%\x1b[0m \x1b[34m€\x1b[37m \x1b[34m.,%&@@@###@@\x1b[32m@@@@@@\x1b[34m&\x1b[32m&!!;\x1b[34m.€\x1b[1;37m\x1b[10C\x1b[5m..\x1b[25m\n”

    ”   .;,\x1b[10C.. ,%&#!;,%%.\x1b[0m \x1b[34m€€\x1b[37m  \x1b[34m.,;%!@@@@@\x1b[32m@@\x1b[34m@##%%,.€€\x1b[37m \x1b[1m\x1b[10C\x1b[5m..\x1b[25m\n”

    ”   .;,\x1b[7C,;,%!%!&%,,,,,;%,..\x1b[0;34m€€.,;;;%!&&&&&#&!,.€€\n”

    “\x1b[1;37m\x1b[6C;%,;%;;!!%%%!&!;,,,,,,;,..\x1b[0m  \x1b[34m€€€.,;;%%%;;;,.€€\n”

    “\x1b[37m \x1b[1m\x1b[5C;%,;%;;;,,..,;;,,.\x1b[5C\x1b[0m\x1b[8C\x1b[34m€€€€€€€€€€€\n”);


    (There’s a few other escape characters in there that I’ve thrown in for this particular example, they’re not necessary to make this work however)

    Take that string, output it to a console that has full ansi support (in this example, iTerm2 with ANSI blinking enabled to make the stars blink) and you get:



    tl;dr – I’m requesting an output file type that instead of using actual escape characters in the file, simply writes the C++ hex escape sequences “\x1b[“, and also does the little bit of extra work of surrounding the lines in quotes and adding newlines “\n”.

    I know quite a few game developers that would really find this useful 🙂


Viewing 1 post (of 1 total)
Reply To: C/C++ Strings Output Support
Your information: