diff --git a/ChangeLog.md b/ChangeLog.md index 3469345..ab55f7c 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -10,6 +10,7 @@ All notable changes to the project are documented in this file. - Add support for `strmatch()` and `strnmatch()` - Add support for `yorn()`, safe yes-or-no prompt - Add support for telnet expect/session APIs +- Add modified `printhdr()` which takes ANSI attribute ### Fixes - Fix `pidfile_signal()`: always return result of `kill()`, or the diff --git a/src/conio.h b/src/conio.h index 261947f..8e0918d 100644 --- a/src/conio.h +++ b/src/conio.h @@ -82,13 +82,26 @@ extern "C" void initscr(int *row, int *col); -/* Print table heading @line to @fp, with optional leading newline */ +/* Print table heading @line to @fp, with optional leading newline + * Example: + * _________________ <-- Empty line with UNDERSCORE to frame first heading + * First heading <-- In normal/RESETATTR + * SUBHEADING <-- In REVERSE and with capital letters like 'top' + */ +static inline void printhdr(FILE *fp, const char *line, int nl, int attr) +{ + if (attr < 0 || attr > 8) + attr = REVERSE; + + fprintf(fp ?: stdout, + "%s\033[%dm%s%*s\033[0m\n", + nl ? "\n" : "", attr, line, + SCREEN_WIDTH - (int)strlen(line), ""); +} + static inline void printheader(FILE *fp, const char *line, int nl) { - fprintf(fp ?: stdout, - "%s\033[7m%s%*s\033[0m\n", - nl ? "\n" : "", - line, SCREEN_WIDTH - (int)strlen(line), ""); + printhdr(fp, line, nl, REVERSE); } #endif /* CONIO_H_ */