chiark / gitweb /
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)
committerSven Eden <yamakuzure@gmx.net>
Fri, 24 Aug 2018 14:47:08 +0000 (16:47 +0200)
Follow-up for #8824

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

index 4ce5e8ab4292826aff520c6964e691dbbd283c18..578fa4a57757f3fa3f3dd52d5813e0d225578941 100644 (file)
@@ -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);
+}
index e7b64c63dc336fe3f7f52b17fd7f1e94164aef3f..561e6f117954d79fc6038a23c62cd47af3b16d7f 100644 (file)
@@ -184,3 +184,5 @@ typedef enum CatFlags {
 } CatFlags;
 
 int cat_files(const char *file, char **dropins, CatFlags flags);
+
+void print_separator(void);