8 Field roles are optional, and indicate the role and formatting of the
9 content. The roles are listed below; only one role is permitted:
11 === ============== =================================================
13 === ============== =================================================
14 C color Field has color and effect controls
15 D decoration Field is non-text (e.g., colon, comma)
16 E error Field is an error message
17 G gettext Call gettext(3) on the format string
18 L label Field is text that prefixes a value
19 N note Field is text that follows a value
20 P padding Field is spaces needed for vertical alignment
21 T title Field is a title value for headings
22 U units Field is the units for the previous value field
23 V value Field is the name of field (the default)
24 W warning Field is a warning message
25 [ start-anchor Begin a section of anchored variable-width text
26 ] stop-anchor End a section of anchored variable-width text
27 === ============== =================================================
32 xo_emit("{L:Free}{D::}{P: }{:free/%u} {U:Blocks}\n",
35 When a role is not provided, the "*value*" role is used as the default.
37 Roles and modifiers can also use more verbose names, when preceded by
41 xo_emit("{,label:Free}{,decoration::}{,padding: }"
42 "{,value:free/%u} {,units:Blocks}\n",
45 .. index:: Field Roles; Color
51 Colors and effects control how text values are displayed; they are
52 used for display styles (TEXT and HTML)::
54 xo_emit("{C:bold}{:value}{C:no-bold}\n", value);
56 Colors and effects remain in effect until modified by other "C"-role
59 xo_emit("{C:bold}{C:inverse}both{C:no-bold}only inverse\n");
61 If the content is empty, the "*reset*" action is performed::
63 xo_emit("{C:both,underline}{:value}{C:}\n", value);
65 The content should be a comma-separated list of zero or more colors or
68 xo_emit("{C:bold,inverse}Ugly{C:no-bold,no-inverse}\n");
70 The color content can be either static, when placed directly within
71 the field descriptor, or a printf-style format descriptor can be used,
72 if preceded by a slash ("/"):
74 xo_emit("{C:/%s%s}{:value}{C:}", need_bold ? "bold" : "",
75 need_underline ? "underline" : "", value);
77 Color names are prefixed with either "fg-" or "bg-" to change the
78 foreground and background colors, respectively::
80 xo_emit("{C:/fg-%s,bg-%s}{Lwc:Cost}{:cost/%u}{C:reset}\n",
81 fg_color, bg_color, cost);
83 The following table lists the supported effects:
85 =============== =================================================
87 =============== =================================================
88 bg-XXXXX Change background color
89 bold Start bold text effect
90 fg-XXXXX Change foreground color
91 inverse Start inverse (aka reverse) text effect
92 no-bold Stop bold text effect
93 no-inverse Stop inverse (aka reverse) text effect
94 no-underline Stop underline text effect
95 normal Reset effects (only)
96 reset Reset colors and effects (restore defaults)
97 underline Start underline text effect
98 =============== =================================================
100 The following color names are supported:
102 ========= ============================================
104 ========= ============================================
108 default Default color for foreground or background
114 ========= ============================================
116 When using colors, the developer should remember that users will
117 change the foreground and background colors of terminal session
118 according to their own tastes, so assuming that "blue" looks nice is
119 never safe, and is a constant annoyance to your dear author. In
120 addition, a significant percentage of users (1 in 12) will be color
121 blind. Depending on color to convey critical information is not a
122 good idea. Color should enhance output, but should not be used as the
123 sole means of encoding information.
125 .. index:: Field Roles; Decoration
128 The Decoration Role ({D:})
129 ++++++++++++++++++++++++++
131 Decorations are typically punctuation marks such as colons,
132 semi-colons, and commas used to decorate the text and make it simpler
133 for human readers. By marking these distinctly, HTML usage scenarios
134 can use CSS to direct their display parameters::
136 xo_emit("{D:((}{:name}{D:))}\n", name);
138 .. index:: Field Roles; Gettext
141 The Gettext Role ({G:})
142 +++++++++++++++++++++++
144 libxo supports internationalization (i18n) through its use of
145 gettext(3). Use the "{G:}" role to request that the remaining part of
146 the format string, following the "{G:}" field, be handled using
149 Since gettext() uses the string as the key into the message catalog,
150 libxo uses a simplified version of the format string that removes
151 unimportant field formatting and modifiers, stopping minor formatting
152 changes from impacting the expensive translation process. A developer
153 change such as changing "/%06d" to "/%08d" should not force hand
154 inspection of all .po files.
156 The simplified version can be generated for a single message using the
157 "`xopo -s $text`" command, or an entire .pot can be translated using
158 the "`xopo -f $input -o $output`" command.
160 xo_emit("{G:}Invalid token\n");
162 The {G:} role allows a domain name to be set. gettext calls will
163 continue to use that domain name until the current format string
164 processing is complete, enabling a library function to emit strings
165 using it's own catalog. The domain name can be either static as the
166 content of the field, or a format can be used to get the domain name
169 xo_emit("{G:libc}Service unavailable in restricted mode\n");
171 See :ref:`i18n` for additional details.
173 .. index:: Field Roles; Label
176 The Label Role ({L:})
177 +++++++++++++++++++++
179 Labels are text that appears before a value::
181 xo_emit("{Lwc:Cost}{:cost/%u}\n", cost);
183 .. index:: Field Roles; Note
189 Notes are text that appears after a value::
191 xo_emit("{:cost/%u} {N:per year}\n", cost);
193 .. index:: Field Roles; Padding
196 The Padding Role ({P:})
197 +++++++++++++++++++++++
199 Padding represents whitespace used before and between fields.
201 The padding content can be either static, when placed directly within
202 the field descriptor, or a printf-style format descriptor can be used,
203 if preceded by a slash ("/")::
205 xo_emit("{P: }{Lwc:Cost}{:cost/%u}\n", cost);
206 xo_emit("{P:/%30s}{Lwc:Cost}{:cost/%u}\n", "", cost);
208 .. index:: Field Roles; Title
211 The Title Role ({T:})
212 +++++++++++++++++++++
214 Title are heading or column headers that are meant to be displayed to
215 the user. The title can be either static, when placed directly within
216 the field descriptor, or a printf-style format descriptor can be used,
217 if preceded by a slash ("/")::
219 xo_emit("{T:Interface Statistics}\n");
220 xo_emit("{T:/%20.20s}{T:/%6.6s}\n", "Item Name", "Cost");
222 Title fields have an extra convenience feature; if both content and
223 format are specified, instead of looking to the argument list for a
224 value, the content is used, allowing a mixture of format and content
225 within the field descriptor::
227 xo_emit("{T:Name/%20s}{T:Count/%6s}\n");
229 Since the incoming argument is a string, the format must be "%s" or
232 .. index:: Field Roles; Units
236 The Units Role ({U:})
237 +++++++++++++++++++++
239 Units are the dimension by which values are measured, such as degrees,
240 miles, bytes, and decibels. The units field carries this information
241 for the previous value field::
243 xo_emit("{Lwc:Distance}{:distance/%u}{Uw:miles}\n", miles);
245 Note that the sense of the 'w' modifier is reversed for units;
246 a blank is added before the contents, rather than after it.
248 When the XOF_UNITS flag is set, units are rendered in XML as the
251 <distance units="miles">50</distance>
253 Units can also be rendered in HTML as the "data-units" attribute::
255 <div class="data" data-tag="distance" data-units="miles"
256 data-xpath="/top/data/distance">50</div>
258 .. index:: Field Roles; Value
261 The Value Role ({V:} and {:})
262 +++++++++++++++++++++++++++++
264 The value role is used to represent the a data value that is
265 interesting for the non-display output styles (XML and JSON). Value
266 is the default role; if no other role designation is given, the field
267 is a value. The field name must appear within the field descriptor,
268 followed by one or two format descriptors. The first format
269 descriptor is used for display styles (TEXT and HTML), while the
270 second one is used for encoding styles (XML and JSON). If no second
271 format is given, the encoding format defaults to the first format,
272 with any minimum width removed. If no first format is given, both
273 format descriptors default to "%s"::
275 xo_emit("{:length/%02u}x{:width/%02u}x{:height/%02u}\n",
276 length, width, height);
277 xo_emit("{:author} wrote \"{:poem}\" in {:year/%4d}\n,
280 .. index:: Field Roles; Anchor
283 The Anchor Roles ({[:} and {]:})
284 ++++++++++++++++++++++++++++++++
286 The anchor roles allow a set of strings by be padded as a group,
287 but still be visible to xo_emit as distinct fields. Either the start
288 or stop anchor can give a field width and it can be either directly in
289 the descriptor or passed as an argument. Any fields between the start
290 and stop anchor are padded to meet the minimum width given.
292 To give a width directly, encode it as the content of the anchor tag::
294 xo_emit("({[:10}{:min/%d}/{:max/%d}{]:})\n", min, max);
296 To pass a width as an argument, use "%d" as the format, which must
297 appear after the "/". Note that only "%d" is supported for widths.
298 Using any other value could ruin your day::
300 xo_emit("({[:/%d}{:min/%d}/{:max/%d}{]:})\n", width, min, max);
302 If the width is negative, padding will be added on the right, suitable
303 for left justification. Otherwise the padding will be added to the
304 left of the fields between the start and stop anchors, suitable for
305 right justification. If the width is zero, nothing happens. If the
306 number of columns of output between the start and stop anchors is less
307 than the absolute value of the given width, nothing happens.
311 Widths over 8k are considered probable errors and not supported. If
312 XOF_WARN is set, a warning will be generated.