diff options
| -rw-r--r-- | color.py | 27 | ||||
| -rwxr-xr-x | main.py | 6 |
2 files changed, 31 insertions, 2 deletions
| @@ -83,15 +83,38 @@ def _Color(fg = None, bg = None, attr = None): | |||
| 83 | return code | 83 | return code |
| 84 | 84 | ||
| 85 | 85 | ||
| 86 | DEFAULT = None | ||
| 87 | |||
| 88 | def SetDefaultColoring(state): | ||
| 89 | """Set coloring behavior to |state|. | ||
| 90 | |||
| 91 | This is useful for overriding config options via the command line. | ||
| 92 | """ | ||
| 93 | if state is None: | ||
| 94 | # Leave it alone -- return quick! | ||
| 95 | return | ||
| 96 | |||
| 97 | global DEFAULT | ||
| 98 | state = state.lower() | ||
| 99 | if state in ('auto',): | ||
| 100 | DEFAULT = state | ||
| 101 | elif state in ('always', 'yes', 'true', True): | ||
| 102 | DEFAULT = 'always' | ||
| 103 | elif state in ('never', 'no', 'false', False): | ||
| 104 | DEFAULT = 'never' | ||
| 105 | |||
| 106 | |||
| 86 | class Coloring(object): | 107 | class Coloring(object): |
| 87 | def __init__(self, config, section_type): | 108 | def __init__(self, config, section_type): |
| 88 | self._section = 'color.%s' % section_type | 109 | self._section = 'color.%s' % section_type |
| 89 | self._config = config | 110 | self._config = config |
| 90 | self._out = sys.stdout | 111 | self._out = sys.stdout |
| 91 | 112 | ||
| 92 | on = self._config.GetString(self._section) | 113 | on = DEFAULT |
| 93 | if on is None: | 114 | if on is None: |
| 94 | on = self._config.GetString('color.ui') | 115 | on = self._config.GetString(self._section) |
| 116 | if on is None: | ||
| 117 | on = self._config.GetString('color.ui') | ||
| 95 | 118 | ||
| 96 | if on == 'auto': | 119 | if on == 'auto': |
| 97 | if pager.active or os.isatty(1): | 120 | if pager.active or os.isatty(1): |
| @@ -36,6 +36,7 @@ try: | |||
| 36 | except ImportError: | 36 | except ImportError: |
| 37 | kerberos = None | 37 | kerberos = None |
| 38 | 38 | ||
| 39 | from color import SetDefaultColoring | ||
| 39 | from trace import SetTrace | 40 | from trace import SetTrace |
| 40 | from git_command import git, GitCommand | 41 | from git_command import git, GitCommand |
| 41 | from git_config import init_ssh, close_ssh | 42 | from git_config import init_ssh, close_ssh |
| @@ -69,6 +70,9 @@ global_options.add_option('-p', '--paginate', | |||
| 69 | global_options.add_option('--no-pager', | 70 | global_options.add_option('--no-pager', |
| 70 | dest='no_pager', action='store_true', | 71 | dest='no_pager', action='store_true', |
| 71 | help='disable the pager') | 72 | help='disable the pager') |
| 73 | global_options.add_option('--color', | ||
| 74 | choices=('auto', 'always', 'never'), default=None, | ||
| 75 | help='control color usage: auto, always, never') | ||
| 72 | global_options.add_option('--trace', | 76 | global_options.add_option('--trace', |
| 73 | dest='trace', action='store_true', | 77 | dest='trace', action='store_true', |
| 74 | help='trace git command execution') | 78 | help='trace git command execution') |
| @@ -113,6 +117,8 @@ class _Repo(object): | |||
| 113 | print('fatal: invalid usage of --version', file=sys.stderr) | 117 | print('fatal: invalid usage of --version', file=sys.stderr) |
| 114 | return 1 | 118 | return 1 |
| 115 | 119 | ||
| 120 | SetDefaultColoring(gopts.color) | ||
| 121 | |||
| 116 | try: | 122 | try: |
| 117 | cmd = self.commands[name] | 123 | cmd = self.commands[name] |
| 118 | except KeyError: | 124 | except KeyError: |
