summaryrefslogtreecommitdiffstats
path: root/powerline/renderers/shell/tcsh.py
blob: bf0697d130c1b998b71352ed0302cf6d8b0dea05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# vim:fileencoding=utf-8:noet
from __future__ import (unicode_literals, division, absolute_import, print_function)

from powerline.renderers.shell.zsh import ZshPromptRenderer


class TcshPromptRenderer(ZshPromptRenderer):
	'''Powerline tcsh prompt segment renderer.'''
	character_translations = ZshPromptRenderer.character_translations.copy()
	character_translations[ord('%')] = '%%'
	character_translations[ord('\\')] = '\\\\'
	character_translations[ord('^')] = '\\^'
	character_translations[ord('!')] = '\\!'

	def do_render(self, **kwargs):
		ret = super(TcshPromptRenderer, self).do_render(**kwargs)
		nbsp = self.character_translations.get(ord(' '), ' ')
		end = self.hlstyle()
		assert not ret or ret.endswith(end)
		if ret.endswith(nbsp + end):
			# Exchange nbsp and highlight end because tcsh removes trailing 
			# %{%} part of the prompt for whatever reason
			ret = ret[:-(len(nbsp) + len(end))] + end + nbsp
		else:
			# We *must* end prompt with non-%{%} sequence for the reasons 
			# explained above. So add nbsp if it is not already there.
			ret += nbsp
		return ret


renderer = TcshPromptRenderer