mirror of
https://github.com/troglobit/libite.git
synced 2026-10-12 10:12:22 +00:00
Add printhdr(), replacement for printheader() with ANSI attribute
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
@@ -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
@@ -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_ */
|
||||
|
||||
Reference in New Issue
Block a user