Now using the style's background color when syntax highlighting.
This commit is contained in:
parent
1a12f6e369
commit
cbba46d5c0
10 changed files with 45 additions and 42 deletions
|
|
@ -1,8 +1,8 @@
|
|||
[0m[38;2;205;40;40m[48;2;0;0;0m[1m#include <iostream>[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
|
||||
[0m[38;2;106;184;37m[48;2;0;0;0m[1musing[0m[38;2;208;208;208m[48;2;0;0;0m [0m[38;2;106;184;37m[48;2;0;0;0m[1mnamespace[0m[38;2;208;208;208m[48;2;0;0;0m std;[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
|
||||
[0m[38;2;106;184;37m[48;2;0;0;0m[1mint[0m[38;2;208;208;208m[48;2;0;0;0m [0m[38;2;68;127;207m[48;2;0;0;0mmain[0m[38;2;208;208;208m[48;2;0;0;0m()[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;208;208;208m[48;2;0;0;0m{[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;208;208;208m[48;2;0;0;0m cout << [0m[38;2;237;157;19m[48;2;0;0;0m"Hello World"[0m[38;2;208;208;208m[48;2;0;0;0m << endl;[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;208;208;208m[48;2;0;0;0m}[0m[38;2;255;255;255m[48;2;0;0;0m [0m
|
||||
[0m[38;2;205;40;40m[48;2;32;32;32m[1m#include <iostream>[0m[38;2;255;255;255m[48;2;32;32;32m [0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;255;255;255m[48;2;32;32;32m [0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;106;184;37m[48;2;32;32;32m[1musing[0m[38;2;208;208;208m[48;2;32;32;32m [0m[38;2;106;184;37m[48;2;32;32;32m[1mnamespace[0m[38;2;208;208;208m[48;2;32;32;32m std;[0m[38;2;255;255;255m[48;2;32;32;32m [0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;255;255;255m[48;2;32;32;32m [0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;106;184;37m[48;2;32;32;32m[1mint[0m[38;2;208;208;208m[48;2;32;32;32m [0m[38;2;68;127;207m[48;2;32;32;32mmain[0m[38;2;208;208;208m[48;2;32;32;32m()[0m[38;2;255;255;255m[48;2;32;32;32m [0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;208;208;208m[48;2;32;32;32m{[0m[38;2;255;255;255m[48;2;32;32;32m [0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;208;208;208m[48;2;32;32;32m cout << [0m[38;2;237;157;19m[48;2;32;32;32m"Hello World"[0m[38;2;208;208;208m[48;2;32;32;32m << endl;[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;208;208;208m[48;2;32;32;32m}[0m[38;2;255;255;255m[48;2;32;32;32m [0m
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
[0m[38;2;106;184;37m[48;2;0;0;0m[1mdef[0m[38;2;208;208;208m[48;2;0;0;0m [0m[38;2;68;127;207m[48;2;0;0;0mhi[0m[38;2;208;208;208m[48;2;0;0;0m():[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;208;208;208m[48;2;0;0;0m [0m[38;2;106;184;37m[48;2;0;0;0m[1mprint[0m[38;2;208;208;208m[48;2;0;0;0m([0m[38;2;237;157;19m[48;2;0;0;0m"hi"[0m[38;2;208;208;208m[48;2;0;0;0m)[0m
|
||||
[0m[38;2;106;184;37m[48;2;32;32;32m[1mdef[0m[38;2;208;208;208m[48;2;32;32;32m [0m[38;2;68;127;207m[48;2;32;32;32mhi[0m[38;2;208;208;208m[48;2;32;32;32m():[0m[38;2;255;255;255m[48;2;32;32;32m [0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;208;208;208m[48;2;32;32;32m [0m[38;2;106;184;37m[48;2;32;32;32m[1mprint[0m[38;2;208;208;208m[48;2;32;32;32m([0m[38;2;237;157;19m[48;2;32;32;32m"hi"[0m[38;2;208;208;208m[48;2;32;32;32m)[0m
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
[0m[38;2;153;153;153m[48;2;0;0;0m[3m#!/usr/bin/perl[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;106;184;37m[48;2;0;0;0m[1mprint[0m[38;2;208;208;208m[48;2;0;0;0m [0m[38;2;237;157;19m[48;2;0;0;0m"Hello, world!\n"[0m[38;2;208;208;208m[48;2;0;0;0m;[0m
|
||||
[0m[38;2;153;153;153m[48;2;32;32;32m[3m#!/usr/bin/perl[0m[38;2;255;255;255m[48;2;32;32;32m [0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;106;184;37m[48;2;32;32;32m[1mprint[0m[38;2;208;208;208m[48;2;32;32;32m [0m[38;2;237;157;19m[48;2;32;32;32m"Hello, world!\n"[0m[38;2;208;208;208m[48;2;32;32;32m;[0m
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
[0m[38;2;106;184;37m[48;2;0;0;0m[1mdef[0m[38;2;208;208;208m[48;2;0;0;0m [0m[38;2;68;127;207m[48;2;0;0;0mhi[0m[38;2;208;208;208m[48;2;0;0;0m():
|
||||
[0m[38;2;106;184;37m[48;2;32;32;32m[1mdef[0m[38;2;208;208;208m[48;2;32;32;32m [0m[38;2;68;127;207m[48;2;32;32;32mhi[0m[38;2;208;208;208m[48;2;32;32;32m():
|
||||
[0m
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
[0m[38;2;106;184;37m[48;2;0;0;0m[1mdef[0m[38;2;208;208;208m[48;2;0;0;0m [0m[38;2;68;127;207m[48;2;0;0;0mhi[0m[38;2;208;208;208m[48;2;0;0;0m():
|
||||
[0m[38;2;106;184;37m[48;2;32;32;32m[1mdef[0m[38;2;208;208;208m[48;2;32;32;32m [0m[38;2;68;127;207m[48;2;32;32;32mhi[0m[38;2;208;208;208m[48;2;32;32;32m():
|
||||
[0m
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
[0m[38;2;208;208;208m[48;2;0;0;0m
|
||||
[0m[38;2;208;208;208m[48;2;32;32;32m
|
||||
[0m
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
[0m[38;2;205;40;40m[48;2;0;0;0m[1m#include <stdio.h>[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
|
||||
[0m[38;2;106;184;37m[48;2;0;0;0m[1mint[0m[38;2;208;208;208m[48;2;0;0;0m [0m[38;2;68;127;207m[48;2;0;0;0mmain[0m[38;2;208;208;208m[48;2;0;0;0m()[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;208;208;208m[48;2;0;0;0m{[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;208;208;208m[48;2;0;0;0m printf([0m[38;2;237;157;19m[48;2;0;0;0m"Hello World\n"[0m[38;2;208;208;208m[48;2;0;0;0m);[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;208;208;208m[48;2;0;0;0m [0m[38;2;106;184;37m[48;2;0;0;0m[1mreturn[0m[38;2;208;208;208m[48;2;0;0;0m [0m[38;2;54;119;169m[48;2;0;0;0m0[0m[38;2;208;208;208m[48;2;0;0;0m;[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;208;208;208m[48;2;0;0;0m}[0m[38;2;255;255;255m[48;2;0;0;0m [0m
|
||||
[0m[38;2;205;40;40m[48;2;32;32;32m[1m#include <stdio.h>[0m[38;2;255;255;255m[48;2;32;32;32m [0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;255;255;255m[48;2;32;32;32m [0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;106;184;37m[48;2;32;32;32m[1mint[0m[38;2;208;208;208m[48;2;32;32;32m [0m[38;2;68;127;207m[48;2;32;32;32mmain[0m[38;2;208;208;208m[48;2;32;32;32m()[0m[38;2;255;255;255m[48;2;32;32;32m [0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;208;208;208m[48;2;32;32;32m{[0m[38;2;255;255;255m[48;2;32;32;32m [0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;208;208;208m[48;2;32;32;32m printf([0m[38;2;237;157;19m[48;2;32;32;32m"Hello World\n"[0m[38;2;208;208;208m[48;2;32;32;32m);[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;208;208;208m[48;2;32;32;32m [0m[38;2;106;184;37m[48;2;32;32;32m[1mreturn[0m[38;2;208;208;208m[48;2;32;32;32m [0m[38;2;54;119;169m[48;2;32;32;32m0[0m[38;2;208;208;208m[48;2;32;32;32m;[0m[38;2;255;255;255m[48;2;32;32;32m [0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;208;208;208m[48;2;32;32;32m}[0m[38;2;255;255;255m[48;2;32;32;32m [0m
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
[0m[38;2;205;40;40m[48;2;0;0;0m[1m#include <iostream>[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
|
||||
[0m[38;2;106;184;37m[48;2;0;0;0m[1musing[0m[38;2;208;208;208m[48;2;0;0;0m [0m[38;2;106;184;37m[48;2;0;0;0m[1mnamespace[0m[38;2;208;208;208m[48;2;0;0;0m std;[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
|
||||
[0m[38;2;106;184;37m[48;2;0;0;0m[1mint[0m[38;2;208;208;208m[48;2;0;0;0m [0m[38;2;68;127;207m[48;2;0;0;0mmain[0m[38;2;208;208;208m[48;2;0;0;0m()[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;208;208;208m[48;2;0;0;0m{[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;208;208;208m[48;2;0;0;0m cout << [0m[38;2;237;157;19m[48;2;0;0;0m"Hello World"[0m[38;2;208;208;208m[48;2;0;0;0m << endl;[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;208;208;208m[48;2;0;0;0m}[0m[38;2;255;255;255m[48;2;0;0;0m [0m
|
||||
[0m[38;2;205;40;40m[48;2;32;32;32m[1m#include <iostream>[0m[38;2;255;255;255m[48;2;32;32;32m [0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;255;255;255m[48;2;32;32;32m [0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;106;184;37m[48;2;32;32;32m[1musing[0m[38;2;208;208;208m[48;2;32;32;32m [0m[38;2;106;184;37m[48;2;32;32;32m[1mnamespace[0m[38;2;208;208;208m[48;2;32;32;32m std;[0m[38;2;255;255;255m[48;2;32;32;32m [0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;255;255;255m[48;2;32;32;32m [0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;106;184;37m[48;2;32;32;32m[1mint[0m[38;2;208;208;208m[48;2;32;32;32m [0m[38;2;68;127;207m[48;2;32;32;32mmain[0m[38;2;208;208;208m[48;2;32;32;32m()[0m[38;2;255;255;255m[48;2;32;32;32m [0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;208;208;208m[48;2;32;32;32m{[0m[38;2;255;255;255m[48;2;32;32;32m [0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;208;208;208m[48;2;32;32;32m cout << [0m[38;2;237;157;19m[48;2;32;32;32m"Hello World"[0m[38;2;208;208;208m[48;2;32;32;32m << endl;[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;208;208;208m[48;2;32;32;32m}[0m[38;2;255;255;255m[48;2;32;32;32m [0m
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
[0m[38;2;205;40;40m[48;2;0;0;0m[1m#ifndef HELLO_H[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;205;40;40m[48;2;0;0;0m[1m#define HELLO_H[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
|
||||
[0m[38;2;106;184;37m[48;2;0;0;0m[1mvoid[0m[38;2;208;208;208m[48;2;0;0;0m [0m[38;2;68;127;207m[48;2;0;0;0mhello[0m[38;2;208;208;208m[48;2;0;0;0m();[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
|
||||
[0m[38;2;205;40;40m[48;2;0;0;0m[1m#endif[0m[38;2;255;255;255m[48;2;0;0;0m [0m
|
||||
[0m[38;2;205;40;40m[48;2;32;32;32m[1m#ifndef HELLO_H[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;205;40;40m[48;2;32;32;32m[1m#define HELLO_H[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;255;255;255m[48;2;32;32;32m [0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;106;184;37m[48;2;32;32;32m[1mvoid[0m[38;2;208;208;208m[48;2;32;32;32m [0m[38;2;68;127;207m[48;2;32;32;32mhello[0m[38;2;208;208;208m[48;2;32;32;32m();[0m[38;2;255;255;255m[48;2;32;32;32m [0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;255;255;255m[48;2;32;32;32m [0m[38;2;255;255;255m[48;2;0;0;0m
|
||||
[0m[38;2;205;40;40m[48;2;32;32;32m[1m#endif[0m[38;2;255;255;255m[48;2;32;32;32m [0m
|
||||
13
tools.py
13
tools.py
|
|
@ -123,24 +123,27 @@ def _run_command(command, status_text=Status.ok):
|
|||
return status, fill3.Text(_fix_input(output))
|
||||
|
||||
|
||||
def _syntax_highlight(text, lexer, style, pad_char=" "):
|
||||
def _syntax_highlight(text, lexer, style):
|
||||
def _parse_rgb(hex_rgb):
|
||||
if hex_rgb.startswith("#"):
|
||||
hex_rgb = hex_rgb[1:]
|
||||
return tuple(eval("0x"+hex_rgb[index:index+2]) for index in [0, 2, 4])
|
||||
def _char_style_for_token_type(token_type):
|
||||
def _char_style_for_token_type(token_type, default_bg_color):
|
||||
token_style = style.style_for_token(token_type)
|
||||
fg_color = (None if token_style["color"] is None
|
||||
else _parse_rgb(token_style["color"]))
|
||||
bg_color = (None if token_style["bgcolor"] is None
|
||||
bg_color = (default_bg_color if token_style["bgcolor"] is None
|
||||
else _parse_rgb(token_style["bgcolor"]))
|
||||
return termstr.CharStyle(fg_color, bg_color, token_style["bold"],
|
||||
token_style["italic"],
|
||||
token_style["underline"])
|
||||
default_bg_color = _parse_rgb(style.background_color)
|
||||
text = fill3.join("",
|
||||
[termstr.TermStr(text, _char_style_for_token_type(token_type))
|
||||
[termstr.TermStr(text, _char_style_for_token_type(token_type,
|
||||
default_bg_color))
|
||||
for token_type, text in pygments.lex(text, lexer)])
|
||||
return fill3.Text(text, pad_char=pad_char)
|
||||
return fill3.Text(text, pad_char=termstr.TermStr(" ").bg_color(
|
||||
default_bg_color))
|
||||
|
||||
|
||||
def _syntax_highlight_using_path(text, path):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue