1
0
Fork 0

Avoid color config in tako if noninteractive

This commit is contained in:
Jeremy Kaplan 2017-01-05 11:11:32 -08:00
commit 3ddaa4572a

View file

@ -40,58 +40,59 @@ $TAKO_SETTINGS.aliases.update({
'workon': _workon, 'workon': _workon,
}) })
if '256color' in $TERM: if 'TERM' in __tako_env__:
colors = { if '256color' in $TERM:
'blue': 81, colors = {
'orange': 166, 'blue': 81,
'purple': 135, 'orange': 166,
'red': 196, 'purple': 135,
'green': 118, 'red': 196,
'gray': 241, 'green': 118,
} 'gray': 241,
}
def colorize(color, text): def colorize(color, text):
prefix = '{COLOR_' + str(colors[color]) + '}' prefix = '{COLOR_' + str(colors[color]) + '}'
suffix = '{NO_COLOR}' suffix = '{NO_COLOR}'
return prefix + text + suffix return prefix + text + suffix
else: else:
colors = { colors = {
'blue': 'BLUE', 'blue': 'BLUE',
'orange': 'YELLOW', 'orange': 'YELLOW',
'purple': 'PURPLE', 'purple': 'PURPLE',
'red': 'RED', 'red': 'RED',
'green': 'GREEN', 'green': 'GREEN',
'gray': 'WHITE', 'gray': 'WHITE',
} }
def colorize(color, text): def colorize(color, text):
prefix = '{%s}' % colors[color] prefix = '{%s}' % colors[color]
suffix = '{NO_COLOR}' suffix = '{NO_COLOR}'
return prefix + text + suffix return prefix + text + suffix
def git_branch(): def git_branch():
ref=$(git symbolic-ref HEAD err> /dev/null) ref=$(git symbolic-ref HEAD err> /dev/null)
if not ref: return None if not ref: return None
prefix = colorize('gray', ':') prefix = colorize('gray', ':')
branch = colorize('orange', re.sub('^refs/heads/', '', ref[0].strip())) branch = colorize('orange', re.sub('^refs/heads/', '', ref[0].strip()))
return prefix + branch return prefix + branch
$TAKO_SETTINGS.prompt_fields['git_branch'] = git_branch $TAKO_SETTINGS.prompt_fields['git_branch'] = git_branch
def make_prompt(): def make_prompt():
username = colorize('purple', '{user}') username = colorize('purple', '{user}')
host = colorize('blue', '{hostname}') host = colorize('blue', '{hostname}')
directory = colorize('green', '{cwd}') directory = colorize('green', '{cwd}')
lbrkt = colorize('gray', '[') lbrkt = colorize('gray', '[')
rbrkt = colorize('gray', ']') rbrkt = colorize('gray', ']')
colon = colorize('gray', ':') colon = colorize('gray', ':')
return lbrkt + colon.join([ return lbrkt + colon.join([
username, username,
host, host,
directory, directory,
]) + '{git_branch}' + rbrkt + '\n{prompt_end} ' ]) + '{git_branch}' + rbrkt + '\n{prompt_end} '
$TAKO_SETTINGS.prompt = make_prompt() $TAKO_SETTINGS.prompt = make_prompt()
$TAKO_SETTINGS.show_traceback = True $TAKO_SETTINGS.show_traceback = True
$TAKO_SETTINGS.traceback_logfile = $HOME + '/tmp/tako.log' $TAKO_SETTINGS.traceback_logfile = $HOME + '/tmp/tako.log'