LIBXO(3)
β¨ LIBXO(3) β¨
okay bestie, so this page is literally the LIBXO(3) entry from the Library Functions Manual, and it's all about xo_options β the common options that every libxo-based command gets to use. pull up a chair, grab a boba, we're doing this π
π NAME π
xo_optionsβ common options for libxo-based commands
π DESCRIPTION π
so libxo is that girl: it lets you render your data into a bunch of different output styles β text, XML, JSON, HTML, the whole wardrobe. π
and it uses command line options to trigger which rendering behavior you want.
Options are recognised in three forms:
--libxo <options>--libxo=<options>--libxo:<brief-options>
The first two forms accept a comma-separated set of words (detailed below π), while the third form accepts a set of letters (also below π). The triggered functionality is identical. fr fr, same vibes, different spelling.
Here's the full menu of long options and what they do:
colorβ enable colors/effects for display styles (TEXT, HTML)flushβ flush after each emit callflush-lineβ flush each line of outputhtmlβ emit HTML outputindent=xxβ set the indentation levelinfoβ add info attributes (HTML)jsonβ emit JSON outputkeysβ emit the key attribute for keys (XML)log-gettextβ log (via stderr) eachgettext(3)string lookuplog-syslogβ log (via stderr) each syslog message (viaxo_syslog)mapβ map between tag namesmap-fileβ use a file to specify mapping between tag namesno-humanizeβ ignore the{h:}modifier (TEXT, HTML)no-localeβ do not initialize the locale settingno-retainβ prevent retaining formatting informationprettyβ emit pretty-printed outputretainβ force retaining formatting informationtextβ emit TEXT outputunderscoresβ replace XML-friendly dashes with JSON-friendly underscoresunitsβ add the'units'(XML) or'data-units(HTML) attributewarnβ emit warnings when libxo detects bad callswarn-xmlβ emit warnings in XMLxmlβ emit XML outputxpathβ add XPath expressions (HTML)
π§ the brief options, aka the short girls π§
The brief options are a set of single-letter aliases for the longer terms, used as a single string. no spaces, no commas, just vibes:
cβ (no equivalent token given, bestie, that's literally what the page says)fβflushFβflush-lineHβhtmlIβinfoi<num>βindent=<num>Jβjsonkβkeysnβno-humanizePβprettyTβtextUβunitsuβunderscoreWβwarnXβxmlxβxpath
Most of these options are simple and direct, but some of them need extra details, and honestly same:
flush-lineperforms line buffering, even when the output is not directed to a TTY device.infogenerates additional data for HTML, encoded in attributes using names that start with"data-".keysadds a"key"attribute for XML output to indicate that a leaf is an identifier for the list member.mapandmap-fileare described below. (spoiler alert π«Ά)no-humanizeavoids "humanizing" numeric output (seehumanize_number(3)for details).no-localeinstructs libxo to avoid translating output to the current locale.no-retaindisables the ability of libxo to internally retain "compiled" information about formatting strings.underscorescan be used with JSON output to change XML-friendly names with dashes into JSON-friendly names with underscores.warnallows libxo to emit warnings on stderr when application code makes incorrect calls.warn-xmlcauses those warnings to be placed in XML inside the output.
π¨ Color Mapping π¨
The colors option takes a value that is a set of mappings from the pre-defined set of colors to new foreground and background colors. The value is a series of "fg/bg" values, separated by a "+".
Each pair of "fg/bg" values gives the colors to which a basic color is mapped when used as a foreground or background color. The order of the mappings is:
- black
- red
- green
- yellow
- blue
- magenta
- cyan
- white
Pairs may be skipped, leaving them mapped as normal β same for missing pairs or single colors. π
For example, consider the following xo_emit call:
xo_emit("{C:fg-red,bg-green}Merry XMas!!{C:}0);
To turn all colored output to red-on-blue, use eight pairs of "red/blue" mappings separated by plus signs ("+"):
--libxo colors=red/blue+red/blue+red/blue+red/blue+ red/blue+red/blue+red/blue+red/blue
To turn the red-on-green text to magenta-on-cyan, give a "magenta" foreground value for red (the second mapping) and a "cyan" background to green (the third mapping):
--libxo colors=+magenta+/cyan
Now consider the common situation where blue output looks unreadable on a terminal session with a black background π. To turn both "blue" foreground and background output to "yellow", give only the fifth mapping, skipping the first four mappings with bare plus signs ("+"):
--libxo colors=++++yellow/yellow
π·οΈ Tag Mapping π·οΈ
libxo supports mapping between tag names, for scenarios where the tags need to make specific values. For example, the "user" tag might be needed as the "owner" tag. libxo can perform this one-to-one tag replacement. slay.
β οΈ Note that libxo does not perform more complex transformations; languages such as XSLT or SLAX should be used when something more than simple one-to-one replacement is required.
Mapping can be specified using the map and map-file options. The map option accepts one or more mappings, in the format "old=new", separated by colons:
--libxo map:one=red,map:two=blue
This example would turn:
<one>fish</one>
<two>fish</two>
into:
<red>fish</red>
<blue>fish</blue>
In another example, the command-line options:
--libxo map:user=owner:name=file:size=bytes:modify-time=time
would turn:
<entry>
<name>xx-00000009</name>
<user>phil</user>
<size>12345</size>
<modify-time value="1644355825">1644355825</modify-time>
</entry>
into:
<entry>
<file>xx-00000009</file>
<owner>phil</owner>
<bytes>12345</bytes>
<time value="1644355825">1644355825</time>
</entry>
The map-file option allows the mappings to be placed into a file, one per line:
--libxo map-file=foo.map
where "foo.map" might contain:
# comments are supported, white space is ignored
user = owner
name=file
# blank lines are allowed
size = bytes
modify-time= time
This untidy example demonstrates the flexibility in the libxo mapping files. (not me judging the formatting π)
If the filename given with the map-file option contains no slashes ("/") and such a file does not exist in the current working directory, libxo will look for the file in the "map" subdirectory of the system "share" directory, typically /usr/share/libxo/map/.
π§© Encoders π§©
In addition to the four "built-in" formats, libxo supports an extensible mechanism for adding encoders. These are activated using the encoder keyword::
--libxo encoder=cbor
The encoder can include encoder-specific options, separated by either colons (":") or plus signs ("+"):
--libxo encoder=csv+path=filesystem+leaf=name+no-header
--libxo encoder=csv:path=filesystem:leaf=name:no-header
For brevity, the string "@" can be used in place of the string "encoder=":
df --libxo @csv:no-header
π₯ EXAMPLES π₯
The following are three example invocations of ps(1):
ps --libxo json,pretty,warn -ux
ps --libxo=xml -lg
ps --libxo:Hxc 1
π SEE ALSO π
π HISTORY π
The libxo library first appeared in FreeBSD 11.0.
π AUTHORS π
libxo was written by Phil Shafer <phil@freebsd.org>.
π ADDITIONAL DOCUMENTATION π
FreeBSD uses libxo version 1.7.5. Complete documentation can be found on github:
https://juniper.github.io/libxo/1.7.5/html/index.html
libxo lives on github as:
https://github.com/Juniper/libxo
The latest release of libxo is available at:
https://github.com/Juniper/libxo/releases
π HISTORY π
The libxo library was added in FreeBSD 11.0.
βοΈ AUTHOR βοΈ
Phil Shafer
aaaand that's the whole page, bestie π«Ά this one came from Debian, dated May 11, 2017, and it's the LIBXO(3) manual β go forth and --libxo responsibly, mwah πβ¨
π¦ where this page comes from
- epel 9: libxo 1.7.5-1.el9 Β· LicenseRef-Callaway-BSD
- fedora 43: libxo 1.7.5-2.fc43 Β· LicenseRef-Callaway-BSD
- fedora 43: libxo 1.7.5-2.fc43 Β· LicenseRef-Callaway-BSD
- fedora 44: libxo 1.7.5-3.fc44 Β· LicenseRef-Callaway-BSD
- fedora 44: libxo 1.7.5-3.fc44 Β· LicenseRef-Callaway-BSD
- nixpkgs unstable: libxo 1.7.5
- Copyright (c) 2014-2017, Juniper Networks, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms