chiark / gitweb /
util, core: add support for ephemeral status lines
authorMichal Schmidt <mschmidt@redhat.com>
Wed, 27 Feb 2013 21:52:43 +0000 (22:52 +0100)
committerMichal Schmidt <mschmidt@redhat.com>
Thu, 28 Feb 2013 01:23:27 +0000 (02:23 +0100)
Ephemeral status lines do not end with a newline and they expect to be
overwritten by the next printed status line.

src/core/job.c
src/core/manager.c
src/core/manager.h
src/shared/util.c
src/shared/util.h

index 9f792b84fdd696681dfd4d639d35e40a651b0694..90de550016ff22cbf34600e66f597c72467c33b2 100644 (file)
@@ -649,7 +649,7 @@ static void job_print_status_message(Unit *u, JobType t, JobResult result) {
 
                 case JOB_FAILED:
                         unit_status_printf(u, ANSI_HIGHLIGHT_RED_ON "FAILED" ANSI_HIGHLIGHT_OFF, format);
 
                 case JOB_FAILED:
                         unit_status_printf(u, ANSI_HIGHLIGHT_RED_ON "FAILED" ANSI_HIGHLIGHT_OFF, format);
-                        manager_status_printf(u->manager, NULL, "See 'systemctl status %s' for details.", u->id);
+                        manager_status_printf(u->manager, false, NULL, "See 'systemctl status %s' for details.", u->id);
                         break;
 
                 case JOB_DEPENDENCY:
                         break;
 
                 case JOB_DEPENDENCY:
index 1dac69b791d132077754aa477203f89afea4985d..c6f13f7d5a0893d2a1383bcfb5351875db5f400d 100644 (file)
@@ -2494,7 +2494,7 @@ static bool manager_get_show_status(Manager *m) {
         return plymouth_running();
 }
 
         return plymouth_running();
 }
 
-void manager_status_printf(Manager *m, const char *status, const char *format, ...) {
+void manager_status_printf(Manager *m, bool ephemeral, const char *status, const char *format, ...) {
         va_list ap;
 
         if (!manager_get_show_status(m))
         va_list ap;
 
         if (!manager_get_show_status(m))
@@ -2504,7 +2504,7 @@ void manager_status_printf(Manager *m, const char *status, const char *format, .
                 return;
 
         va_start(ap, format);
                 return;
 
         va_start(ap, format);
-        status_vprintf(status, true, format, ap);
+        status_vprintf(status, true, ephemeral, format, ap);
         va_end(ap);
 }
 
         va_end(ap);
 }
 
index d21f27dfd469b04fd3f9082641a08b044d2852a5..0d0255289a4b9325da1a4365b6b367491ba7bc7d 100644 (file)
@@ -293,6 +293,6 @@ void manager_undo_generators(Manager *m);
 void manager_recheck_journal(Manager *m);
 
 void manager_set_show_status(Manager *m, bool b);
 void manager_recheck_journal(Manager *m);
 
 void manager_set_show_status(Manager *m, bool b);
-void manager_status_printf(Manager *m, const char *status, const char *format, ...);
+void manager_status_printf(Manager *m, bool ephemeral, const char *status, const char *format, ...);
 
 void watch_init(Watch *w);
 
 void watch_init(Watch *w);
index f5adedc531a2521f46924cda1619df5af5463055..cc415894a54cd1f0f62b8b5c22365ea03ac55c5a 100644 (file)
@@ -2859,12 +2859,13 @@ cpu_set_t* cpu_set_malloc(unsigned *ncpus) {
         }
 }
 
         }
 }
 
