Пример #1
0
    def type_color_markup(type_label: str, type_category: DisplayTypeCategory,
                          config: DisplayConfig) -> str:
        '''
        Return a format string for applying color to a type based on type category and config.
        '''
        color = getattr(config, type_category.CONFIG_ATTR)
        if config.display_format in _DISPLAY_FORMAT_HTML:
            return HexColor.format_html(color, FORMAT_EMPTY)

        if config.display_format in _DISPLAY_FORMAT_TERMINAL:
            if terminal_ansi():
                return HexColor.format_terminal(color, FORMAT_EMPTY)
            # if not a compatible terminal, return label unaltered
            return FORMAT_EMPTY

        raise NotImplementedError('no handling for display format:',
                                  config.display_format)
Пример #2
0
 def type_color_markup(
         type_label: str,
         type_category: DisplayTypeCategory,
         config: DisplayConfig
         ):
     '''
     Return type label with markup for color.
     '''
     color = getattr(config, type_category.CONFIG_ATTR)
     if config.display_format in _DISPLAY_FORMAT_HTML:
         return HexColor.format_html(color, type_label)
     elif config.display_format in _DISPLAY_FORMAT_TERMINAL:
         if terminal_ansi():
             return HexColor.format_terminal(color, type_label)
         # if not a compatible terminal, return label unaltered
         return type_label
     raise NotImplementedError('no handling for display format:',
             config.display_format)
Пример #3
0
    def type_color_markup(type_category: tp.Type[DisplayTypeCategory],
                          config: DisplayConfig) -> str:
        '''
        Return a format string for applying color to a type based on type category and config.

        Returns:
            A templated string with a "text" field for formatting.
        '''
        color = getattr(config, type_category.CONFIG_ATTR)
        if config.display_format in _DISPLAY_FORMAT_HTML:
            return HexColor.format_html(color, FORMAT_EMPTY)

        if config.display_format in _DISPLAY_FORMAT_TERMINAL and terminal_ansi(
        ):
            return HexColor.format_terminal(color,
                                            FORMAT_EMPTY)  #pragma: no cover
            # if not a compatible terminal, return label unaltered

        return FORMAT_EMPTY
 def test_format_html_a(self) -> None:
     post = HexColor.format_html('aqua', 'test')
     self.assertEqual(post, '<span style="color: #ffff">test</span>')