summaryrefslogtreecommitdiffstats
path: root/color.py
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2014-12-22 15:17:59 -0500
committerMike Frysinger <vapier@google.com>2014-12-30 18:50:05 -0500
commit902665bce668a58996de657a65c5ae3002a8810b (patch)
tree04d5093d86a398acb3be824cec60b89076674258 /color.py
parent3eb87cec5cae5f43becfe9fd1ff94de855cac08c (diff)
downloadgit-repo-902665bce668a58996de657a65c5ae3002a8810b.tar.gz
add a global --color option
If you want to turn off colors for commands, you have to manually adjust the git config settings (in various locations). If you're writing scripts though, you often don't want to modify those locations. Add a commandline option to explicitly control things. The default behavior is unchanged -- we still scan the config files. Change-Id: I54a3fd8e1918bac180aadd7c7d3004f069b02522
Diffstat (limited to 'color.py')
-rw-r--r--color.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/color.py b/color.py
index 7970198a..b2799286 100644
--- a/color.py
+++ b/color.py
@@ -83,15 +83,38 @@ def _Color(fg = None, bg = None, attr = None):
83 return code 83 return code
84 84
85 85
86DEFAULT = None
87
88def 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
86class Coloring(object): 107class 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):