From 443679d532f73dc7488338b65145e1b61df3460a Mon Sep 17 00:00:00 2001 From: Foo Date: Tue, 16 May 2017 18:49:10 +0300 Subject: [PATCH] Make last_pipe_status fallback to last_exit_code --- powerline/segments/shell.py | 5 ++++- tests/test_python/test_segments.py | 29 +++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/powerline/segments/shell.py b/powerline/segments/shell.py index 57847e4f..a9e96092 100644 --- a/powerline/segments/shell.py +++ b/powerline/segments/shell.py @@ -39,7 +39,10 @@ def last_pipe_status(pl, segment_info): Highlight groups used: ``exit_fail``, ``exit_success`` ''' - last_pipe_status = segment_info['args'].last_pipe_status + last_pipe_status = ( + segment_info['args'].last_pipe_status + or (segment_info['args'].last_exit_code,) + ) if any(last_pipe_status): return [ { diff --git a/tests/test_python/test_segments.py b/tests/test_python/test_segments.py index 4aef6a19..7b576d01 100644 --- a/tests/test_python/test_segments.py +++ b/tests/test_python/test_segments.py @@ -52,15 +52,35 @@ class TestShell(TestCase): def test_last_pipe_status(self): pl = Pl() - segment_info = {'args': Args(last_pipe_status=[])} + segment_info = {'args': Args(last_pipe_status=[], last_exit_code=0)} self.assertEqual(shell.last_pipe_status(pl=pl, segment_info=segment_info), None) segment_info['args'].last_pipe_status = [0, 0, 0] self.assertEqual(shell.last_pipe_status(pl=pl, segment_info=segment_info), None) + segment_info['args'].last_pipe_status = [0, 0] + self.assertEqual(shell.last_pipe_status(pl=pl, segment_info=segment_info), None) + segment_info['args'].last_pipe_status = [0] + self.assertEqual(shell.last_pipe_status(pl=pl, segment_info=segment_info), None) segment_info['args'].last_pipe_status = [0, 2, 0] self.assertEqual(shell.last_pipe_status(pl=pl, segment_info=segment_info), [ {'contents': '0', 'highlight_groups': ['exit_success'], 'draw_inner_divider': True}, {'contents': '2', 'highlight_groups': ['exit_fail'], 'draw_inner_divider': True}, - {'contents': '0', 'highlight_groups': ['exit_success'], 'draw_inner_divider': True} + {'contents': '0', 'highlight_groups': ['exit_success'], 'draw_inner_divider': True}, + ]) + segment_info['args'].last_pipe_status = [2, 0, 0] + self.assertEqual(shell.last_pipe_status(pl=pl, segment_info=segment_info), [ + {'contents': '2', 'highlight_groups': ['exit_fail'], 'draw_inner_divider': True}, + {'contents': '0', 'highlight_groups': ['exit_success'], 'draw_inner_divider': True}, + {'contents': '0', 'highlight_groups': ['exit_success'], 'draw_inner_divider': True}, + ]) + segment_info['args'].last_pipe_status = [0, 0, 2] + self.assertEqual(shell.last_pipe_status(pl=pl, segment_info=segment_info), [ + {'contents': '0', 'highlight_groups': ['exit_success'], 'draw_inner_divider': True}, + {'contents': '0', 'highlight_groups': ['exit_success'], 'draw_inner_divider': True}, + {'contents': '2', 'highlight_groups': ['exit_fail'], 'draw_inner_divider': True}, + ]) + segment_info['args'].last_pipe_status = [2] + self.assertEqual(shell.last_pipe_status(pl=pl, segment_info=segment_info), [ + {'contents': '2', 'highlight_groups': ['exit_fail'], 'draw_inner_divider': True}, ]) segment_info['args'].last_pipe_status = [0, 'sigsegv', 'sigsegv+core'] self.assertEqual(shell.last_pipe_status(pl=pl, segment_info=segment_info), [ @@ -80,6 +100,11 @@ class TestShell(TestCase): {'contents': 'sigsegv+core', 'highlight_groups': ['exit_fail'], 'draw_inner_divider': True}, {'contents': '0', 'highlight_groups': ['exit_success'], 'draw_inner_divider': True} ]) + segment_info['args'].last_pipe_status = [] + segment_info['args'].last_exit_code = 5 + self.assertEqual(shell.last_pipe_status(pl=pl, segment_info=segment_info), [ + {'contents': '5', 'highlight_groups': ['exit_fail'], 'draw_inner_divider': True}, + ]) def test_jobnum(self): pl = Pl()