Пример #1
0
    def test_empty_colorscheme(self):
        config("test/data/config1")
        pri_color = Colors().get_priority_colors()
        project_color = Colors().get_project_color()
        context_color = Colors().get_context_color()
        link_color = Colors().get_link_color()
        metadata_color = Colors().get_metadata_color()

        self.assertEqual(pri_color['A'], '\033[0;36m')
        self.assertEqual(pri_color['B'], '\033[0;33m')
        self.assertEqual(pri_color['C'], '\033[0;34m')
        self.assertEqual(project_color, '\033[1;31m')
        self.assertEqual(context_color, '\033[1;35m')
        self.assertEqual(link_color, '\033[4;36m')
        self.assertEqual(metadata_color, '\033[1;32m')
Пример #2
0
    def test_empty_color_values(self):
        config("test/data/ColorsTest5.conf")
        pri_color = Colors().get_priority_colors()
        project_color = Colors().get_project_color()
        context_color = Colors().get_context_color()
        link_color = Colors().get_link_color()
        metadata_color = Colors().get_metadata_color()

        self.assertEqual(pri_color['A'], NEUTRAL_COLOR)
        self.assertEqual(pri_color['B'], NEUTRAL_COLOR)
        self.assertEqual(pri_color['C'], NEUTRAL_COLOR)
        self.assertEqual(project_color, '')
        self.assertEqual(context_color, '')
        self.assertEqual(link_color, '')
        self.assertEqual(metadata_color, '')
Пример #3
0
    def test_priority_color4(self):
        config("test/data/ColorsTest4.conf")
        color = Colors().get_priority_colors()

        self.assertEqual(color['A'], NEUTRAL_COLOR)
        self.assertEqual(color['B'], NEUTRAL_COLOR)
        self.assertEqual(color['C'], NEUTRAL_COLOR)
Пример #4
0
    def test_priority_color2(self):
        config("test/data/ColorsTest2.conf")
        color = Colors().get_priority_colors()

        self.assertEqual(color['A'], '\033[0;35m')
        self.assertEqual(color['B'], '\033[0;1;36m')
        self.assertEqual(color['C'], '\033[0;37m')
Пример #5
0
    def test_priority_color1(self):
        config("test/data/ColorsTest1.conf")
        color = Colors().get_priority_colors()

        self.assertEqual(color['A'], '\033[0;38;5;1m')
        self.assertEqual(color['B'], '\033[0;38;5;2m')
        self.assertEqual(color['C'], '\033[0;38;5;3m')
Пример #6
0
    def test_priority_color3(self):
        config("test/data/ColorsTest3.conf")
        color = Colors().get_priority_colors()

        self.assertEqual(color['A'], '\033[0;35m')
        self.assertEqual(color['B'], '\033[0;1;36m')
        self.assertEqual(color['Z'], NEUTRAL_COLOR)
        self.assertEqual(color['D'], '\033[0;31m')
        self.assertEqual(color['C'], '\033[0;38;5;7m')
Пример #7
0
    def filter(self, p_todo_str, p_todo):
        """ Applies the colors. """

        colorscheme = Colors()
        priority_colors = colorscheme.get_priority_colors()
        project_color = colorscheme.get_project_color()
        context_color = colorscheme.get_context_color()
        metadata_color = colorscheme.get_metadata_color()
        link_color = colorscheme.get_link_color()

        if config().colors():
            color = NEUTRAL_COLOR
            try:
                color = priority_colors[p_todo.priority()]
            except KeyError:
                pass

            # color by priority
            p_todo_str = color + p_todo_str

            # color projects / contexts
            p_todo_str = re.sub(
                r'\B(\+|@)(\S*\w)', lambda m: (context_color if m.group(0)[
                    0] == "@" else project_color) + m.group(0) + color,
                p_todo_str)

            # tags
            p_todo_str = re.sub(r'\b\S+:[^/\s]\S*\b',
                                metadata_color + r'\g<0>' + color, p_todo_str)

            # add link_color to any valid URL specified outside of the tag.
            p_todo_str = re.sub(r'(^|\s)(\w+:){1}(//\S+)',
                                ' ' + link_color + r'\2\3' + color, p_todo_str)

        p_todo_str += NEUTRAL_COLOR

        return p_todo_str
Пример #8
0
    def filter(self, p_todo_str, p_todo):
        """ Applies the colors. """

        colorscheme = Colors()
        priority_colors = colorscheme.get_priority_colors()
        project_color = colorscheme.get_project_color()
        context_color = colorscheme.get_context_color()
        metadata_color = colorscheme.get_metadata_color()
        link_color = colorscheme.get_link_color()

        if config().colors():
            color = NEUTRAL_COLOR
            try:
                color = priority_colors[p_todo.priority()]
            except KeyError:
                pass

            # color by priority
            p_todo_str = color + p_todo_str

            # color projects / contexts
            p_todo_str = re.sub(
                r'\B(\+|@)(\S*\w)',
                lambda m: (
                    context_color if m.group(0)[0] == "@"
                    else project_color) + m.group(0) + color,
                p_todo_str)

            # tags
            p_todo_str = re.sub(r'\b\S+:[^/\s]\S*\b',
                                metadata_color + r'\g<0>' + color,
                                p_todo_str)

            # add link_color to any valid URL specified outside of the tag.
            p_todo_str = re.sub(r'(^|\s)(\w+:){1}(//\S+)',
                                ' ' + link_color + r'\2\3' + color,
                                p_todo_str)

        p_todo_str += NEUTRAL_COLOR

        return p_todo_str
Пример #9
0
    def test_project_color1(self):
        config(p_overrides={('colorscheme', 'project_color'): '2'})
        color = Colors().get_project_color()

        self.assertEqual(color, '\033[1;38;5;2m')
Пример #10
0
    def test_project_color3(self):
        config(p_overrides={('colorscheme', 'project_color'): 'yellow'})
        color = Colors().get_project_color()

        self.assertEqual(color, '\033[1;33m')
Пример #11
0
    def test_metadata_color4(self):
        config(p_overrides={('colorscheme', 'metadata_color'): '777'})
        color = Colors().get_metadata_color()

        self.assertEqual(color, NEUTRAL_COLOR)
Пример #12
0
    def test_link_color1(self):
        config(p_overrides={('colorscheme', 'link_color'): '77'})
        color = Colors().get_link_color()

        self.assertEqual(color, '\033[4;38;5;77m')
Пример #13
0
    def test_metadata_color3(self):
        config(p_overrides={('colorscheme', 'metadata_color'): 'light-red'})
        color = Colors().get_metadata_color()

        self.assertEqual(color, '\033[1;1;31m')
Пример #14
0
    def test_metadata_color1(self):
        config(p_overrides={('colorscheme', 'metadata_color'): '128'})
        color = Colors().get_metadata_color()

        self.assertEqual(color, '\033[1;38;5;128m')
Пример #15
0
    def test_context_color4(self):
        config(p_overrides={('colorscheme', 'context_color'): '392'})
        color = Colors().get_context_color()

        self.assertEqual(color, NEUTRAL_COLOR)
Пример #16
0
    def test_context_color3(self):
        config(p_overrides={('colorscheme', 'context_color'): 'magenta'})
        color = Colors().get_context_color()

        self.assertEqual(color, '\033[1;35m')
Пример #17
0
    def test_project_color2(self):
        config(p_overrides={('colorscheme', 'project_color'): 'Foo'})
        color = Colors().get_project_color()

        self.assertEqual(color, NEUTRAL_COLOR)