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> #include <iostream> 
 
using namespace std; using namespace std; 
 
int main() int main() 
{ { 
 cout << "Hello World" << endl;  cout << "Hello World" << endl;
}  } 

View file

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

View file

@ -1,2 +1,2 @@
#!/usr/bin/perl #!/usr/bin/perl 
print "Hello, world!\n"; 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> #include <stdio.h> 
 
int main() int main() 
{ { 
 printf("Hello World\n");  printf("Hello World\n");
 return 0;  return 0; 
}  } 

View file

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

View file

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

View file

@ -123,24 +123,27 @@ def _run_command(command, status_text=Status.ok):
return status, fill3.Text(_fix_input(output)) 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): def _parse_rgb(hex_rgb):
if hex_rgb.startswith("#"): if hex_rgb.startswith("#"):
hex_rgb = hex_rgb[1:] hex_rgb = hex_rgb[1:]
return tuple(eval("0x"+hex_rgb[index:index+2]) for index in [0, 2, 4]) 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) token_style = style.style_for_token(token_type)
fg_color = (None if token_style["color"] is None fg_color = (None if token_style["color"] is None
else _parse_rgb(token_style["color"])) 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"])) else _parse_rgb(token_style["bgcolor"]))
return termstr.CharStyle(fg_color, bg_color, token_style["bold"], return termstr.CharStyle(fg_color, bg_color, token_style["bold"],
token_style["italic"], token_style["italic"],
token_style["underline"]) token_style["underline"])
default_bg_color = _parse_rgb(style.background_color)
text = fill3.join("", 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)]) 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): def _syntax_highlight_using_path(text, path):