#8 Colored output

open
nobody
7
2008-09-18
2008-09-18
dante4d
No

I'd like to have colored output from pwsafe, it would greatly improve readability. I already tried to implement it, check the screenshot.

I'm willing to do it myself if we settle on how I should implement it. For now I did it like (with adding -c|--color switch that fills arg_color bool variable):

void DB::list(const char* regex /* might be NULL */) {
...
// entry color formating
const char* name_fmt = "%s";
const char* login_fmt = " - %s\n";
const char* default_login_fmt = " - [%s]\n";
if (arg_color) {
name_fmt = "\033[1;31;40m%s\033[0m";
login_fmt = " - \033[1;32;40m%s\033[0m\n";
default_login_fmt = " - [\033[1;33;40m%s\033[0m]\n";
}
...
fprintf(outfile,name_fmt, e.groupname().c_str());

// append the login if it exists
if (!e.login.empty())
fprintf(outfile,login_fmt, e.login.c_str());
else if (e.default_login)
fprintf(outfile,default_login_fmt,
...

Discussion

  • dante4d
    dante4d
    2008-09-18

    • priority: 5 --> 7