示例#1
0
 def init(self,
          term_colors=0,
          renderer=None,
          palette=None,
          theme=None,
          fix_all=False,
          fix_text=False):
     self.term_colors = term_colors or terminal_colors(sys.stdout)
     self.renderer = renderer or select_render_engine(self.term_colors)
     self.palette = palette or select_palette(self.term_colors)
     self.theme = theme(palette=self.palette,
                        renderer=self.renderer) if theme else BasicTheme(
             palette=self.palette,
             renderer=self.renderer)
     self._need_text_fix = self.need_text_fix()
     self._need_emoji_fix = self.need_emoji_fix()
     if fix_all and self._need_emoji_fix:
         fix_text = True
         try:
             from emoji2text import emoji2text
             self.fix_emoji = emoji2text
         except ImportError:
             raise ImportError('Please install python package: emoji2text')
     if fix_text and self._need_text_fix:
         try:
             from ftfy import fix_text
             self.fix_text = fix_text
         except ImportError:
             raise ImportError('Please install python package: ftfy')
示例#2
0
 def id256(self):
     if terminal_colors() == 0:
         return self.copy(self._body)
     if self.key:
         color = parse_color(self.key)
     else:
         color = parse_color(self._body)
     ansi = int(rgb2short(color.hex_l)[0])
     match = ColorPoint(source=color, target=color, ansi=ansi)
     text = self._render(self._body, fg=match)
     return self.copy(text)
示例#3
0
 def m(self):
     if terminal_colors() == 0:
         return self.copy(self._body)
     text = self._body
     text = sty.ef.dim + text + sty.rs.all
     return self.copy(text)