Merge remote-tracking branch 'zyx-i/branch-colors' into develop
This commit is contained in:
commit
8861c7144c
|
@ -5,6 +5,8 @@
|
|||
"superuser": { "fg": "white", "bg": "brightred", "attr": ["bold"] },
|
||||
"virtualenv": { "fg": "white", "bg": "darkcyan" },
|
||||
"branch": { "fg": "gray9", "bg": "gray2" },
|
||||
"branch_dirty": { "fg": "brightyellow", "bg": "gray2" },
|
||||
"branch_clean": { "fg": "gray9", "bg": "gray2" },
|
||||
"cwd": { "fg": "gray9", "bg": "gray4" },
|
||||
"cwd:current_folder": { "fg": "gray10", "bg": "gray4", "attr": ["bold"] },
|
||||
"cwd:divider": { "fg": "gray7", "bg": "gray4" },
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
"superuser": { "fg": "oldlace", "bg": "red", "attr": ["bold"] },
|
||||
"virtualenv": { "fg": "oldlace", "bg": "green" },
|
||||
"branch": { "fg": "gray61", "bg": "royalblue5" },
|
||||
"branch_dirty": { "fg": "yellow", "bg": "royalblue5" },
|
||||
"branch_clean": { "fg": "gray61", "bg": "royalblue5" },
|
||||
"cwd": { "fg": "lightyellow", "bg": "darkgreencopper" },
|
||||
"cwd:current_folder": { "fg": "oldlace", "bg": "darkgreencopper", "attr": ["bold"] },
|
||||
"cwd:divider": { "fg": "gray61", "bg": "darkgreencopper" },
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"paste_indicator": { "fg": "white", "bg": "mediumorange", "attr": ["bold"] },
|
||||
"readonly_indicator": { "fg": "brightestred", "bg": "gray4" },
|
||||
"branch": { "fg": "gray9", "bg": "gray4" },
|
||||
"branch_dirty": { "fg": "brightyellow", "bg": "gray4" },
|
||||
"branch_clean": { "fg": "gray9", "bg": "gray4" },
|
||||
"branch:divider": { "fg": "gray7", "bg": "gray4" },
|
||||
"file_directory": { "fg": "gray9", "bg": "gray4" },
|
||||
"file_name": { "fg": "white", "bg": "gray4", "attr": ["bold"] },
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"paste_indicator": { "fg": "oldlace", "bg": "orange", "attr": ["bold"] },
|
||||
"readonly_indicator": { "fg": "red", "bg": "darkgreencopper" },
|
||||
"branch": { "fg": "lightyellow", "bg": "darkgreencopper" },
|
||||
"branch_dirty": { "fg": "yellow", "bg": "darkgreencopper" },
|
||||
"branch_clean": { "fg": "lightyellow", "bg": "darkgreencopper" },
|
||||
"branch:divider": { "fg": "gray61", "bg": "darkgreencopper" },
|
||||
"file_directory": { "fg": "lightyellow", "bg": "darkgreencopper" },
|
||||
"file_name": { "fg": "oldlace", "bg": "darkgreencopper", "attr": ["bold"] },
|
||||
|
|
|
@ -41,11 +41,24 @@ def user():
|
|||
}]
|
||||
|
||||
|
||||
def branch():
|
||||
'''Return the current VCS branch.'''
|
||||
def branch(status_colors=True):
|
||||
'''Return the current VCS branch.@
|
||||
|
||||
:param bool status_colors:
|
||||
determines whether repository status will be used to determine highlighting. Default: True.
|
||||
|
||||
Highlight groups used: ``branch_clean``, ``branch_dirty``, ``branch``.
|
||||
'''
|
||||
repo = guess(path=os.path.abspath(os.getcwd()))
|
||||
if repo:
|
||||
return repo.branch()
|
||||
branch = repo.branch()
|
||||
if status_colors:
|
||||
return [{
|
||||
'contents': branch,
|
||||
'highlight_group': ['branch_dirty' if repo.status().strip() else 'branch_clean', 'branch'],
|
||||
}]
|
||||
else:
|
||||
return branch
|
||||
return None
|
||||
|
||||
|
||||
|
|
|
@ -306,15 +306,21 @@ def modified_buffers(text='+ ', join_str=','):
|
|||
|
||||
@requires_segment_info
|
||||
@memoize(2, cache_key=bufnr, cache_reg_func=purgeall_on_shell)
|
||||
def branch(segment_info):
|
||||
def branch(segment_info, status_colors=True):
|
||||
'''Return the current working branch.
|
||||
|
||||
:param bool status_colors:
|
||||
determines whether repository status will be used to determine highlighting. Default: True.
|
||||
|
||||
Highlight groups used: ``branch_clean``, ``branch_dirty``, ``branch``.
|
||||
|
||||
Divider highlight group used: ``branch:divider``.
|
||||
'''
|
||||
repo = guess(path=os.path.abspath(segment_info['buffer'].name or os.getcwd()))
|
||||
if repo:
|
||||
return [{
|
||||
'contents': repo.branch(),
|
||||
'highlight_group': (['branch_dirty' if repo.status().strip() else 'branch_clean'] if status_colors else []) + ['branch'],
|
||||
'divider_highlight_group': 'branch:divider',
|
||||
}]
|
||||
return None
|
||||
|
@ -351,5 +357,5 @@ def repository_status(segment_info):
|
|||
'''Return the status for the current repo.'''
|
||||
repo = guess(path=os.path.abspath(segment_info['buffer'].name or os.getcwd()))
|
||||
if repo:
|
||||
return repo.status()
|
||||
return repo.status().strip() or None
|
||||
return None
|
||||
|
|
|
@ -46,8 +46,14 @@ class TestCommon(TestCase):
|
|||
self.assertEqual(common.user(), [{'contents': 'def', 'highlight_group': ['superuser', 'user']}])
|
||||
|
||||
def test_branch(self):
|
||||
with replace_module_attr(common, 'guess', lambda path: Args(branch=lambda: os.path.basename(path))):
|
||||
self.assertEqual(common.branch(), 'tests')
|
||||
with replace_module_attr(common, 'guess', lambda path: Args(branch=lambda: os.path.basename(path), status=lambda: ' ')):
|
||||
self.assertEqual(common.branch(status_colors=False), 'tests')
|
||||
self.assertEqual(common.branch(status_colors=True),
|
||||
[{'contents': 'tests', 'highlight_group': ['branch_clean', 'branch']}])
|
||||
with replace_module_attr(common, 'guess', lambda path: Args(branch=lambda: os.path.basename(path), status=lambda: 'D ')):
|
||||
self.assertEqual(common.branch(status_colors=False), 'tests')
|
||||
self.assertEqual(common.branch(),
|
||||
[{'contents': 'tests', 'highlight_group': ['branch_dirty', 'branch']}])
|
||||
with replace_module_attr(common, 'guess', lambda path: None):
|
||||
self.assertEqual(common.branch(), None)
|
||||
|
||||
|
|
Loading…
Reference in New Issue