1983afe33SPhil Shafer 2983afe33SPhil Shafer.. index:: Field Roles 3983afe33SPhil Shafer.. _field-roles: 4983afe33SPhil Shafer 5983afe33SPhil ShaferField Roles 6983afe33SPhil Shafer~~~~~~~~~~~ 7983afe33SPhil Shafer 8983afe33SPhil ShaferField roles are optional, and indicate the role and formatting of the 9983afe33SPhil Shafercontent. The roles are listed below; only one role is permitted: 10983afe33SPhil Shafer 11983afe33SPhil Shafer === ============== ================================================= 12983afe33SPhil Shafer R Name Description 13983afe33SPhil Shafer === ============== ================================================= 14983afe33SPhil Shafer C color Field has color and effect controls 15983afe33SPhil Shafer D decoration Field is non-text (e.g., colon, comma) 16983afe33SPhil Shafer E error Field is an error message 17983afe33SPhil Shafer G gettext Call gettext(3) on the format string 18983afe33SPhil Shafer L label Field is text that prefixes a value 19983afe33SPhil Shafer N note Field is text that follows a value 20983afe33SPhil Shafer P padding Field is spaces needed for vertical alignment 21983afe33SPhil Shafer T title Field is a title value for headings 22983afe33SPhil Shafer U units Field is the units for the previous value field 23983afe33SPhil Shafer V value Field is the name of field (the default) 24983afe33SPhil Shafer W warning Field is a warning message 25983afe33SPhil Shafer [ start-anchor Begin a section of anchored variable-width text 26983afe33SPhil Shafer ] stop-anchor End a section of anchored variable-width text 27983afe33SPhil Shafer === ============== ================================================= 28983afe33SPhil Shafer 2976afb20cSPhil Shafer:: 3076afb20cSPhil Shafer 31983afe33SPhil Shafer EXAMPLE: 32983afe33SPhil Shafer xo_emit("{L:Free}{D::}{P: }{:free/%u} {U:Blocks}\n", 33983afe33SPhil Shafer free_blocks); 34983afe33SPhil Shafer 35983afe33SPhil ShaferWhen a role is not provided, the "*value*" role is used as the default. 36983afe33SPhil Shafer 37983afe33SPhil ShaferRoles and modifiers can also use more verbose names, when preceded by 38983afe33SPhil Shafera comma:: 39983afe33SPhil Shafer 40983afe33SPhil Shafer EXAMPLE: 41983afe33SPhil Shafer xo_emit("{,label:Free}{,decoration::}{,padding: }" 42983afe33SPhil Shafer "{,value:free/%u} {,units:Blocks}\n", 43983afe33SPhil Shafer free_blocks); 44983afe33SPhil Shafer 45983afe33SPhil Shafer.. index:: Field Roles; Color 46983afe33SPhil Shafer.. _color-role: 47983afe33SPhil Shafer 48983afe33SPhil ShaferThe Color Role ({C:}) 49983afe33SPhil Shafer+++++++++++++++++++++ 50983afe33SPhil Shafer 51983afe33SPhil ShaferColors and effects control how text values are displayed; they are 52983afe33SPhil Shaferused for display styles (TEXT and HTML):: 53983afe33SPhil Shafer 54983afe33SPhil Shafer xo_emit("{C:bold}{:value}{C:no-bold}\n", value); 55983afe33SPhil Shafer 56983afe33SPhil ShaferColors and effects remain in effect until modified by other "C"-role 57983afe33SPhil Shaferfields:: 58983afe33SPhil Shafer 59983afe33SPhil Shafer xo_emit("{C:bold}{C:inverse}both{C:no-bold}only inverse\n"); 60983afe33SPhil Shafer 61983afe33SPhil ShaferIf the content is empty, the "*reset*" action is performed:: 62983afe33SPhil Shafer 63983afe33SPhil Shafer xo_emit("{C:both,underline}{:value}{C:}\n", value); 64983afe33SPhil Shafer 65983afe33SPhil ShaferThe content should be a comma-separated list of zero or more colors or 66983afe33SPhil Shaferdisplay effects:: 67983afe33SPhil Shafer 68983afe33SPhil Shafer xo_emit("{C:bold,inverse}Ugly{C:no-bold,no-inverse}\n"); 69983afe33SPhil Shafer 70983afe33SPhil ShaferThe color content can be either static, when placed directly within 71983afe33SPhil Shaferthe field descriptor, or a printf-style format descriptor can be used, 72983afe33SPhil Shaferif preceded by a slash ("/"): 73983afe33SPhil Shafer 74983afe33SPhil Shafer xo_emit("{C:/%s%s}{:value}{C:}", need_bold ? "bold" : "", 75983afe33SPhil Shafer need_underline ? "underline" : "", value); 76983afe33SPhil Shafer 77983afe33SPhil ShaferColor names are prefixed with either "fg-" or "bg-" to change the 78983afe33SPhil Shaferforeground and background colors, respectively:: 79983afe33SPhil Shafer 80983afe33SPhil Shafer xo_emit("{C:/fg-%s,bg-%s}{Lwc:Cost}{:cost/%u}{C:reset}\n", 81983afe33SPhil Shafer fg_color, bg_color, cost); 82983afe33SPhil Shafer 83983afe33SPhil ShaferThe following table lists the supported effects: 84983afe33SPhil Shafer 85983afe33SPhil Shafer =============== ================================================= 86983afe33SPhil Shafer Name Description 87983afe33SPhil Shafer =============== ================================================= 88983afe33SPhil Shafer bg-XXXXX Change background color 89983afe33SPhil Shafer bold Start bold text effect 90983afe33SPhil Shafer fg-XXXXX Change foreground color 91983afe33SPhil Shafer inverse Start inverse (aka reverse) text effect 92983afe33SPhil Shafer no-bold Stop bold text effect 93983afe33SPhil Shafer no-inverse Stop inverse (aka reverse) text effect 94983afe33SPhil Shafer no-underline Stop underline text effect 95983afe33SPhil Shafer normal Reset effects (only) 96983afe33SPhil Shafer reset Reset colors and effects (restore defaults) 97983afe33SPhil Shafer underline Start underline text effect 98983afe33SPhil Shafer =============== ================================================= 99983afe33SPhil Shafer 100983afe33SPhil ShaferThe following color names are supported: 101983afe33SPhil Shafer 102983afe33SPhil Shafer ========= ============================================ 103983afe33SPhil Shafer Name Description 104983afe33SPhil Shafer ========= ============================================ 105983afe33SPhil Shafer black 106983afe33SPhil Shafer blue 107983afe33SPhil Shafer cyan 108983afe33SPhil Shafer default Default color for foreground or background 109983afe33SPhil Shafer green 110983afe33SPhil Shafer magenta 111983afe33SPhil Shafer red 112983afe33SPhil Shafer white 113983afe33SPhil Shafer yellow 114983afe33SPhil Shafer ========= ============================================ 115983afe33SPhil Shafer 116983afe33SPhil ShaferWhen using colors, the developer should remember that users will 117983afe33SPhil Shaferchange the foreground and background colors of terminal session 118983afe33SPhil Shaferaccording to their own tastes, so assuming that "blue" looks nice is 119983afe33SPhil Shafernever safe, and is a constant annoyance to your dear author. In 120983afe33SPhil Shaferaddition, a significant percentage of users (1 in 12) will be color 121983afe33SPhil Shaferblind. Depending on color to convey critical information is not a 122983afe33SPhil Shafergood idea. Color should enhance output, but should not be used as the 123983afe33SPhil Shafersole means of encoding information. 124983afe33SPhil Shafer 125983afe33SPhil Shafer.. index:: Field Roles; Decoration 126983afe33SPhil Shafer.. _decoration-role: 127983afe33SPhil Shafer 128983afe33SPhil ShaferThe Decoration Role ({D:}) 129983afe33SPhil Shafer++++++++++++++++++++++++++ 130983afe33SPhil Shafer 131983afe33SPhil ShaferDecorations are typically punctuation marks such as colons, 132983afe33SPhil Shafersemi-colons, and commas used to decorate the text and make it simpler 133983afe33SPhil Shaferfor human readers. By marking these distinctly, HTML usage scenarios 134983afe33SPhil Shafercan use CSS to direct their display parameters:: 135983afe33SPhil Shafer 136983afe33SPhil Shafer xo_emit("{D:((}{:name}{D:))}\n", name); 137983afe33SPhil Shafer 138983afe33SPhil Shafer.. index:: Field Roles; Gettext 139983afe33SPhil Shafer.. _gettext-role: 140983afe33SPhil Shafer 141983afe33SPhil ShaferThe Gettext Role ({G:}) 142983afe33SPhil Shafer+++++++++++++++++++++++ 143983afe33SPhil Shafer 144983afe33SPhil Shaferlibxo supports internationalization (i18n) through its use of 145983afe33SPhil Shafergettext(3). Use the "{G:}" role to request that the remaining part of 146983afe33SPhil Shaferthe format string, following the "{G:}" field, be handled using 147983afe33SPhil Shafergettext(). 148983afe33SPhil Shafer 149983afe33SPhil ShaferSince gettext() uses the string as the key into the message catalog, 150983afe33SPhil Shaferlibxo uses a simplified version of the format string that removes 151983afe33SPhil Shaferunimportant field formatting and modifiers, stopping minor formatting 152983afe33SPhil Shaferchanges from impacting the expensive translation process. A developer 153983afe33SPhil Shaferchange such as changing "/%06d" to "/%08d" should not force hand 154983afe33SPhil Shaferinspection of all .po files. 155983afe33SPhil Shafer 156983afe33SPhil ShaferThe simplified version can be generated for a single message using the 157983afe33SPhil Shafer"`xopo -s $text`" command, or an entire .pot can be translated using 158983afe33SPhil Shaferthe "`xopo -f $input -o $output`" command. 159983afe33SPhil Shafer 160983afe33SPhil Shafer xo_emit("{G:}Invalid token\n"); 161983afe33SPhil Shafer 162983afe33SPhil ShaferThe {G:} role allows a domain name to be set. gettext calls will 163983afe33SPhil Shafercontinue to use that domain name until the current format string 164983afe33SPhil Shaferprocessing is complete, enabling a library function to emit strings 165983afe33SPhil Shaferusing it's own catalog. The domain name can be either static as the 166983afe33SPhil Shafercontent of the field, or a format can be used to get the domain name 167983afe33SPhil Shaferfrom the arguments. 168983afe33SPhil Shafer 169983afe33SPhil Shafer xo_emit("{G:libc}Service unavailable in restricted mode\n"); 170983afe33SPhil Shafer 171983afe33SPhil ShaferSee :ref:`i18n` for additional details. 172983afe33SPhil Shafer 173983afe33SPhil Shafer.. index:: Field Roles; Label 174983afe33SPhil Shafer.. _label-role: 175983afe33SPhil Shafer 176983afe33SPhil ShaferThe Label Role ({L:}) 177983afe33SPhil Shafer+++++++++++++++++++++ 178983afe33SPhil Shafer 179983afe33SPhil ShaferLabels are text that appears before a value:: 180983afe33SPhil Shafer 181983afe33SPhil Shafer xo_emit("{Lwc:Cost}{:cost/%u}\n", cost); 182983afe33SPhil Shafer 183*34b867caSPhil ShaferIf a label needs to include a slash, it must be escaped using two 184*34b867caSPhil Shaferbackslashes, one for the C compiler and one for libxo:: 185*34b867caSPhil Shafer 186*34b867caSPhil Shafer xo_emit("{Lc:Low\\/warn level}{:level/%s}\n", level); 187*34b867caSPhil Shafer 188983afe33SPhil Shafer.. index:: Field Roles; Note 189983afe33SPhil Shafer.. _note-role: 190983afe33SPhil Shafer 191983afe33SPhil ShaferThe Note Role ({N:}) 192983afe33SPhil Shafer++++++++++++++++++++ 193983afe33SPhil Shafer 194983afe33SPhil ShaferNotes are text that appears after a value:: 195983afe33SPhil Shafer 196983afe33SPhil Shafer xo_emit("{:cost/%u} {N:per year}\n", cost); 197983afe33SPhil Shafer 198983afe33SPhil Shafer.. index:: Field Roles; Padding 199983afe33SPhil Shafer.. _padding-role: 200983afe33SPhil Shafer 201983afe33SPhil ShaferThe Padding Role ({P:}) 202983afe33SPhil Shafer+++++++++++++++++++++++ 203983afe33SPhil Shafer 204983afe33SPhil ShaferPadding represents whitespace used before and between fields. 205983afe33SPhil Shafer 206983afe33SPhil ShaferThe padding content can be either static, when placed directly within 207983afe33SPhil Shaferthe field descriptor, or a printf-style format descriptor can be used, 208983afe33SPhil Shaferif preceded by a slash ("/"):: 209983afe33SPhil Shafer 210983afe33SPhil Shafer xo_emit("{P: }{Lwc:Cost}{:cost/%u}\n", cost); 211983afe33SPhil Shafer xo_emit("{P:/%30s}{Lwc:Cost}{:cost/%u}\n", "", cost); 212983afe33SPhil Shafer 213983afe33SPhil Shafer.. index:: Field Roles; Title 214983afe33SPhil Shafer.. _title-role: 215983afe33SPhil Shafer 216983afe33SPhil ShaferThe Title Role ({T:}) 217983afe33SPhil Shafer+++++++++++++++++++++ 218983afe33SPhil Shafer 219983afe33SPhil ShaferTitle are heading or column headers that are meant to be displayed to 220983afe33SPhil Shaferthe user. The title can be either static, when placed directly within 221983afe33SPhil Shaferthe field descriptor, or a printf-style format descriptor can be used, 222983afe33SPhil Shaferif preceded by a slash ("/"):: 223983afe33SPhil Shafer 224983afe33SPhil Shafer xo_emit("{T:Interface Statistics}\n"); 225983afe33SPhil Shafer xo_emit("{T:/%20.20s}{T:/%6.6s}\n", "Item Name", "Cost"); 226983afe33SPhil Shafer 227983afe33SPhil ShaferTitle fields have an extra convenience feature; if both content and 228983afe33SPhil Shaferformat are specified, instead of looking to the argument list for a 229983afe33SPhil Shafervalue, the content is used, allowing a mixture of format and content 230983afe33SPhil Shaferwithin the field descriptor:: 231983afe33SPhil Shafer 232983afe33SPhil Shafer xo_emit("{T:Name/%20s}{T:Count/%6s}\n"); 233983afe33SPhil Shafer 234983afe33SPhil ShaferSince the incoming argument is a string, the format must be "%s" or 235983afe33SPhil Shafersomething suitable. 236983afe33SPhil Shafer 237983afe33SPhil Shafer.. index:: Field Roles; Units 238983afe33SPhil Shafer.. index:: XOF_UNITS 239983afe33SPhil Shafer.. _units-role: 240983afe33SPhil Shafer 241983afe33SPhil ShaferThe Units Role ({U:}) 242983afe33SPhil Shafer+++++++++++++++++++++ 243983afe33SPhil Shafer 244983afe33SPhil ShaferUnits are the dimension by which values are measured, such as degrees, 245983afe33SPhil Shafermiles, bytes, and decibels. The units field carries this information 246983afe33SPhil Shaferfor the previous value field:: 247983afe33SPhil Shafer 248983afe33SPhil Shafer xo_emit("{Lwc:Distance}{:distance/%u}{Uw:miles}\n", miles); 249983afe33SPhil Shafer 250983afe33SPhil ShaferNote that the sense of the 'w' modifier is reversed for units; 251983afe33SPhil Shafera blank is added before the contents, rather than after it. 252983afe33SPhil Shafer 253983afe33SPhil ShaferWhen the XOF_UNITS flag is set, units are rendered in XML as the 254983afe33SPhil Shafer"units" attribute:: 255983afe33SPhil Shafer 256983afe33SPhil Shafer <distance units="miles">50</distance> 257983afe33SPhil Shafer 258983afe33SPhil ShaferUnits can also be rendered in HTML as the "data-units" attribute:: 259983afe33SPhil Shafer 260983afe33SPhil Shafer <div class="data" data-tag="distance" data-units="miles" 261983afe33SPhil Shafer data-xpath="/top/data/distance">50</div> 262983afe33SPhil Shafer 263983afe33SPhil Shafer.. index:: Field Roles; Value 264983afe33SPhil Shafer.. _value-role: 265983afe33SPhil Shafer 266983afe33SPhil ShaferThe Value Role ({V:} and {:}) 267983afe33SPhil Shafer+++++++++++++++++++++++++++++ 268983afe33SPhil Shafer 269983afe33SPhil ShaferThe value role is used to represent the a data value that is 270983afe33SPhil Shaferinteresting for the non-display output styles (XML and JSON). Value 271983afe33SPhil Shaferis the default role; if no other role designation is given, the field 272983afe33SPhil Shaferis a value. The field name must appear within the field descriptor, 273983afe33SPhil Shaferfollowed by one or two format descriptors. The first format 274983afe33SPhil Shaferdescriptor is used for display styles (TEXT and HTML), while the 275983afe33SPhil Shafersecond one is used for encoding styles (XML and JSON). If no second 276983afe33SPhil Shaferformat is given, the encoding format defaults to the first format, 277983afe33SPhil Shaferwith any minimum width removed. If no first format is given, both 278983afe33SPhil Shaferformat descriptors default to "%s":: 279983afe33SPhil Shafer 280983afe33SPhil Shafer xo_emit("{:length/%02u}x{:width/%02u}x{:height/%02u}\n", 281983afe33SPhil Shafer length, width, height); 282983afe33SPhil Shafer xo_emit("{:author} wrote \"{:poem}\" in {:year/%4d}\n, 283983afe33SPhil Shafer author, poem, year); 284983afe33SPhil Shafer 285983afe33SPhil Shafer.. index:: Field Roles; Anchor 286983afe33SPhil Shafer.. _anchor-role: 287983afe33SPhil Shafer 288983afe33SPhil ShaferThe Anchor Roles ({[:} and {]:}) 289983afe33SPhil Shafer++++++++++++++++++++++++++++++++ 290983afe33SPhil Shafer 291983afe33SPhil ShaferThe anchor roles allow a set of strings by be padded as a group, 292983afe33SPhil Shaferbut still be visible to xo_emit as distinct fields. Either the start 293983afe33SPhil Shaferor stop anchor can give a field width and it can be either directly in 294983afe33SPhil Shaferthe descriptor or passed as an argument. Any fields between the start 295983afe33SPhil Shaferand stop anchor are padded to meet the minimum width given. 296983afe33SPhil Shafer 297983afe33SPhil ShaferTo give a width directly, encode it as the content of the anchor tag:: 298983afe33SPhil Shafer 299983afe33SPhil Shafer xo_emit("({[:10}{:min/%d}/{:max/%d}{]:})\n", min, max); 300983afe33SPhil Shafer 301983afe33SPhil ShaferTo pass a width as an argument, use "%d" as the format, which must 302983afe33SPhil Shaferappear after the "/". Note that only "%d" is supported for widths. 303983afe33SPhil ShaferUsing any other value could ruin your day:: 304983afe33SPhil Shafer 305983afe33SPhil Shafer xo_emit("({[:/%d}{:min/%d}/{:max/%d}{]:})\n", width, min, max); 306983afe33SPhil Shafer 307983afe33SPhil ShaferIf the width is negative, padding will be added on the right, suitable 308983afe33SPhil Shaferfor left justification. Otherwise the padding will be added to the 309983afe33SPhil Shaferleft of the fields between the start and stop anchors, suitable for 310983afe33SPhil Shaferright justification. If the width is zero, nothing happens. If the 311983afe33SPhil Shafernumber of columns of output between the start and stop anchors is less 312983afe33SPhil Shaferthan the absolute value of the given width, nothing happens. 313983afe33SPhil Shafer 314983afe33SPhil Shafer.. index:: XOF_WARN 315983afe33SPhil Shafer 316983afe33SPhil ShaferWidths over 8k are considered probable errors and not supported. If 317983afe33SPhil ShaferXOF_WARN is set, a warning will be generated. 318