mercurial/ui.py
changeset 11325 22a737306ba5
parent 11324 cdf6d861b207
child 11416 caf10970950e
equal deleted inserted replaced
11324:cdf6d861b207 11325:22a737306ba5
   251         for section in cfg.sections():
   251         for section in cfg.sections():
   252             for name, value in self.configitems(section, untrusted):
   252             for name, value in self.configitems(section, untrusted):
   253                 yield section, name, str(value).replace('\n', '\\n')
   253                 yield section, name, str(value).replace('\n', '\\n')
   254 
   254 
   255     def plain(self):
   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         return 'HGPLAIN' in os.environ
   266         return 'HGPLAIN' in os.environ
   257 
   267 
   258     def username(self):
   268     def username(self):
   259         """Return default username to be used in commits.
   269         """Return default username to be used in commits.
   260 
   270 
   367         except: pass
   377         except: pass
   368         try: sys.stderr.flush()
   378         try: sys.stderr.flush()
   369         except: pass
   379         except: pass
   370 
   380 
   371     def interactive(self):
   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         i = self.configbool("ui", "interactive", None)
   395         i = self.configbool("ui", "interactive", None)
   373         if i is None:
   396         if i is None:
   374             try:
   397             try:
   375                 return sys.stdin.isatty()
   398                 return sys.stdin.isatty()
   376             except AttributeError:
   399             except AttributeError:
   379                 return False
   402                 return False
   380 
   403 
   381         return i
   404         return i
   382 
   405 
   383     def formatted(self):
   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         if self.plain():
   423         if self.plain():
   385             return False
   424             return False
   386 
   425 
   387         i = self.configbool("ui", "formatted", None)
   426         i = self.configbool("ui", "formatted", None)
   388         if i is None:
   427         if i is None: