New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gsoc: Fix colors from the output #4627

Merged
merged 2 commits into from Aug 24, 2017
Jump to file or symbol
Failed to load files and symbols.
+40 −22
Diff settings

Always

Just for now

Next

Fix colors from the output

Fixes #4625
  • Loading branch information...
Nosferatul committed Aug 7, 2017
commit d03303c00d5e6afa543cb173288b3908a8945428
@@ -58,11 +58,8 @@ class NoColorStyle(Style):
}
def highlight_text(no_color, text, lexer=TextLexer(), style=None):
if style:
formatter = TerminalTrueColorFormatter(style=style)
else:
formatter = TerminalTrueColorFormatter()
def highlight_text(no_color, text, style, lexer=TextLexer()):
formatter = TerminalTrueColorFormatter(style=style)
if no_color:
formatter = TerminalTrueColorFormatter(style=NoColorStyle)
return highlight(text, lexer, formatter)[:-1]
@@ -239,21 +236,24 @@ def print_lines(console_printer,
printed_chars = 0
if i == sourcerange.start.line and sourcerange.start.column:
console_printer.print(highlight_text(
no_color, line[:sourcerange.start.column - 1], lexer), end='')
no_color, line[:sourcerange.start.column - 1],
BackgroundMessageStyle, lexer), end='')
printed_chars = sourcerange.start.column - 1
if i == sourcerange.end.line and sourcerange.end.column:
console_printer.print(highlight_text(
no_color, line[printed_chars:sourcerange.end.column - 1],
lexer, BackgroundSourceRangeStyle), end='')
BackgroundSourceRangeStyle, lexer), end='')
console_printer.print(highlight_text(
no_color, line[sourcerange.end.column - 1:], lexer), end='')
no_color, line[sourcerange.end.column - 1:],
BackgroundSourceRangeStyle, lexer), end='')
console_printer.print('')
else:
console_printer.print(highlight_text(
no_color, line[printed_chars:], lexer), end='')
no_color, line[printed_chars:], BackgroundMessageStyle, lexer),
end='')

This comment has been minimized.

@yukiisbored

yukiisbored Aug 15, 2017

Member

Wouldn't it be better if we add this to highlight_text itself?

@yukiisbored

yukiisbored Aug 15, 2017

Member

Wouldn't it be better if we add this to highlight_text itself?

This comment has been minimized.

@yukiisbored

yukiisbored Aug 15, 2017

Member

Since logically we want to end the highlight at some point and not have it bled to the other lines.

@yukiisbored

yukiisbored Aug 15, 2017

Member

Since logically we want to end the highlight at some point and not have it bled to the other lines.

This comment has been minimized.

@Nosferatul

Nosferatul Aug 15, 2017

Member

so, i think style variable from highlight_text should be non-optional, right?

@Nosferatul

Nosferatul Aug 15, 2017

Member

so, i think style variable from highlight_text should be non-optional, right?

This comment has been minimized.

@yukiisbored

yukiisbored Aug 15, 2017

Member

Well, we wanna make sure by doing that doesn't break anything.

@yukiisbored

yukiisbored Aug 15, 2017

Member

Well, we wanna make sure by doing that doesn't break anything.

console_printer.print('')
@@ -303,7 +303,7 @@ def print_result(console_printer,
color=RESULT_SEVERITY_COLORS[result.severity])
lexer = TextLexer()
result.message = highlight_text(no_color, result.message,
lexer, BackgroundMessageStyle)
BackgroundMessageStyle, lexer)
console_printer.print(format_lines(result.message, symbol='!'))
if interactive:
@@ -35,6 +35,8 @@
from pygments.filters import VisibleWhitespaceFilter
from pygments.lexers import TextLexer
from pygments.style import Style
from pygments.token import Token
STR_GET_VAL_FOR_SETTING = ('Please enter a value for the setting \"{}\" ({}) '
@@ -45,6 +47,12 @@
STR_PROJECT_WIDE = 'Project wide:'
class NoColorStyle(Style):
styles = {
Token: 'noinherit'
}
class TestAction(ResultAction):
def apply(self, result, original_file_dict, file_diff_dict, param):
@@ -656,7 +664,8 @@ def test_print_results_for_file(self):
filename
[ ]2 {0}
**** SpaceConsistencyBear [Section: | Severity: NORMAL] ****
! ! {1}\n""".format(highlight_text(self.no_color, 'line 2', self.lexer),
! ! {1}\n""".format(highlight_text(self.no_color, 'line 2', NoColorStyle,
self.lexer),
highlight_text(self.no_color,
'Trailing whitespace found',
style=BackgroundMessageStyle), ''),
@@ -681,7 +690,8 @@ def test_print_results_for_file(self):
filename
[ ]5 {0}
**** SpaceConsistencyBear [Section: | Severity: NORMAL] ****
! ! {1}\n""".format(highlight_text(self.no_color, 'line 5', self.lexer),
! ! {1}\n""".format(highlight_text(self.no_color, 'line 5', NoColorStyle,
self.lexer),
highlight_text(self.no_color,
'Trailing whitespace found',
style=BackgroundMessageStyle), ''),
@@ -716,11 +726,13 @@ def test_print_results_sorting(self):
file
[ ]5 {2}
**** SpaceConsistencyBear [Section: | Severity: NORMAL] ****
! ! {1}\n""".format(highlight_text(self.no_color, '\t', self.lexer),
! ! {1}\n""".format(highlight_text(self.no_color, '\t', NoColorStyle,
self.lexer),
highlight_text(self.no_color,
'Trailing whitespace found',
style=BackgroundMessageStyle),
highlight_text(self.no_color, 'line 5\t', self.lexer)),
highlight_text(self.no_color, 'line 5\t',
NoColorStyle, self.lexer)),
stdout.getvalue())
def test_print_results_multiple_ranges(self):
@@ -753,13 +765,18 @@ def test_print_results_multiple_ranges(self):
[ ]6 li{0}{4}
[ ]7 li{0}{5}
**** ClangCloneDetectionBear [Section: | Severity: NORMAL] ****
! ! {6}\n""".format(highlight_text(self.no_color, 'ne', self.lexer,
BackgroundSourceRangeStyle),
highlight_text(self.no_color, ' 1', self.lexer),
highlight_text(self.no_color, ' 3', self.lexer),
highlight_text(self.no_color, ' 5', self.lexer),
highlight_text(self.no_color, ' 6', self.lexer),
highlight_text(self.no_color, ' 7', self.lexer),
! ! {6}\n""".format(highlight_text(self.no_color, 'ne',
BackgroundSourceRangeStyle, self.lexer),
highlight_text(self.no_color, ' 1', NoColorStyle,
self.lexer),
highlight_text(self.no_color, ' 3', NoColorStyle,
self.lexer),
highlight_text(self.no_color, ' 5', NoColorStyle,
self.lexer),
highlight_text(self.no_color, ' 6', NoColorStyle,
self.lexer),
highlight_text(self.no_color, ' 7', NoColorStyle,
self.lexer),
highlight_text(self.no_color, 'Clone Found',
style=BackgroundMessageStyle), ' '),
stdout.getvalue())
@@ -812,7 +829,8 @@ def test_print_results_missing_line(self):
'**** t [Section: | Severity: NORMAL] ****\n'
'! ! {1}\n'.format(
highlight_text(self.no_color,
'line 5', self.lexer),
'line 5', NoColorStyle,
self.lexer),
highlight_text(self.no_color, 'msg',
style=BackgroundMessageStyle),
STR_LINE_DOESNT_EXIST, ' '),
ProTip! Use n and p to navigate between commits in a pull request.