diff --git a/powerline/__init__.py b/powerline/__init__.py index c19b0424..0b99d85c 100644 --- a/powerline/__init__.py +++ b/powerline/__init__.py @@ -349,7 +349,7 @@ class Powerline(object): shutdown_event=None, config_loader=None): '''Do actual initialization. - + __init__ function only stores the arguments and runs this function. This function exists for powerline to be able to reload itself: it is easier to make ``__init__`` store arguments and call overriddable ``init`` than @@ -773,7 +773,6 @@ class Powerline(object): Not guaranteed to work properly, use it at your own risk. It may break your python code. ''' - from imp import reload import sys modules = self.imported_modules | set((module for module in sys.modules if module.startswith('powerline'))) modules_holder = [] diff --git a/powerline/renderer.py b/powerline/renderer.py index 204a328d..a2a9d32d 100644 --- a/powerline/renderer.py +++ b/powerline/renderer.py @@ -257,9 +257,9 @@ class Renderer(object): segments = theme.get_segments(side, line, self.get_segment_info(segment_info, mode)) # Handle excluded/included segments for the current mode segments = [ - self._get_highlighting(segment, segment['mode'] or mode) + self._get_highlighting(segment, segment_mode) for segment, segment_mode in ( - (segment, segment['mode']) + (segment, segment['mode'] or mode) for segment in segments ) if ( segment_mode not in segment['exclude_modes'] diff --git a/tests/test_configuration.py b/tests/test_configuration.py index ec05dab4..39bb9d20 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -384,6 +384,50 @@ class TestThemeHierarchy(TestRender): ]) +class TestModes(TestRender): + @add_args + def test_include_modes(self, p, config): + config['themes/test/default']['segments'] = { + 'left': [ + highlighted_string('s1', 'g1', include_modes=['m1']), + highlighted_string('s2', 'g1', include_modes=['m1', 'm2']), + highlighted_string('s3', 'g1', include_modes=['m3']), + ] + } + self.assertRenderEqual(p, '{--}') + self.assertRenderEqual(p, '{56} s1{56}>{56}s2{6-}>>{--}', mode='m1') + self.assertRenderEqual(p, '{56} s2{6-}>>{--}', mode='m2') + self.assertRenderEqual(p, '{56} s3{6-}>>{--}', mode='m3') + + @add_args + def test_exclude_modes(self, p, config): + config['themes/test/default']['segments'] = { + 'left': [ + highlighted_string('s1', 'g1', exclude_modes=['m1']), + highlighted_string('s2', 'g1', exclude_modes=['m1', 'm2']), + highlighted_string('s3', 'g1', exclude_modes=['m3']), + ] + } + self.assertRenderEqual(p, '{56} s1{56}>{56}s2{56}>{56}s3{6-}>>{--}') + self.assertRenderEqual(p, '{56} s3{6-}>>{--}', mode='m1') + self.assertRenderEqual(p, '{56} s1{56}>{56}s3{6-}>>{--}', mode='m2') + self.assertRenderEqual(p, '{56} s1{56}>{56}s2{6-}>>{--}', mode='m3') + + @add_args + def test_exinclude_modes(self, p, config): + config['themes/test/default']['segments'] = { + 'left': [ + highlighted_string('s1', 'g1', exclude_modes=['m1'], include_modes=['m2']), + highlighted_string('s2', 'g1', exclude_modes=['m1', 'm2'], include_modes=['m3']), + highlighted_string('s3', 'g1', exclude_modes=['m3'], include_modes=['m3']), + ] + } + self.assertRenderEqual(p, '{--}') + self.assertRenderEqual(p, '{--}', mode='m1') + self.assertRenderEqual(p, '{56} s1{6-}>>{--}', mode='m2') + self.assertRenderEqual(p, '{56} s2{6-}>>{--}', mode='m3') + + class TestVim(TestCase): def test_environ_update(self): # Regression test: test that segment obtains environment from vim, not @@ -406,7 +450,6 @@ class TestVim(TestCase): # Regression test: VimPowerline.add_local_theme did not work properly. from powerline.vim import VimPowerline import powerline as powerline_module - import vim with swap_attributes(config, powerline_module): with get_powerline_raw(config, VimPowerline) as powerline: powerline.add_local_theme('tests.matchers.always_true', {