diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-05-10 20:28:33 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-05-11 08:15:33 +0200 |
commit | cb91deaf77018e035b065edce9ebc88ba817347c (patch) | |
tree | 04a0f335f98b7f5b0397166ff490bfbe0a544b3a /src | |
parent | Merge pull request #8953 from yuwata/bus-macro (diff) | |
download | systemd-cb91deaf77018e035b065edce9ebc88ba817347c.tar.xz systemd-cb91deaf77018e035b065edce9ebc88ba817347c.zip |
terminal-util: add a function that shows a pretty separator line
Follow-up for #8824
Diffstat (limited to 'src')
-rw-r--r-- | src/analyze/analyze.c | 5 | ||||
-rw-r--r-- | src/basic/terminal-util.c | 22 | ||||
-rw-r--r-- | src/basic/terminal-util.h | 2 | ||||
-rw-r--r-- | src/test/test-terminal-util.c | 2 |
4 files changed, 27 insertions, 4 deletions
diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index c1b5aca7e2..5e1766b053 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -1322,10 +1322,7 @@ static int cat_config(int argc, char *argv[], void *userdata) { const char *t = NULL; if (arg != argv + 1) - printf("%s%*s%s\n\n", - ansi_underline(), - columns(), "", - ansi_normal()); + print_separator(); if (path_is_absolute(*arg)) { const char *dir; diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 7f18d3d35c..fa90a466d2 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -1418,3 +1418,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 ea7eb2d63b..798bab6c26 100644 --- a/src/basic/terminal-util.h +++ b/src/basic/terminal-util.h @@ -166,3 +166,5 @@ typedef enum CatFlags { } CatFlags; int cat_files(const char *file, char **dropins, CatFlags flags); + +void print_separator(void); diff --git a/src/test/test-terminal-util.c b/src/test/test-terminal-util.c index 61a3ea5e56..216c8bef00 100644 --- a/src/test/test-terminal-util.c +++ b/src/test/test-terminal-util.c @@ -94,5 +94,7 @@ int main(int argc, char *argv[]) { test_terminal_urlify(); test_cat_files(); + print_separator(); + return 0; } |