def _draw_line(self, current_line: AbsoluteLine) -> None: y = current_line - self.point.top_line # type: ScreenLine line = self.lines[current_line - 1] clear_eol = '\x1b[m\x1b[K' sgr0 = '\x1b[m' plain = unstyled(line) selection_sgr = '\x1b[38{};48{}m'.format( color_as_sgr(self.opts.selection_foreground), color_as_sgr(self.opts.selection_background)) start, end = self._start_end() # anti-flicker optimization if self.mark_type.line_inside_region(current_line, start, end): self.cmd.set_cursor_position(0, y) self.print('{}{}'.format(selection_sgr, plain), end=clear_eol) return self.cmd.set_cursor_position(0, y) self.print('{}{}'.format(sgr0, line), end=clear_eol) if self.mark_type.line_outside_region(current_line, start, end): return start_x, end_x = self.mark_type.selection_in_line( current_line, start, end, wcswidth(plain)) if start_x is None or end_x is None: return line_slice, half = string_slice(plain, start_x, end_x) self.cmd.set_cursor_position(start_x - (1 if half else 0), y) self.print('{}{}'.format(selection_sgr, line_slice), end='')
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
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 ''
def set_formats(opts): formats['text'] = '38' + color_as_sgr( opts.foreground) + ';48' + color_as_sgr(opts.background) formats['margin'] = '38' + color_as_sgr( opts.margin_fg) + ';48' + color_as_sgr(opts.margin_bg) formats['title'] = '38' + color_as_sgr( opts.title_fg) + ';48' + color_as_sgr(opts.title_bg) + ';1'
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 ''
def set_formats(opts: DiffOptions) -> None: formats['text'] = '48' + color_as_sgr(opts.background) formats['title'] = '38' + color_as_sgr(opts.title_fg) + ';48' + color_as_sgr(opts.title_bg) + ';1' formats['margin'] = '38' + color_as_sgr(opts.margin_fg) + ';48' + color_as_sgr(opts.margin_bg) formats['added_margin'] = '38' + color_as_sgr(opts.margin_fg) + ';48' + color_as_sgr(opts.added_margin_bg) formats['removed_margin'] = '38' + color_as_sgr(opts.margin_fg) + ';48' + color_as_sgr(opts.removed_margin_bg) formats['added'] = '48' + color_as_sgr(opts.added_bg) formats['removed'] = '48' + color_as_sgr(opts.removed_bg) formats['filler'] = '48' + color_as_sgr(opts.filler_bg) formats['margin_filler'] = '48' + color_as_sgr(opts.margin_filler_bg or opts.filler_bg) formats['hunk_margin'] = '38' + color_as_sgr(opts.margin_fg) + ';48' + color_as_sgr(opts.hunk_margin_bg) formats['hunk'] = '38' + color_as_sgr(opts.margin_fg) + ';48' + color_as_sgr(opts.hunk_bg) formats['removed_highlight'] = '48' + color_as_sgr(opts.highlight_removed_bg) formats['added_highlight'] = '48' + color_as_sgr(opts.highlight_added_bg)
def set_formats(opts): formats['text'] = '38' + color_as_sgr( opts.foreground) + ';48' + color_as_sgr(opts.background) formats['title'] = '38' + color_as_sgr( opts.title_fg) + ';48' + color_as_sgr(opts.title_bg) + ';1' formats['margin'] = '38' + color_as_sgr( opts.margin_fg) + ';48' + color_as_sgr(opts.margin_bg) formats['added_margin'] = '38' + color_as_sgr( opts.margin_fg) + ';48' + color_as_sgr(opts.added_margin_bg) formats['removed_margin'] = '38' + color_as_sgr( opts.margin_fg) + ';48' + color_as_sgr(opts.removed_margin_bg) formats['added'] = '38' + color_as_sgr( opts.foreground) + ';48' + color_as_sgr(opts.added_bg) formats['removed'] = '38' + color_as_sgr( opts.foreground) + ';48' + color_as_sgr(opts.removed_bg) formats['filler'] = '48' + color_as_sgr(opts.filler_bg) formats['hunk_margin'] = '38' + color_as_sgr( opts.margin_fg) + ';48' + color_as_sgr(opts.hunk_margin_bg) formats['hunk'] = '38' + color_as_sgr( opts.margin_fg) + ';48' + color_as_sgr(opts.hunk_bg)