From 7672be21e00ad67fd4dddd965ec091452c5eb9f9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 10 May 2018 11:28:33 -0700 Subject: [PATCH] terminal-util: add a function that shows a pretty separator line Follow-up for #8824 --- src/basic/terminal-util.c | 22 ++++++++++++++++++++++ src/basic/terminal-util.h | 2 ++ 2 files changed, 24 insertions(+) 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); -- 2.30.2