##// END OF EJS Templates
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen -
r11325:22a73730 default
parent child Browse files
Show More
@@ -253,6 +253,16 b' class ui(object):'
253 253 yield section, name, str(value).replace('\n', '\\n')
254 254
255 255 def plain(self):
256 '''is plain mode active?
257
258 Plain mode means that all configuration variables which affect the
259 behavior and output of Mercurial should be ignored. Additionally, the
260 output should be stable, reproducible and suitable for use in scripts or
261 applications.
262
263 The only way to trigger plain mode is by setting the `HGPLAIN'
264 environment variable.
265 '''
256 266 return 'HGPLAIN' in os.environ
257 267
258 268 def username(self):
@@ -369,6 +379,19 b' class ui(object):'
369 379 except: pass
370 380
371 381 def interactive(self):
382 '''is interactive input allowed?
383
384 An interactive session is a session where input can be reasonably read
385 from `sys.stdin'. If this function returns false, any attempt to read
386 from stdin should fail with an error, unless a sensible default has been
387 specified.
388
389 Interactiveness is triggered by the value of the `ui.interactive'
390 configuration variable or - if it is unset - when `sys.stdin' points
391 to a terminal device.
392
393 This function refers to input only; for output, see `ui.formatted()'.
394 '''
372 395 i = self.configbool("ui", "interactive", None)
373 396 if i is None:
374 397 try:
@@ -381,6 +404,22 b' class ui(object):'
381 404 return i
382 405
383 406 def formatted(self):
407 '''should formatted output be used?
408
409 It is often desirable to format the output to suite the output medium.
410 Examples of this are truncating long lines or colorizing messages.
411 However, this is not often not desirable when piping output into other
412 utilities, e.g. `grep'.
413
414 Formatted output is triggered by the value of the `ui.formatted'
415 configuration variable or - if it is unset - when `sys.stdout' points
416 to a terminal device. Please note that `ui.formatted' should be
417 considered an implementation detail; it is not intended for use outside
418 Mercurial or its extensions.
419
420 This function refers to output only; for input, see `ui.interactive()'.
421 This function always returns false when in plain mode, see `ui.plain()'.
422 '''
384 423 if self.plain():
385 424 return False
386 425
General Comments 0
You need to be logged in to leave comments. Login now