[systemd-commits] src/login src/shared

Michal Schmidt michich at kemper.freedesktop.org
Mon Nov 12 13:32:42 PST 2012


 src/login/sysfs-show.c   |   10 +++++-----
 src/shared/cgroup-show.c |   14 +++++++-------
 src/shared/util.c        |   16 ++++++++--------
 src/shared/util.h        |    6 +++---
 4 files changed, 23 insertions(+), 23 deletions(-)

New commits:
commit 45a5ff0de744bc73a0695e61f749ee983ef97b64
Author: Michal Schmidt <mschmidt at redhat.com>
Date:   Mon Nov 12 22:27:48 2012 +0100

    util: nicer tree drawings
    
    Draw trees more similar to pstree/findmnt/lsblk/...

diff --git a/src/login/sysfs-show.c b/src/login/sysfs-show.c
index 172c75d..d113ec3 100644
--- a/src/login/sysfs-show.c
+++ b/src/login/sysfs-show.c
@@ -105,8 +105,8 @@ static int show_sysfs_one(
                 }
 
                 k = ellipsize(sysfs, n_columns, 20);
-                printf("%s%s %s\n", prefix, draw_special_char(lookahead ? DRAW_BOX_VERT_AND_RIGHT : DRAW_BOX_UP_AND_RIGHT),
-                                    k ? k : sysfs);
+                printf("%s%s%s\n", prefix, draw_special_char(lookahead ? DRAW_TREE_BRANCH : DRAW_TREE_RIGHT),
+                                   k ? k : sysfs);
                 free(k);
 
                 if (asprintf(&l,
@@ -118,8 +118,8 @@ static int show_sysfs_one(
                 }
 
                 k = ellipsize(l, n_columns, 70);
-                printf("%s%s %s\n", prefix, lookahead ? draw_special_char(DRAW_BOX_VERT) : " ",
-                                    k ? k : l);
+                printf("%s%s%s\n", prefix, lookahead ? draw_special_char(DRAW_TREE_VERT) : "  ",
+                                   k ? k : l);
                 free(k);
                 free(l);
 
@@ -127,7 +127,7 @@ static int show_sysfs_one(
                 if (*item) {
                         char *p;
 
-                        p = strjoin(prefix, lookahead ? draw_special_char(DRAW_BOX_VERT) : " ", " ", NULL);
+                        p = strappend(prefix, lookahead ? draw_special_char(DRAW_TREE_VERT) : "  ");
                         show_sysfs_one(udev, seat, item, sysfs, p ? p : prefix, n_columns - 2);
                         free(p);
                 }
diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c
index 69fe7fc..437d097 100644
--- a/src/shared/cgroup-show.c
+++ b/src/shared/cgroup-show.c
@@ -86,10 +86,10 @@ static void show_pid_array(int pids[], unsigned n_pids, const char *prefix, unsi
 
                 get_process_cmdline(pids[i], n_columns, true, &t);
 
-                printf("%s%s %*lu %s\n",
+                printf("%s%s%*lu %s\n",
                        prefix,
                        draw_special_char(extra ? DRAW_TRIANGULAR_BULLET :
-                                         ((more || i < n_pids-1) ? DRAW_BOX_VERT_AND_RIGHT : DRAW_BOX_UP_AND_RIGHT)),
+                                         ((more || i < n_pids-1) ? DRAW_TREE_BRANCH : DRAW_TREE_RIGHT)),
                        pid_width,
                        (unsigned long) pids[i],
                        strna(t));
@@ -208,11 +208,11 @@ int show_cgroup_by_path(const char *path, const char *prefix, unsigned n_columns
                 }
 
                 if (last) {
-                        printf("%s%s %s\n", prefix, draw_special_char(DRAW_BOX_VERT_AND_RIGHT),
-                                            path_get_file_name(last));
+                        printf("%s%s%s\n", prefix, draw_special_char(DRAW_TREE_BRANCH),
+                                           path_get_file_name(last));
 
                         if (!p1) {
-                                p1 = strjoin(prefix, draw_special_char(DRAW_BOX_VERT), " ", NULL);
+                                p1 = strappend(prefix, draw_special_char(DRAW_TREE_VERT));
                                 if (!p1) {
                                         free(k);
                                         r = -ENOMEM;
@@ -234,8 +234,8 @@ int show_cgroup_by_path(const char *path, const char *prefix, unsigned n_columns
                 show_cgroup_one_by_path(path, prefix, n_columns, !!last, kernel_threads);
 
         if (last) {
-                printf("%s%s %s\n", prefix, draw_special_char(DRAW_BOX_UP_AND_RIGHT),
-                                    path_get_file_name(last));
+                printf("%s%s%s\n", prefix, draw_special_char(DRAW_TREE_RIGHT),
+                                   path_get_file_name(last));
 
                 if (!p2) {
                         p2 = strappend(prefix, "  ");
diff --git a/src/shared/util.c b/src/shared/util.c
index 9983695..5a326ec 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -6148,16 +6148,16 @@ out:
 const char *draw_special_char(DrawSpecialChar ch) {
         static const char *draw_table[2][_DRAW_SPECIAL_CHAR_MAX] = {
                 /* UTF-8 */ {
-                        [DRAW_BOX_VERT]           = "\342\224\202", /* │ */
-                        [DRAW_BOX_VERT_AND_RIGHT] = "\342\224\234", /* ├ */
-                        [DRAW_BOX_UP_AND_RIGHT]   = "\342\224\224", /* â”” */
-                        [DRAW_TRIANGULAR_BULLET]  = "\342\200\243", /* ‣ */
+                        [DRAW_TREE_VERT]          = "\342\224\202 ",            /* │  */
+                        [DRAW_TREE_BRANCH]        = "\342\224\234\342\224\200", /* ├─ */
+                        [DRAW_TREE_RIGHT]         = "\342\224\224\342\224\200", /* └─ */
+                        [DRAW_TRIANGULAR_BULLET]  = "\342\200\243 ",            /* ‣  */
                 },
                 /* ASCII fallback */ {
-                        [DRAW_BOX_VERT] = "|",
-                        [DRAW_BOX_VERT_AND_RIGHT] = "+",
-                        [DRAW_BOX_UP_AND_RIGHT]   = "\\",
-                        [DRAW_TRIANGULAR_BULLET]  = ">",
+                        [DRAW_TREE_VERT]          = "| ",
+                        [DRAW_TREE_BRANCH]        = "|-",
+                        [DRAW_TREE_RIGHT]         = "`-",
+                        [DRAW_TRIANGULAR_BULLET]  = "> ",
                 }
         };
 
diff --git a/src/shared/util.h b/src/shared/util.h
index 99972cc..c2bed2a 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -604,9 +604,9 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
 bool is_locale_utf8(void);
 
 typedef enum DrawSpecialChar {
-        DRAW_BOX_VERT,
-        DRAW_BOX_VERT_AND_RIGHT,
-        DRAW_BOX_UP_AND_RIGHT,
+        DRAW_TREE_VERT,
+        DRAW_TREE_BRANCH,
+        DRAW_TREE_RIGHT,
         DRAW_TRIANGULAR_BULLET,
         _DRAW_SPECIAL_CHAR_MAX
 } DrawSpecialChar;



More information about the systemd-commits mailing list