-int status_vprintf(const char *status, bool ellipse, const char *format, va_list ap) {
+int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char *format, va_list ap) {
         static const char status_indent[] = "         "; /* "[" STATUS "] " */
         _cleanup_free_ char *s = NULL;
         _cleanup_close_ int fd = -1;
         static const char status_indent[] = "         "; /* "[" STATUS "] " */
         _cleanup_free_ char *s = NULL;
         _cleanup_close_ int fd = -1;
-        struct iovec iovec[5];
+        struct iovec iovec[6];
         int n = 0;
         int n = 0;
+        static bool prev_ephemeral;
 
         assert(format);
 
 
         assert(format);
 
@@ -2902,6 +2903,10 @@ int status_vprintf(const char *status, bool ellipse, const char *format, va_list
 
         zero(iovec);
 
 
         zero(iovec);
 
+        if (prev_ephemeral)
+                IOVEC_SET_STRING(iovec[n++], "\r" ANSI_ERASE_TO_END_OF_LINE);
+        prev_ephemeral = ephemeral;
+
         if (status) {
                 if (!isempty(status)) {
                         IOVEC_SET_STRING(iovec[n++], "[");
         if (status) {
                 if (!isempty(status)) {
                         IOVEC_SET_STRING(iovec[n++], "[");
@@ -2912,7 +2917,8 @@ int status_vprintf(const char *status, bool ellipse, const char *format, va_list
         }
 
         IOVEC_SET_STRING(iovec[n++], s);
         }
 
         IOVEC_SET_STRING(iovec[n++], s);
-        IOVEC_SET_STRING(iovec[n++], "\n");
+        if (!ephemeral)
+                IOVEC_SET_STRING(iovec[n++], "\n");
 
         if (writev(fd, iovec, n) < 0)
                 return -errno;
 
         if (writev(fd, iovec, n) < 0)
                 return -errno;
@@ -2920,14 +2926,14 @@ int status_vprintf(const char *status, bool ellipse, const char *format, va_list
         return 0;
 }
 
         return 0;
 }
 
-int status_printf(const char *status, bool ellipse, const char *format, ...) {
+int status_printf(const char *status, bool ellipse, bool ephemeral, const char *format, ...) {
         va_list ap;
         int r;
 
         assert(format);
 
         va_start(ap, format);
         va_list ap;
         int r;
 
         assert(format);
 
         va_start(ap, format);
-        r = status_vprintf(status, ellipse, format, ap);
+        r = status_vprintf(status, ellipse, ephemeral, format, ap);
         va_end(ap);
 
         return r;
         va_end(ap);
 
         return r;
index 19cc36af843dd622bdb2a5aad80d57e07cf8342b..f8957bca4265e9901fddf88d76a3bc9c5dc0cd08 100644 (file)
@@ -59,6 +59,7 @@ union dirent_storage {
 #define ANSI_HIGHLIGHT_GREEN_ON "\x1B[1;32m"
 #define ANSI_HIGHLIGHT_YELLOW_ON "\x1B[1;33m"
 #define ANSI_HIGHLIGHT_OFF "\x1B[0m"
 #define ANSI_HIGHLIGHT_GREEN_ON "\x1B[1;32m"
 #define ANSI_HIGHLIGHT_YELLOW_ON "\x1B[1;33m"
 #define ANSI_HIGHLIGHT_OFF "\x1B[0m"
+#define ANSI_ERASE_TO_END_OF_LINE "\x1B[K"
 
 size_t page_size(void);
 #define PAGE_ALIGN(l) ALIGN_TO((l), page_size())
 
 size_t page_size(void);
 #define PAGE_ALIGN(l) ALIGN_TO((l), page_size())
@@ -354,8 +355,8 @@ int pipe_eof(int fd);
 
 cpu_set_t* cpu_set_malloc(unsigned *ncpus);
 
 
 cpu_set_t* cpu_set_malloc(unsigned *ncpus);
 
-int status_vprintf(const char *status, bool ellipse, const char *format, va_list ap);
-int status_printf(const char *status, bool ellipse, const char *format, ...);
+int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char *format, va_list ap);
+int status_printf(const char *status, bool ellipse, bool ephemeral, const char *format, ...);
 int status_welcome(void);
 
 int fd_columns(int fd);
 int status_welcome(void);
 
 int fd_columns(int fd);