XML Output: libxo - provide single API to output TXT, XML, JSON and HTML
Phil Shafer
phil at juniper.net
Thu Jul 31 09:19:01 UTC 2014
"Simon J. Gerraty" writes:
>w(1) sizes those strings based on its expectation of the width of the
>tty. That can obviously be fixed/improved - but involves exposing
>knowledge of the out format (or at least that it isn't TXT) to the
>application.
libxo allows the field description to carry two distinct format
descriptors, one for text/html and one for xml/json. The latter
defaults to the former:
xo_emit(" {:words/%7ju/%ju}", twordct);
For "w", this is does the right thing; in text mode, the command
string is truncated:
5:08AM up 27 days, 12:22, 11 user%s, load averages: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE WHAT
phil pts/1 76.182.32.73 05Jul14 - /usr/bin/perl /u/phil/bin/plum (
...
In XML mode, the command is not truncated.
<uptime-information>
<time-of-day> 5:09AM</time-of-day>
<uptime seconds="2377336">27 days</uptime>
<uptime>12:22</uptime>
<users>11</users>
<load-average-1>0.00</load-average-1>
<load-average-5>0.00</load-average-5>
<load-average-15>0.00</load-average-15>
<user-table>
<user-entry>
<user>phil</user>
<tty>pts/1</tty>
<from>76.182.32.73</from>
<login-time>05Jul14</login-time>
<idle> 1</idle>
<command>/usr/bin/perl /u/phil/bin/plum (perl5.12.4)</command>
</user-entry>
...
(Yes, I'm likely the only plum user left in the wild.)
Thanks,
Phil
More information about the freebsd-arch
mailing list