Bug 246514 - w(1) truncates output before passing to libxo
Summary: w(1) truncates output before passing to libxo
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL: https://reviews.freebsd.org/D25013
Keywords: patch
Depends on:
Blocks:
 
Reported: 2020-05-16 20:26 UTC by Eirik Oeverby
Modified: 2020-05-27 14:44 UTC (History)
5 users (show)

See Also:


Attachments
don't truncate argument list if --libxo was specified (3.29 KB, patch)
2020-05-19 19:35 UTC, Yuri Pankov
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eirik Oeverby 2020-05-16 20:26:31 UTC
When calling w(1) as
 w --libxo=json
or any other output format, values - particularly the WHAT column - gets truncated by the terminal size at the time of invocation. This is particularly troublesome when called in a non-terminal session e.g. from cron(8), as it will then default to 79 characters.

It could be argued that unless the output is a terminal, it should not make any assumptions about or adaptations to terminal size at all. For example, w|head should not truncate. However, changing this behaviour might be a violation of the POLA.

Truncating output prior to passing to libxo shoul, however, probably be considered a bug.
Comment 1 Conrad Meyer freebsd_committer 2020-05-17 18:50:01 UTC
> For example, w|head should not truncate.

Good luck.  :-)  I've never been able to convince anyone of that.
Comment 2 Eirik Oeverby 2020-05-19 17:55:41 UTC
If nobody is working (or plans to work) on this, I'll ask one of our people to have a crack at it. I guess it won't make it to 11.4 anyway..
Comment 3 Yuri Pankov freebsd_committer 2020-05-19 18:00:19 UTC
(In reply to Eirik Oeverby from comment #2)
The code change here is easy and obvious, getting it integrated however isn't, as Conrad mentioned.
Comment 4 Eirik Oeverby 2020-05-19 18:01:19 UTC
(In reply to Yuri Pankov from comment #3)

Even if _only_ the --libxo case is fixed?
Comment 5 Kyle Evans freebsd_committer 2020-05-19 18:02:34 UTC
(In reply to Eirik Oeverby from comment #4)

I'd be willing to take any heat for committing a patch to fix just the --libxo case.
Comment 6 Ed Maste freebsd_committer 2020-05-19 18:44:01 UTC
I think it's quite feasible to get the libxo case fixed for 11.4.
Comment 7 Yuri Pankov freebsd_committer 2020-05-19 19:35:22 UTC
Created attachment 214657 [details]
don't truncate argument list if --libxo was specified

(I'm on very limited internet connection at the moment so attaching the patch I came up with here.)

Proposed patch adding a xo_libxo_set() to libxo to let consumers know if --libxo was specified in the command line arguments passed to xo_parse_args(), and use it in w to decide if we should truncate the argument list.
Comment 8 Phil Shafer freebsd_committer 2020-05-27 14:44:32 UTC
Just knowing that the "--libxo"  was used is not sufficient, since there are options that should not affect output (e.g. color, no-humanize, warn).

Can you describe more exactly when you want to avoid truncation?  I'm guessing you want this for the "encoding" output styles (XML, JSON) and not text, but  do you want to truncate HTML output?

Maybe the test you are needing is just "if (xo_get_style(NULL) == XO_STYLE_TEXT)"?

Thanks,
 Phil