Esempio n. 1
0
    def __init__(self, style: str = 'default') -> None:
        try:
            Formatter.__init__(self, style=style)
            initialized = True
        except ClassNotFound:
            initialized = False
        if not initialized:
            raise StyleNotFound(f'pygments style "{style}" not found')

        self.styles: Dict[str, Tuple[str, str]] = {}
        for token, token_style in self.style:
            start = []
            end = []
            fstart = fend = ''
            # a style item is a tuple in the following form:
            # colors are readily specified in hex: 'RRGGBB'
            col = token_style['color']
            if col:
                pc = parse_sharp(col)
                if pc is not None:
                    start.append('38' + color_as_sgr(pc))
                    end.append('39')
            if token_style['bold']:
                start.append('1')
                end.append('22')
            if token_style['italic']:
                start.append('3')
                end.append('23')
            if token_style['underline']:
                start.append('4')
                end.append('24')
            if start:
                fstart = '\033[{}m'.format(';'.join(start))
                fend = '\033[{}m'.format(';'.join(end))
            self.styles[token] = fstart, fend
Esempio n. 2
0
    def __init__(self, style='default'):
        try:
            Formatter.__init__(self, style=style)
            initialized = True
        except ClassNotFound:
            initialized = False
        if not initialized:
            raise StyleNotFound('pygments style "{}" not found'.format(style))

        self.styles = {}
        for token, style in self.style:
            start = []
            end = []
            # a style item is a tuple in the following form:
            # colors are readily specified in hex: 'RRGGBB'
            if style['color']:
                start.append('38' + color_as_sgr(parse_sharp(style['color'])))
                end.append('39')
            if style['bold']:
                start.append('1')
                end.append('22')
            if style['italic']:
                start.append('3')
                end.append('23')
            if style['underline']:
                start.append('4')
                end.append('24')
            if start:
                start = '\033[{}m'.format(';'.join(start))
                end = '\033[{}m'.format(';'.join(end))
            self.styles[token] = start or '', end or ''
Esempio n. 3
0
 def __init__(self, style='default'):
     Formatter.__init__(self, style=style)
     self.styles = {}
     for token, style in self.style:
         start = []
         end = []
         # a style item is a tuple in the following form:
         # colors are readily specified in hex: 'RRGGBB'
         if style['color']:
             start.append('38' + color_as_sgr(parse_sharp(style['color'])))
             end.append('39')
         if style['bold']:
             start.append('1')
             end.append('22')
         if style['italic']:
             start.append('3')
             end.append('23')
         if style['underline']:
             start.append('4')
             end.append('24')
         if start:
             start = '\033[{}m'.format(';'.join(start))
             end = '\033[{}m'.format(';'.join(end))
         self.styles[token] = start or '', end or ''