--- src/pstree.c +++ src/pstree.c 2009-05-11 13:32:34.749902293 +0200 @@ -60,6 +60,7 @@ extern const char *__progname; #define UTF_HD "\342\224\254" /* U+252C, Horizontal and down */ #define VT_BEG "\033(0\017" /* use graphic chars */ +#define VT_LEN 4 #define VT_END "\033(B" /* back to normal char set */ #define VT_V "x" /* see UTF definitions above */ #define VT_VR "t" @@ -220,6 +221,27 @@ out_string (const char *str) out_char (*str++); } +/* + * Only affects vt100 line drawing mode: Do not count the strlen of + * VT_BEG to prevent doing end-of-line way too early: + */ +static void +out_sym (const char *str) +{ + int seq = 0; + if (sym == &sym_vt100 && *str == '\033') { + seq = 1; + if (cur_x <= output_width || !trunc) + cur_x -= VT_LEN; + } + out_string(str); + if (seq) { + str = VT_END; + while (*str) + putchar (*str++); + } +} + static int out_int (int x) /* non-negative integers only */ @@ -431,7 +453,11 @@ dump_tree (PROC * current, int level, in { for (i = width[lvl] + 1; i; i--) out_char (' '); - out_string (lvl == level - 1 ? last ? sym->last_2 : sym->branch_2 : + /* + * Replace all three symbol-drawing calls with calls to out_sym() + * to handle VT100 line drawing sequences if VT100 mode is active: + */ + out_sym (lvl == level - 1 ? last ? sym->last_2 : sym->branch_2 : more[lvl + 1] ? sym->vert_2 : sym->empty_2); } if (rep < 2) @@ -543,7 +569,7 @@ dump_tree (PROC * current, int level, in width[level] = comm_len + cur_x - offset + add; if (cur_x >= output_width && trunc) { - out_string (sym->first_3); + out_sym (sym->first_3); out_string ("+"); out_newline (); } @@ -570,7 +596,7 @@ dump_tree (PROC * current, int level, in } if (first) { - out_string (next ? sym->first_3 : sym->single_3); + out_sym (next ? sym->first_3 : sym->single_3); first = 0; } dump_tree (walk->child, level + 1, count + 1,