Python pygments.formatters.Terminal256Formatter() Examples
The following are 14
code examples of pygments.formatters.Terminal256Formatter().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pygments.formatters
, or try the search function
.
Example #1
Source File: cli.py From jc with MIT License | 8 votes |
def json_out(data, pretty=False, mono=False, piped_out=False): if not mono and not piped_out: # set colors class JcStyle(Style): styles = set_env_colors() if pretty: print(highlight(json.dumps(data, indent=2), JsonLexer(), Terminal256Formatter(style=JcStyle))[0:-1]) else: print(highlight(json.dumps(data), JsonLexer(), Terminal256Formatter(style=JcStyle))[0:-1]) else: if pretty: print(json.dumps(data, indent=2)) else: print(json.dumps(data))
Example #2
Source File: style_transfer.py From style_transfer with MIT License | 6 votes |
def printargs(): """Prints out all command-line parameters.""" switch = {BGColor.LIGHT: 'xcode', BGColor.DARK: 'vim', BGColor.UNKNOWN: 'default'} style = switch[terminal_bg()] pprint = print try: import pygments from pygments.lexers import Python3Lexer from pygments.formatters import Terminal256Formatter pprint = partial(pygments.highlight, lexer=Python3Lexer(), formatter=Terminal256Formatter(style=style), outfile=sys.stdout) except ImportError: pass print('Parameters:') for key in sorted(ARGS): v = repr(getattr(ARGS, key)) print('% 16s: ' % key, end='') pprint(v) print()
Example #3
Source File: arm.py From deen with Apache License 2.0 | 6 votes |
def _syntax_highlighting(self, data): try: from pygments import highlight from pygments.lexers import GasLexer from pygments.formatters import TerminalFormatter, Terminal256Formatter from pygments.styles import get_style_by_name style = get_style_by_name('colorful') import curses curses.setupterm() if curses.tigetnum('colors') >= 256: FORMATTER = Terminal256Formatter(style=style) else: FORMATTER = TerminalFormatter() # When pygments is available, we # can print the disassembled # instructions with syntax # highlighting. data = highlight(data, GasLexer(), FORMATTER) except ImportError: pass finally: data = data.encode() return data
Example #4
Source File: prettier.py From python-devtools with MIT License | 5 votes |
def get_pygments(): try: import pygments from pygments.lexers import PythonLexer from pygments.formatters import Terminal256Formatter except ImportError: # pragma: no cover return None, None, None else: return pygments, PythonLexer(), Terminal256Formatter(style='vim')
Example #5
Source File: tbv.py From tbvaccine with MIT License | 5 votes |
def __init__(self, code_dir=None, isolate=True, show_vars=True, max_length=120): # The directory we're interested in. if not code_dir: code_dir = os.getcwd() self._code_dir = code_dir # Whether to print interesting lines in color or not. If False, # all lines are printed in color. self._isolate = isolate # Our current state. self._state = State.no_idea # The filename of the line we're currently printing. self._file = None # The buffer that we use to build up the output in. self._buffer = "" # Whether to print variables for stack frames. self._show_vars = show_vars # Max length of printed variable lines self._max_length = max_length self._load_config() self.pygments_lexer = PythonLexer() self.pygments_formatter = TerminalFormatter(style=self._config.get("style", "color_scheme"))
Example #6
Source File: __init__.py From cs with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _format_json(data, theme): """Pretty print a dict as a JSON, with colors if pygments is present.""" output = json.dumps(data, indent=2, sort_keys=True) if pygments and sys.stdout.isatty(): style = get_style_by_name(theme) formatter = Terminal256Formatter(style=style) return pygments.highlight(output, JsonLexer(), formatter) return output
Example #7
Source File: run_commands.py From stackhut with Apache License 2.0 | 5 votes |
def call_service(self, msg): r = stackhut_api_call('run', msg) result = highlight(json.dumps(r, indent=4), JsonLexer(), Terminal256Formatter()) log.info("Service {} returned - \n{}".format(utils.SERVER_URL, result))
Example #8
Source File: run_commands.py From stackhut with Apache License 2.0 | 5 votes |
def test_interactive(self, service_name): # get the contract contract = rpc.load_contract_file() interfaces = contract.interfaces log.info("Service has {} interface(s) - {}".format(len(interfaces), list(interfaces.keys()))) for i in contract.interfaces.values(): log.info("Interface '{}' has {} function(s):". format(i.name, len(i.functions))) for f in i.functions.values(): log.info("\t{}".format(rpc.render_signature(f))) while True: (iface, fname) = prompt('Enter Interface.Function to test: ').split('.') f = contract.interface(iface).function(fname) values = [prompt('Enter "{}" value for {}: '.format(p.type, p.name)) for p in f.params] eval_values = [json.loads(x) for x in values] if utils.VERBOSE: pp_values = highlight(json.dumps(eval_values, indent=4), JsonLexer(), Terminal256Formatter()) log.debug("Calling {} with {}".format(f.full_name, pp_values)) msg = { "service": service_name, "request": { "method": f.full_name, "params": eval_values } } self.call_service(msg)
Example #9
Source File: main_config.py From evo with GNU General Public License v3.0 | 5 votes |
def log_info_dict_json(data_str, colored=True): data_str = json.dumps(data_str, indent=4, sort_keys=True) if colored and os.name != "nt": data_str = highlight(data_str, lexers.JsonLexer(), formatters.Terminal256Formatter(style="monokai")) logger.info(data_str)
Example #10
Source File: x86.py From deen with Apache License 2.0 | 5 votes |
def _syntax_highlighting(self, data): try: from pygments import highlight from pygments.lexers import NasmLexer, GasLexer from pygments.formatters import TerminalFormatter, Terminal256Formatter from pygments.styles import get_style_by_name style = get_style_by_name('colorful') import curses curses.setupterm() if curses.tigetnum('colors') >= 256: FORMATTER = Terminal256Formatter(style=style) else: FORMATTER = TerminalFormatter() if self.ks.syntax == keystone.KS_OPT_SYNTAX_INTEL: lexer = NasmLexer() else: lexer = GasLexer() # When pygments is available, we # can print the disassembled # instructions with syntax # highlighting. data = highlight(data, lexer, FORMATTER) except ImportError: pass finally: data = data.encode() return data
Example #11
Source File: show_code.py From lddmm-ot with MIT License | 5 votes |
def show_code(func): if type(func) is str : code = func else : code = inspect.getsourcelines(func)[0] code = ''.join(code) print(highlight(code, PythonLexer(), Terminal256Formatter()))
Example #12
Source File: sqlformatter.py From sqlformatter with MIT License | 5 votes |
def __init__(self, *args, **kwargs): self.highlight = kwargs.pop('highlight', True) self.style = kwargs.pop('style', 'default') self.parse = kwargs.pop('parse', True) self.reindent = kwargs.pop('reindent', True) self.keyword_case = kwargs.pop('keyword_case', 'upper') self._lexer = SqlLexer() self._formatter = Terminal256Formatter(style=self.style) super(SqlFormatter, self).__init__(*args, **kwargs)
Example #13
Source File: main_config.py From evo_slam with GNU General Public License v3.0 | 5 votes |
def log_info_dict_json(data_str, colored=True): data_str = json.dumps(data_str, indent=4, sort_keys=True) if colored and os.name != "nt": data_str = highlight(data_str, lexers.JsonLexer(), formatters.Terminal256Formatter(style="monokai")) logger.info(data_str)
Example #14
Source File: __init__.py From ansible-inventory with GNU General Public License v3.0 | 5 votes |
def __print_vars( self, e_vars, pre_middle_var, pre_last_var ): e_line = '' e_vars_keys = [] for v in e_vars: e_vars_keys.append( v ) if e_vars_keys: e_vars_keys.sort() last_key = e_vars_keys[-1] longest_key = self.C(e_vars_keys[0]).__len__() for v in e_vars_keys: if self.C(v).__len__() > longest_key: longest_key = self.C(v).__len__() for v in e_vars_keys: if v == last_key: e_line+= pre_last_var else: e_line+= pre_middle_var var_line = '╴%%-%ds = %%s\n' % longest_key if isinstance( e_vars[v], dict ): if self.color.use_colors: from pygments import highlight, lexers, formatters var_dict = highlight(json.dumps(e_vars[v], sort_keys=True, indent=2), lexers.JsonLexer(), formatters.Terminal256Formatter(style='vim')) var_dict = var_dict.replace("\n", "\n │ │ ") else: var_dict = json.dumps(e_vars[v], sort_keys=True, indent=2).replace("\n", "\n │ │ ") e_line+= var_line % (self.C(v), var_dict) else: e_line+= var_line % (self.C(v), e_vars[v]) return e_line