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: Change output #4369

Merged
merged 1 commit into from Jun 22, 2017
Jump to file or symbol
Failed to load files and symbols.
+130 −147
Diff settings

Always

Just for now

CLI: Improve results output

Change "| |" to "[  ]".
Use "**** <bear> [Section: <x>] ****]".
Delete multiple lines from the output of a file.
Delete executing section.
  • Loading branch information...
Nosferatul committed Jun 17, 2017
commit d75d10ab7bb9be4abe7d14f201afc748fb1b96d6
View
@@ -110,7 +110,6 @@ def run_coala(console_printer=None,
section['default_actions'] = '*: ShowPatchAction'
section['show_result_on_top'] = 'yeah'
print_section_beginning(section)
section_result = execute_section(
section=section,
global_bear_list=global_bears[section_name],
@@ -8,7 +8,6 @@
import readline # pylint: disable=unused-import
except ImportError: # pragma: no cover
pass
import os.path
from coalib.misc.DictUtilities import inverse_dicts
from coalib.bearlib.spacing.SpacingHelper import SpacingHelper
@@ -87,8 +86,9 @@ def highlight_text(no_color, text, lexer=TextLexer(), style=None):
DIFF_EXCERPT_MAX_SIZE = 4
def format_lines(lines, line_nr=''):
return '\n'.join('|{:>4}| {}'.format(line_nr, line)
def format_lines(lines, symbol='', line_nr=''):
def sym(x): return ']' if x is '[' else x
return '\n'.join('{}{:>5}{} {}'.format(symbol, sym(symbol), line_nr, line)
for line in lines.rstrip('\n').split('\n'))
@@ -179,9 +179,6 @@ def print_lines(console_printer,
no_color = not console_printer.print_colored
for i in range(sourcerange.start.line, sourcerange.end.line + 1):
# Print affected file's line number in the sidebar.
console_printer.print(format_lines(lines='', line_nr=i),
color=FILE_LINES_COLOR,
end='')
line = file_dict[sourcerange.file][i - 1].rstrip('\n')
try:
@@ -206,12 +203,7 @@ def print_lines(console_printer,
lexer, BackgroundSourceRangeStyle), end='')
console_printer.print(highlight_text(
no_color, line[sourcerange.end.column - 1:], lexer), end='')
console_printer.print('')
else:
console_printer.print(highlight_text(
no_color, line[printed_chars:], lexer), end='')
no_color, line[sourcerange.end.column - 1:], lexer), end='')
console_printer.print('')
@@ -241,13 +233,21 @@ def print_result(console_printer,
'class.')
return
console_printer.print(format_lines('[{sev}] {bear}:'.format(
sev=RESULT_SEVERITY.__str__(result.severity), bear=result.origin)),
if hasattr(section, 'name'):
console_printer.print('\n**** {bear} [Section: {section}] ****\n'
.format(bear=result.origin, section=section.name),
color=RESULT_SEVERITY_COLORS[result.severity])
else:
console_printer.print('\n**** {bear} [Section: {section}] ****\n'
.format(bear=result.origin, section='<empty>'),
color=RESULT_SEVERITY_COLORS[result.severity])
console_printer.print(format_lines('[Severity: {sev}]'.format(
sev=RESULT_SEVERITY.__str__(result.severity)), '!'),
color=RESULT_SEVERITY_COLORS[result.severity])
lexer = TextLexer()
result.message = highlight_text(no_color, result.message,
lexer, BackgroundMessageStyle)
console_printer.print(format_lines(result.message))
console_printer.print(format_lines(result.message, symbol='!'))
if interactive:
cli_actions = CLI_ACTIONS
@@ -285,7 +285,7 @@ def print_diffs_info(diffs, printer):
format_lines('+{additions} -{deletions} in {file}'.format(
file=filename,
additions=additions,
deletions=deletions)),
deletions=deletions), '!'),
color='green')
@@ -452,13 +452,12 @@ def print_affected_lines(console_printer, file_dict, sourcerange):
:param sourcerange: The SourceRange object referring to the related
lines to print.
"""
console_printer.print('\n' + os.path.relpath(sourcerange.file),
color=FILE_NAME_COLOR)
if sourcerange.start.line is not None:
if len(file_dict[sourcerange.file]) < sourcerange.end.line:
console_printer.print(format_lines(lines=STR_LINE_DOESNT_EXIST,
line_nr=sourcerange.end.line))
line_nr=sourcerange.end.line,
symbol='!'))
else:
print_lines(console_printer,
file_dict,
@@ -544,7 +543,7 @@ def get_action_info(section, action, failed_actions):
if param_name not in section or action.name in failed_actions:
question = format_lines(
"Please enter a value for the parameter '{}' ({}): "
.format(param_name, params[param_name][0]))
.format(param_name, params[param_name][0]), symbol='!')
section.append(Setting(param_name, input(question)))
return action.name, section
@@ -560,15 +559,14 @@ def choose_action(console_printer, actions):
:return: Return choice of action of user.
"""
while True:
console_printer.print(format_lines('*0: ' +
'Do nothing'))
console_printer.print(format_lines('{}'.format('*0: Do nothing'),
symbol='['))
for i, action in enumerate(actions, 1):
console_printer.print(format_lines('{:>2}: {}'.format(
i,
action.desc)))
i, action.desc), symbol='['))
try:
line = format_lines(STR_ENTER_NUMBER)
line = format_lines(STR_ENTER_NUMBER, symbol='[')
choice = input(line)
if not choice:
@@ -579,7 +577,8 @@ def choose_action(console_printer, actions):
except ValueError:
pass
console_printer.print(format_lines('Please enter a valid number.'))
console_printer.print(format_lines(
'Please enter a valid letter.', symbol='['))
def print_actions(console_printer, section, actions, failed_actions):
@@ -646,7 +645,7 @@ def ask_for_action_and_apply(console_printer,
file_diff_dict,
section)
console_printer.print(
format_lines(chosen_action.SUCCESS_MESSAGE),
format_lines(chosen_action.SUCCESS_MESSAGE, symbol='['),
color=SUCCESS_COLOR)
failed_actions.discard(action_name)
except Exception as exception: # pylint: disable=broad-except
@@ -819,7 +818,8 @@ def show_language_bears_capabilities(language_bears_capabilities,
else:
for language, capabilities in language_bears_capabilities.items():
if capabilities[0]:
console_printer.print('coala can do the following for ', end='')
console_printer.print(
'coala can do the following for ', end='')
console_printer.print(language.upper(), color='blue')
console_printer.print(' Can detect only: ', end='')
console_printer.print(
@@ -10,20 +10,19 @@
from coala_utils.decorators import enforce_signature
def format_line(line, real_nr='', sign='|', mod_nr='', symbol='', ):
return '|{:>4}{}{:>4}|{:1}{}'.format(real_nr,
sign,
mod_nr,
symbol,
line.rstrip('\n'))
def format_line(line, real_nr='', sign=']', mod_nr='', symbol='', ):
return '[{:>4}{}{:1}{}'.format(real_nr,
sign,
symbol,
line.rstrip('\n'))
def print_from_name(printer, line):
printer.print(format_line(line, real_nr='----'), color='red')
def print_to_name(printer, line):
printer.print(format_line(line, mod_nr='++++'), color='green')
printer.print(format_line(line, real_nr='++++'), color='green')
def print_beautified_diff(difflines, printer):
@@ -40,24 +39,14 @@ def print_beautified_diff(difflines, printer):
elif line.startswith('+++'):
print_to_name(printer, line[4:])
elif line.startswith('+'):
printer.print(format_line(line[1:],
mod_nr=current_line_added,
symbol='+'),
color='green')
print_to_name(printer, line[1:])
current_line_added += 1
elif line.startswith('-'):
printer.print(format_line(line[1:],
real_nr=current_line_subtracted,
symbol='-'),
color='red')
printer.print(format_line
('Line affected {}'.format(current_line_added)))
printer.print(format_line(''))
print_from_name(printer, line[1:])
current_line_subtracted += 1
else:
printer.print(format_line(line[1:],
real_nr=current_line_subtracted,
mod_nr=current_line_added,
symbol=' '))
current_line_subtracted += 1
current_line_added += 1
class ShowPatchAction(ResultAction):
View
@@ -54,7 +54,7 @@ def test_find_no_issues(self, debug=False):
'--settings',
'use_spaces=True',
debug=debug)
self.assertIn('Executing section cli', stdout)
self.assertEqual('', stdout)
if not debug:
self.assertFalse(stderr)
else:
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.