Add printhdr(), replacement for printheader() with ANSI attribute

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2019-08-21 23:57:29 +02:00
parent 83ace4f12d
commit 72d1cb6501
2 changed files with 19 additions and 5 deletions
+1
View File
@@ -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
+18 -5
View File
@@ -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_ */