示例#1
0
    def transform_attrs(self, attrs):
        min_brightness = to_float(self.min_brightness)
        max_brightness = to_float(self.max_brightness)
        assert 0 <= min_brightness <= 1
        assert 0 <= max_brightness <= 1

        # Don't do anything if the whole brightness range is acceptable.
        # This also avoids turning ansi colors into RGB sequences.
        if min_brightness == 0.0 and max_brightness == 1.0:
            return attrs

        # If a foreground color is given without a background color.
        no_background = not attrs.bgcolor or attrs.bgcolor == 'default'
        has_fgcolor = attrs.color and attrs.color != 'ansidefault'

        if has_fgcolor and no_background:
            # Calculate new RGB values.
            r, g, b = self._color_to_rgb(attrs.color)
            hue, brightness, saturation = rgb_to_hls(r, g, b)
            brightness = self._interpolate_brightness(brightness,
                                                      min_brightness,
                                                      max_brightness)
            r, g, b = hls_to_rgb(hue, brightness, saturation)
            new_color = '%02x%02x%02x' % (int(r * 255), int(
                g * 255), int(b * 255))

            attrs = attrs._replace(color=new_color)

        return attrs
    def transform_attrs(self, attrs):
        min_brightness = to_float(self.min_brightness)
        max_brightness = to_float(self.max_brightness)
        assert 0 <= min_brightness <= 1
        assert 0 <= max_brightness <= 1

        # Don't do anything if the whole brightness range is acceptable.
        # This also avoids turning ansi colors into RGB sequences.
        if min_brightness == 0.0 and max_brightness == 1.0:
            return attrs

        # If a foreground color is given without a background color.
        no_background = not attrs.bgcolor or attrs.bgcolor == 'default'
        has_fgcolor = attrs.color and attrs.color != 'ansidefault'

        if has_fgcolor and no_background:
            # Calculate new RGB values.
            r, g, b = self._color_to_rgb(attrs.color)
            hue, brightness, saturation = rgb_to_hls(r, g, b)
            brightness = self._interpolate_brightness(
                brightness, min_brightness, max_brightness)
            r, g, b = hls_to_rgb(hue, brightness, saturation)
            new_color = '%02x%02x%02x' % (
                int(r * 255),
                int(g * 255),
                int(b * 255))

            attrs = attrs._replace(color=new_color)

        return attrs
示例#3
0
 def invalidation_hash(self):
     return ('adjust-brightness', to_float(self.min_brightness),
             to_float(self.max_brightness))
 def invalidation_hash(self) -> Hashable:
     return (
         "adjust-brightness",
         to_float(self.min_brightness),
         to_float(self.max_brightness),
     )
 def invalidation_hash(self):
     return (
         'adjust-brightness',
         to_float(self.min_brightness),
         to_float(self.max_brightness)
     )