From: Lennart Poettering Date: Thu, 10 May 2018 18:28:33 +0000 (-0700) Subject: terminal-util: add a function that shows a pretty separator line X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=7672be21e00ad67fd4dddd965ec091452c5eb9f9;p=elogind.git terminal-util: add a function that shows a pretty separator line Follow-up for #8824 --- diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 4ce5e8ab4..578fa4a57 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -1437,3 +1437,25 @@ int cat_files(const char *file, char **dropins, CatFlags flags) { return 0; } + +void print_separator(void) { + + /* Outputs a separator line that resolves to whitespace when copied from the terminal. We do that by outputting + * one line filled with spaces with ANSI underline set, followed by a second (empty) line. */ + + if (underline_enabled()) { + size_t i, c; + + c = columns(); + + flockfile(stdout); + fputs_unlocked(ANSI_UNDERLINE, stdout); + + for (i = 0; i < c; i++) + fputc_unlocked(' ', stdout); + + fputs_unlocked(ANSI_NORMAL "\n\n", stdout); + funlockfile(stdout); + } else + fputs("\n\n", stdout); +} diff --git a/src/basic/terminal-util.h b/src/basic/terminal-util.h index e7b64c63d..561e6f117 100644 --- a/src/basic/terminal-util.h +++ b/src/basic/terminal-util.h @@ -184,3 +184,5 @@ typedef enum CatFlags { } CatFlags; int cat_files(const char *file, char **dropins, CatFlags flags); + +void print_separator(void);