Colored chprintf

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
User avatar
tfAteba
Posts: 547
Joined: Fri Oct 16, 2015 11:03 pm
Location: Strasbourg, France
Has thanked: 91 times
Been thanked: 48 times

Colored chprintf

Postby tfAteba » Sat Sep 02, 2017 1:27 am

Hi Giovanni, Hi all,

For my robot, I use a set of macro to add color to chprintf and I think it would be interesting to share with other people in the forum.

Here are the macros:

Code: Select all

#define chprintf_r(x, y)  chprintf(x, "\x1b[31m" y "\x1b[0m")  /* Red            */
#define chprintf_g(x, y)  chprintf(x, "\x1b[32m" y "\x1b[0m")  /* Green        */
#define chprintf_y(x, y)  chprintf(x, "\x1b[33m" y "\x1b[0m")  /* Yellow.      */
#define chprintf_b(x, y)  chprintf(x, "\x1b[34m" y "\x1b[0m")  /* Blue.         */
#define chprintf_m(x, y)  chprintf(x, "\x1b[35m" y "\x1b[0m") /* Magenta.   */
#define chprintf_c(x, y)  chprintf(x, "\x1b[36m" y "\x1b[0m")  /* Cyant.       */
#define chprintf_w(x, y)  chprintf(x, "\x1b[0m" y "\x1b[0m")   /* White.       */


so to print a test in green we can use:

Code: Select all

chprintf_g(chp, "\n\r   Application is started.");


I join for example an image of the output log of the robot at boot time

If it could be interesting to have that feature, I can add it to chiprintf so that it will be easily usable by developers.

Thanks
Attachments
2017-09-02-022209_452x604_scrot.png
regards,

Theo.

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Colored chprintf

Postby Giovanni » Sat Sep 02, 2017 7:32 am

Hi Theo,

I think that is way out of scope for chprintf(), it is meant to be a simple utility, another problem is that those control code are for a specific terminal, it could not work on a different one.

Giovanni

User avatar
tfAteba
Posts: 547
Joined: Fri Oct 16, 2015 11:03 pm
Location: Strasbourg, France
Has thanked: 91 times
Been thanked: 48 times

Re: Colored chprintf

Postby tfAteba » Sat Sep 02, 2017 12:42 pm

It make sense, thanks for your point of view :)
regards,

Theo.


Return to “Development and Feedback”

Who is online

Users browsing this forum: No registered users and 11 guests