--- a/src/libeinfo/einfo.h +++ a/src/libeinfo/einfo.h @@ -140,5 +140,8 @@ void eoutdentv(void); /*! @brief Prefix each einfo line with something */ void eprefix(const char * EINFO_RESTRICT); +/*! @brief toggles between left-side and right-sided eend output */ +void eleft(bool); + __END_DECLS #endif --- a/src/libeinfo/einfo.map +++ a/src/libeinfo/einfo.map @@ -29,7 +29,7 @@ global: eindentv; eoutdentv; eprefix; - + eleft; local: *; }; --- a/src/libeinfo/libeinfo.c +++ a/src/libeinfo/libeinfo.c @@ -73,6 +73,7 @@ hidden_proto(elog) hidden_proto(eoutdent) hidden_proto(eoutdentv) hidden_proto(eprefix) +hidden_proto(eleft) hidden_proto(ewarn) hidden_proto(ewarnn) hidden_proto(ewarnv) @@ -118,6 +119,9 @@ hidden_proto(ewendv) /* A pointer to a string to prefix to einfo/ewarn/eerror messages */ static const char *_eprefix = NULL; +/* A bool for toggling left (true) and right-sided (false) eend */ +static bool _eleft = false; + /* Buffers and structures to hold the final colours */ static char ebuffer[100]; struct ecolor { @@ -525,6 +529,13 @@ eprefix(const char *EINFO_RESTRICT prefix) } hidden_def(eprefix) +void +eleft(bool eleft) +{ + _eleft=eleft; +} +hidden_def(eleft) + static void EINFO_PRINTF(2, 0) elogv(int level, const char *EINFO_RESTRICT fmt, va_list ap) { @@ -819,9 +830,15 @@ _eend(FILE * EINFO_RESTRICT fp, int col, ECOLOR color, const char *msg) cols--; if (cols > 0 && colour_terminal(fp)) { - fprintf(fp, "%s%s %s[%s %s %s]%s\n", up, tgoto(goto_column, 0, cols), + if (_eleft) { + fprintf(fp, "%s%s %s[%s %s %s]%s\n", up, tgoto(goto_column, 0, 0), ecolor(ECOLOR_BRACKET), ecolor(color), msg, ecolor(ECOLOR_BRACKET), ecolor(ECOLOR_NORMAL)); + } else { + fprintf(fp, "%s%s %s[%s %s %s]%s\n", up, tgoto(goto_column, 0, cols), + ecolor(ECOLOR_BRACKET), ecolor(color), msg, + ecolor(ECOLOR_BRACKET), ecolor(ECOLOR_NORMAL)); + } } else { if (col > 0) for (i = 0; i < cols - col; i++) --- a/src/rc/rc-status.c +++ a/src/rc/rc-status.c @@ -47,6 +47,8 @@ static RC_STRINGLIST *types; static RC_STRINGLIST *levels, *services, *tmp, *alist; static RC_STRINGLIST *sservices, *nservices, *needsme; +bool left = false; + bool _rc_can_find_pids(void) { @@ -95,7 +97,14 @@ static void print_service(const char *service) { char status[10]; - int cols = printf(" %s", service); + int cols; + if (left && isatty(fileno(stdout))) + { + /* hardcoded width, should be fixed */ + cols = printf(" %s", service); + } else { + cols = printf("%s", service); + } const char *c = ecolor(ECOLOR_GOOD); RC_SERVICE state = rc_service_state(service); ECOLOR color = ECOLOR_BAD; @@ -195,7 +204,7 @@ print_stacked_services(const char *runlevel) #define usagestring "" \ "Usage: rc-status [options] ...\n" \ " or: rc-status [options] [-a | -c | -l | -r | -s | -u]" -#define getoptstring "aclrsu" getoptstring_COMMON +#define getoptstring "xaclrsu" getoptstring_COMMON static const struct option longopts[] = { {"all", 0, NULL, 'a'}, {"crashed", 0, NULL, 'c'}, @@ -203,6 +212,7 @@ static const struct option longopts[] = { {"runlevel", 0, NULL, 'r'}, {"servicelist", 0, NULL, 's'}, {"unused", 0, NULL, 'u'}, + {"leftaligned", 0, NULL, 'x'}, longopts_COMMON }; static const char * const longopts_help[] = { @@ -212,6 +222,7 @@ static const char * const longopts_help[] = { "Show the name of the current runlevel", "Show service list", "Show services not assigned to any runlevel", + "Show output left-aligned", longopts_help_COMMON }; #include "_usage.c" @@ -229,6 +240,9 @@ rc_status(int argc, char **argv) while ((opt = getopt_long(argc, argv, getoptstring, longopts, (int *) 0)) != -1) switch (opt) { + case 'x': + left = true; + break; case 'a': aflag++; levels = rc_runlevel_list(); @@ -277,6 +291,10 @@ rc_status(int argc, char **argv) case_RC_COMMON_GETOPT } + // alignment stuff + if (left) + eleft(true); + if (!levels) levels = rc_stringlist_new(); opt = (optind < argc) ? 0 : 1;