From 9a56edb37b9a01e36a2fdf9d441b3bbded933878 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Wed, 22 Nov 2023 07:01:50 +0900
Subject: [PATCH] pid1: move draw_cylong() to pretty-print.[ch]

(cherry picked from commit d61a4dbba93a2b34dc85522e432c30ca152d4dda)
(cherry picked from commit f76318f2c9d1e0122640f378043427d0d200a008)
(cherry picked from commit adbcdc481cac36b6d50225bae6cb7bc3b16b32e9)

Conflict:code context adaptation and add missing header file
Reference:https://github.com/systemd/systemd/commit/d61a4dbba93a2b34dc85522e432c30ca152d4dda
---
 src/core/manager.c        | 39 +--------------------------------------
 src/shared/pretty-print.c | 36 ++++++++++++++++++++++++++++++++++++
 src/shared/pretty-print.h |  4 ++++
 3 files changed, 41 insertions(+), 38 deletions(-)

diff --git a/src/core/manager.c b/src/core/manager.c
index 6357d3b625..7446444add 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -65,6 +65,7 @@
 #include "parse-util.h"
 #include "path-lookup.h"
 #include "path-util.h"
+#include "pretty-print.h"
 #include "process-util.h"
 #include "ratelimit.h"
 #include "rlimit-util.h"
@@ -164,44 +165,6 @@ static void manager_watch_jobs_in_progress(Manager *m) {
         (void) sd_event_source_set_description(m->jobs_in_progress_event_source, "manager-jobs-in-progress");
 }
 
-#define CYLON_BUFFER_EXTRA (2*STRLEN(ANSI_RED) + STRLEN(ANSI_HIGHLIGHT_RED) + 2*STRLEN(ANSI_NORMAL))
-
-static void draw_cylon(char buffer[], size_t buflen, unsigned width, unsigned pos) {
-        char *p = buffer;
-
-        assert(buflen >= CYLON_BUFFER_EXTRA + width + 1);
-        assert(pos <= width+1); /* 0 or width+1 mean that the center light is behind the corner */
-
-        if (pos > 1) {
-                if (pos > 2)
-                        p = mempset(p, ' ', pos-2);
-                if (log_get_show_color())
-                        p = stpcpy(p, ANSI_RED);
-                *p++ = '*';
-        }
-
-        if (pos > 0 && pos <= width) {
-                if (log_get_show_color())
-                        p = stpcpy(p, ANSI_HIGHLIGHT_RED);
-                *p++ = '*';
-        }
-
-        if (log_get_show_color())
-                p = stpcpy(p, ANSI_NORMAL);
-
-        if (pos < width) {
-                if (log_get_show_color())
-                        p = stpcpy(p, ANSI_RED);
-                *p++ = '*';
-                if (pos < width-1)
-                        p = mempset(p, ' ', width-1-pos);
-                if (log_get_show_color())
-                        p = stpcpy(p, ANSI_NORMAL);
-        }
-
-        *p = '\0';
-}
-
 static void manager_flip_auto_status(Manager *m, bool enable, const char *reason) {
         assert(m);
 
diff --git a/src/shared/pretty-print.c b/src/shared/pretty-print.c
index 98619c25d4..2d52ed3d83 100644
--- a/src/shared/pretty-print.c
+++ b/src/shared/pretty-print.c
@@ -18,6 +18,43 @@
 #include "terminal-util.h"
 #include "util.h"
+#include "memory-util.h"
+
+void draw_cylon(char buffer[], size_t buflen, unsigned width, unsigned pos) {
+        char *p = buffer;
+
+        assert(buflen >= CYLON_BUFFER_EXTRA + width + 1);
+        assert(pos <= width+1); /* 0 or width+1 mean that the center light is behind the corner */
+
+        if (pos > 1) {
+                if (pos > 2)
+                        p = mempset(p, ' ', pos-2);
+                if (log_get_show_color())
+                        p = stpcpy(p, ANSI_RED);
+                *p++ = '*';
+        }
+
+        if (pos > 0 && pos <= width) {
+                if (log_get_show_color())
+                        p = stpcpy(p, ANSI_HIGHLIGHT_RED);
+                *p++ = '*';
+        }
+
+        if (log_get_show_color())
+                p = stpcpy(p, ANSI_NORMAL);
+
+        if (pos < width) {
+                if (log_get_show_color())
+                        p = stpcpy(p, ANSI_RED);
+                *p++ = '*';
+                if (pos < width-1)
+                        p = mempset(p, ' ', width-1-pos);
+                if (log_get_show_color())
+                        p = stpcpy(p, ANSI_NORMAL);
+        }
+
+        *p = '\0';
+}

 bool urlify_enabled(void) {
 #if ENABLE_URLIFY
         static int cached_urlify_enabled = -1;
diff --git a/src/shared/pretty-print.h b/src/shared/pretty-print.h
index 45644da67d..cf28860bb8 100644
--- a/src/shared/pretty-print.h
+++ b/src/shared/pretty-print.h
@@ -4,6 +4,12 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include "terminal-util.h"
+
+#define CYLON_BUFFER_EXTRA (2*STRLEN(ANSI_RED) + STRLEN(ANSI_HIGHLIGHT_RED) + 2*STRLEN(ANSI_NORMAL))
+
+void draw_cylon(char buffer[], size_t buflen, unsigned width, unsigned pos);
+
 void print_separator(void);
 
 int file_url_from_path(const char *path, char **ret);
-- 
2.33.0

