Make the prefix length dynamic
This commit is contained in:
parent
090090328a
commit
809b5286b6
@ -299,7 +299,6 @@ static void cleanup (void)
|
|||||||
|
|
||||||
static int write_prefix (int fd, const char *buffer, size_t bytes, bool *prefixed) {
|
static int write_prefix (int fd, const char *buffer, size_t bytes, bool *prefixed) {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int j;
|
|
||||||
const char *ec;
|
const char *ec;
|
||||||
const char *ec_normal = ecolor (ecolor_normal);
|
const char *ec_normal = ecolor (ecolor_normal);
|
||||||
ssize_t ret = 0;
|
ssize_t ret = 0;
|
||||||
@ -316,11 +315,9 @@ static int write_prefix (int fd, const char *buffer, size_t bytes, bool *prefixe
|
|||||||
|
|
||||||
if (! *prefixed) {
|
if (! *prefixed) {
|
||||||
ret += write (fd, ec, strlen (ec));
|
ret += write (fd, ec, strlen (ec));
|
||||||
ret += write (fd, applet, strlen (applet));
|
ret += write (fd, prefix, strlen (prefix));
|
||||||
for (j = strlen (applet); j < 11; j++)
|
|
||||||
ret += write (fd, " ", 1);
|
|
||||||
ret += write (fd, ec_normal, strlen (ec_normal));
|
ret += write (fd, ec_normal, strlen (ec_normal));
|
||||||
ret += write (fd, " |", 2);
|
ret += write (fd, "|", 2);
|
||||||
*prefixed = true;
|
*prefixed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1082,11 +1079,23 @@ int main (int argc, char **argv)
|
|||||||
|
|
||||||
/* eprefix is kinda klunky, but it works for our purposes */
|
/* eprefix is kinda klunky, but it works for our purposes */
|
||||||
if (rc_is_env ("RC_PREFIX", "yes")) {
|
if (rc_is_env ("RC_PREFIX", "yes")) {
|
||||||
int l = strlen (applet);
|
int l = 0;
|
||||||
if (l < 13)
|
char *svc;
|
||||||
l = 13;
|
|
||||||
prefix = rc_xmalloc (sizeof (char *) * l);
|
/* Get the longest service name */
|
||||||
snprintf (prefix, l, "%s%s", applet, " ");
|
services = rc_services_in_runlevel (NULL);
|
||||||
|
STRLIST_FOREACH (services, svc, i) {
|
||||||
|
int ll = strlen (svc);
|
||||||
|
if (ll > l)
|
||||||
|
l = ll;
|
||||||
|
}
|
||||||
|
// rc_strlist_free (services);
|
||||||
|
|
||||||
|
svc = prefix = rc_xmalloc (sizeof (char *) * l);
|
||||||
|
svc += strlcpy (prefix, applet, l);
|
||||||
|
i = l - strlen (prefix);
|
||||||
|
memset (svc, ' ', i);
|
||||||
|
memset (svc + i, 0, 1);
|
||||||
eprefix (prefix);
|
eprefix (prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user