Now using the style's background color when syntax highlighting.

This commit is contained in:
Andrew Hamilton 2016-02-18 19:58:46 +00:00
parent 1a12f6e369
commit cbba46d5c0
10 changed files with 45 additions and 42 deletions

View file

@ -1,8 +1,8 @@
#include <iostream>
using namespace std;
int main()
{
 cout << "Hello World" << endl;
} 
#include <iostream> 
 
using namespace std; 
 
int main() 
{ 
 cout << "Hello World" << endl;
} 

View file

@ -1,2 +1,2 @@
def hi():
 print("hi")
def hi(): 
 print("hi")

View file

@ -1,2 +1,2 @@
#!/usr/bin/perl
print "Hello, world!\n";
#!/usr/bin/perl 
print "Hello, world!\n";

View file

@ -1,2 +1,2 @@
def hi():
def hi():


View file

@ -1,2 +1,2 @@
def hi():
def hi():


View file

@ -1,2 +1,2 @@




View file

@ -1,7 +1,7 @@
#include <stdio.h>
int main()
{
 printf("Hello World\n");
 return 0;
} 
#include <stdio.h> 
 
int main() 
{ 
 printf("Hello World\n");
 return 0; 
} 

View file

@ -1,8 +1,8 @@
#include <iostream>
using namespace std;
int main()
{
 cout << "Hello World" << endl;
} 
#include <iostream> 
 
using namespace std; 
 
int main() 
{ 
 cout << "Hello World" << endl;
} 

View file

@ -1,6 +1,6 @@
#ifndef HELLO_H
#define HELLO_H
void hello();
#endif 
#ifndef HELLO_H
#define HELLO_H
 
void hello(); 
 
#endif 

View file

@ -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):
@ -302,7 +305,7 @@ def python_unittests(path):
status = Status.ok if returncode == 0 else Status.problem
native_style = pygments.styles.get_style_by_name("native")
return status, _syntax_highlight(stderr, _python_console_lexer,
native_style)
native_style)
else:
return Status.not_applicable, fill3.Text("No tests.")
python_unittests.dependencies = {"python", "python3"}