]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
terminal-util: add a function that shows a pretty separator line
authorLennart Poettering <lennart@poettering.net>
Thu, 10 May 2018 18:28:33 +0000 (11:28 -0700)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 11 May 2018 06:15:33 +0000 (08:15 +0200)
Follow-up for #8824

src/analyze/analyze.c
src/basic/terminal-util.c
src/basic/terminal-util.h
src/test/test-terminal-util.c

index c1b5aca7e2a10c1ffa2a0a3cb6d60d2b35333b14..5e1766b0536eaa781c288e84df10571e37471b3f 100644 (file)
@@ -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;
index 7f18d3d35cf8fc43bb61e6213fd7f4666163a4b9..fa90a466d219ca0afab42175f8b7a940fa0099d6 100644 (file)
@@ -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);
+}
index ea7eb2d63b59e12b1bd45bc7362c9089291fd9b5..798bab6c266bc94dfb49bdd3ef16f262beff2dff 100644 (file)
@@ -166,3 +166,5 @@ typedef enum CatFlags {
 } CatFlags;
 
 int cat_files(const char *file, char **dropins, CatFlags flags);
+
+void print_separator(void);
index 61a3ea5e56f08214e10c9033b80eae4bc3fea38a..216c8bef0029aa2762bee53fc9d42a02a657baf4 100644 (file)
@@ -94,5 +94,7 @@ int main(int argc, char *argv[]) {
         test_terminal_urlify();
         test_cat_files();
 
+        print_separator();
+
         return 0;
 }