hgext/color.py
branchstable
changeset 14769 9adce4b38ed1
parent 14768 55db12e54450
child 14989 9e9d4a762586
equal deleted inserted replaced
14768:55db12e54450 14769:9adce4b38ed1
    73 ECMA-48 mode, the options are 'bold', 'inverse', 'italic', and
    73 ECMA-48 mode, the options are 'bold', 'inverse', 'italic', and
    74 'underline'.  How each is rendered depends on the terminal emulator.
    74 'underline'.  How each is rendered depends on the terminal emulator.
    75 Some may not be available for a given terminal type, and will be
    75 Some may not be available for a given terminal type, and will be
    76 silently ignored.
    76 silently ignored.
    77 
    77 
       
    78 Note that on some systems, terminfo mode may cause problems when using
       
    79 color with the pager extension and less -R. less with the -R option
       
    80 will only display ECMA-48 color codes, and terminfo mode may sometimes
       
    81 emit codes that less doesn't understand. You can work around this by
       
    82 either using ansi mode (or auto mode), or by using less -r (which will
       
    83 pass through all terminal control codes, not just color control
       
    84 codes).
       
    85 
    78 Because there are only eight standard colors, this module allows you
    86 Because there are only eight standard colors, this module allows you
    79 to define color names for other color slots which might be available
    87 to define color names for other color slots which might be available
    80 for your terminal type, assuming terminfo mode.  For instance::
    88 for your terminal type, assuming terminfo mode.  For instance::
    81 
    89 
    82   color.brightblue = 12
    90   color.brightblue = 12
    87 that have brighter colors defined in the upper eight) and, 'pink' and
    95 that have brighter colors defined in the upper eight) and, 'pink' and
    88 'orange' to colors in 256-color xterm's default color cube.  These
    96 'orange' to colors in 256-color xterm's default color cube.  These
    89 defined colors may then be used as any of the pre-defined eight,
    97 defined colors may then be used as any of the pre-defined eight,
    90 including appending '_background' to set the background to that color.
    98 including appending '_background' to set the background to that color.
    91 
    99 
    92 The color extension will try to detect whether to use terminfo, ANSI
   100 By default, the color extension will use ANSI mode (or win32 mode on
    93 codes or Win32 console APIs, unless it is made explicit; e.g.::
   101 Windows) if it detects a terminal. To override auto mode (to enable
       
   102 terminfo mode, for example), set the following configuration option::
    94 
   103 
    95   [color]
   104   [color]
    96   mode = ansi
   105   mode = terminfo
    97 
   106 
    98 Any value other than 'ansi', 'win32', 'terminfo', or 'auto' will
   107 Any value other than 'ansi', 'win32', 'terminfo', or 'auto' will
    99 disable color.
   108 disable color.
   100 
       
   101 '''
   109 '''
   102 
   110 
   103 import os
   111 import os
   104 
   112 
   105 from mercurial import commands, dispatch, extensions, ui as uimod, util
   113 from mercurial import commands, dispatch, extensions, ui as uimod, util
   166     realmode = mode
   174     realmode = mode
   167     if mode == 'auto':
   175     if mode == 'auto':
   168         if os.name == 'nt' and 'TERM' not in os.environ:
   176         if os.name == 'nt' and 'TERM' not in os.environ:
   169             # looks line a cmd.exe console, use win32 API or nothing
   177             # looks line a cmd.exe console, use win32 API or nothing
   170             realmode = 'win32'
   178             realmode = 'win32'
   171         elif not formatted:
   179         else:
   172             realmode = 'ansi'
   180             realmode = 'ansi'
   173         else:
       
   174             realmode = 'terminfo'
       
   175 
   181 
   176     if realmode == 'win32':
   182     if realmode == 'win32':
   177         if not w32effects:
   183         if not w32effects:
   178             if mode == 'win32':
   184             if mode == 'win32':
   179                 # only warn if color.mode is explicitly set to win32
   185                 # only warn if color.mode is explicitly set to win32