aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/w/w.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/w/w.c')
-rw-r--r--usr.bin/w/w.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/usr.bin/w/w.c b/usr.bin/w/w.c
index ac1df96077d3..502bf5a412b9 100644
--- a/usr.bin/w/w.c
+++ b/usr.bin/w/w.c
@@ -473,7 +473,7 @@ main(int argc, char *argv[])
static void
pr_header(time_t *nowp, int nusers)
{
- char buf[64];
+ char buf[64], *s, *e;
struct sbuf upbuf;
double avenrun[3];
struct timespec tp;
@@ -484,8 +484,15 @@ pr_header(time_t *nowp, int nusers)
* Print time of day.
*/
if (strftime(buf, sizeof(buf),
- use_ampm ? "%l:%M%p" : "%k:%M", localtime(nowp)) != 0)
- xo_emit("{:time-of-day/%s} ", buf);
+ use_ampm ? "%l:%M%p" : "%k:%M", localtime(nowp)) != 0) {
+ s = buf;
+ if (xo_get_style(NULL) != XO_STYLE_TEXT) {
+ /* trim leading whitespace */
+ while (isspace((unsigned char)*s))
+ s++;
+ }
+ xo_emit("{:time-of-day/%s} ", s);
+ }
/*
* Print how long system has been up.
*/
@@ -516,21 +523,31 @@ pr_header(time_t *nowp, int nusers)
if (days > 0)
sbuf_printf(&upbuf, " %ld day%s,",
- days, days > 1 ? "s" : "");
+ days, days > 1 ? "s" : "");
if (hrs > 0 && mins > 0)
sbuf_printf(&upbuf, " %2ld:%02ld,", hrs, mins);
else if (hrs > 0)
sbuf_printf(&upbuf, " %ld hr%s,",
- hrs, hrs > 1 ? "s" : "");
+ hrs, hrs > 1 ? "s" : "");
else if (mins > 0)
sbuf_printf(&upbuf, " %ld min%s,",
- mins, mins > 1 ? "s" : "");
+ mins, mins > 1 ? "s" : "");
else
sbuf_printf(&upbuf, " %ld sec%s,",
- secs, secs > 1 ? "s" : "");
+ secs, secs > 1 ? "s" : "");
if (sbuf_finish(&upbuf) != 0)
xo_err(1, "Could not generate output");
- xo_emit("{:uptime-human/%s}", sbuf_data(&upbuf));
+ s = sbuf_data(&upbuf);
+ if (xo_get_style(NULL) != XO_STYLE_TEXT) {
+ e = s + sbuf_len(&upbuf) - 1;
+ /* trim leading whitespace */
+ while (isspace((unsigned char)*s))
+ s++;
+ /* trim trailing comma */
+ if (e > s && *e == ',')
+ *e = '\0';
+ }
+ xo_emit("{:uptime-human/%s}", s);
sbuf_delete(&upbuf);
}