From e7ea269435a2982724860e3f06784545a11e6904 Mon Sep 17 00:00:00 2001 From: Lasse Schuirmann Date: Wed, 15 Apr 2015 12:40:06 +0200 Subject: [PATCH] ConsoleInteractor: Strip to 79 chars --- coalib/output/ConsoleInteractor.py | 85 ++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 28 deletions(-) diff --git a/coalib/output/ConsoleInteractor.py b/coalib/output/ConsoleInteractor.py index 5da57276af..6cb5e7077b 100644 --- a/coalib/output/ConsoleInteractor.py +++ b/coalib/output/ConsoleInteractor.py @@ -9,9 +9,11 @@ class ConsoleInteractor(Interactor, ConsolePrinter): - STR_GET_VAL_FOR_SETTING = _("Please enter a value for the setting \"{}\" ({}) needed by {}: ") - STR_LINE_DOESNT_EXIST = _("The line belonging to the following result cannot be printed because it refers to a " - "line that doesn't seem to exist in the given file.") + STR_GET_VAL_FOR_SETTING = _("Please enter a value for the setting \"{}\" " + "({}) needed by {}: ") + STR_LINE_DOESNT_EXIST = _("The line belonging to the following result " + "cannot be printed because it refers to a line " + "that doesn't seem to exist in the given file.") STR_PROJECT_WIDE = _("Project wide:") def __init__(self, @@ -31,7 +33,8 @@ def __init__(self, def acquire_settings(self, settings_names_dict): if not isinstance(settings_names_dict, dict): - raise TypeError("The settings_names_dict parameter has to be a dictionary.") + raise TypeError("The settings_names_dict parameter has to be a " + "dictionary.") result = {} for setting_name, arr in settings_names_dict.items(): @@ -52,7 +55,7 @@ def _require_setting(self, setting_name, arr): if len(arr) == 2: needed = arr[1] - else: # Translators: this is the and that connects the last two items of an enumeration (1st, 2nd AND 3rd) + else: needed = ", ".join(arr[1:-1]) + _(" and ") + arr[-1] return input(self.STR_GET_VAL_FOR_SETTING.format(str(setting_name), @@ -60,14 +63,20 @@ def _require_setting(self, setting_name, arr): needed)) def _format_line(self, line, real_nr="", sign="|", mod_nr="", symbol="", ): - return "|{:>4}{}{:>4}|{:1}{}".format(real_nr, sign, mod_nr, symbol, line.rstrip("\n")) + return "|{:>4}{}{:>4}|{:1}{}".format(real_nr, + sign, + mod_nr, + symbol, + line.rstrip("\n")) def _print_result(self, result): - message_string_list = "[{sev}] {bear}:\n{msg}".format(sev=RESULT_SEVERITY.__str__(result.severity), - bear=result.origin, - msg=result.message).split("\n") + message_string_list = "[{sev}] {bear}:\n{msg}".format( + sev=RESULT_SEVERITY.__str__(result.severity), + bear=result.origin, + msg=result.message).split("\n") - return self.print("\n".join([self._format_line(line) for line in message_string_list])) + return self.print("\n".join([self._format_line(line) + for line in message_string_list])) def _print_actions(self, actions): self.print(self._format_line( @@ -84,7 +93,8 @@ def _print_actions(self, actions): def _choose_action(self, actions): while True: for i, action in enumerate(actions): - self.print(self._format_line("{:>2}: {}".format(i + 1, action.desc))) + self.print(self._format_line("{:>2}: {}".format(i + 1, + action.desc))) try: line = self._format_line(_("Please enter the number of the " @@ -116,26 +126,33 @@ def _get_action_info(self, action): return action.name, self.current_section def _print_segregation(self): - self.print(self._format_line(line="", real_nr="...", sign="|", mod_nr="...")) + self.print(self._format_line(line="", + real_nr="...", + sign="|", + mod_nr="...")) def _print_lines(self, file_dict, current_line, result_line, result_file): """ - Prints the lines between the current and the result line. If needed they will be shortened. + Prints the lines between the current and the result line. If needed + they will be shortened. """ line_delta = result_line - current_line if line_delta > self.pre_padding: self._print_segregation() - for i in range(max(result_line - self.pre_padding, 1), result_line + 1): - self.print(self._format_line(line=file_dict[result_file][i - 1], - real_nr=i, - mod_nr=i)) + for i in range(max(result_line - self.pre_padding, 1), + result_line + 1): + self.print(self._format_line( + line=file_dict[result_file][i - 1], + real_nr=i, + mod_nr=i)) else: for i in range(1, line_delta + 1): - self.print(self._format_line(line=file_dict[result_file][current_line + i - 1], - real_nr=current_line + i, - mod_nr=current_line + i)) + self.print(self._format_line( + line=file_dict[result_file][current_line + i - 1], + real_nr=current_line + i, + mod_nr=current_line + i)) def print_results(self, result_list, file_dict): if not isinstance(result_list, list): @@ -143,7 +160,9 @@ def print_results(self, result_list, file_dict): if not isinstance(file_dict, dict): raise TypeError("file_dict should be of type dict") - current_file = False # We can't use None since we need line 109 be executed if file of first result is None + # We can't use None since we need line 109 be executed if file of first + # result is None + current_file = False current_line = 0 for result in sorted(result_list): @@ -151,21 +170,31 @@ def print_results(self, result_list, file_dict): if result.file in file_dict or result.file is None: current_file = result.file current_line = 0 - self.print("\n\n{}".format(current_file if current_file is not None else self.STR_PROJECT_WIDE)) + self.print("\n\n{}".format(current_file + if current_file is not None + else self.STR_PROJECT_WIDE)) else: - self.log_printer.warn(_("A result ({}) cannot be printed because it refers to a file that doesn't" - " seem to exist.").format(str(result))) + self.log_printer.warn(_("A result ({}) cannot be printed " + "because it refers to a file that " + "doesn't seem to " + "exist.").format(str(result))) continue if result.line_nr is not None: if current_file is None: - raise AssertionError("A result with a line_nr should also have a file.") + raise AssertionError("A result with a line_nr should also " + "have a file.") if result.line_nr < current_line: # pragma: no cover - raise AssertionError("The sorting of the results doesn't work correctly.") + raise AssertionError("The sorting of the results doesn't " + "work correctly.") if len(file_dict[result.file]) < result.line_nr - 1: - self.print(self._format_line(line=self.STR_LINE_DOESNT_EXIST)) + self.print(self._format_line( + line=self.STR_LINE_DOESNT_EXIST)) else: - self._print_lines(file_dict, current_line, result.line_nr, result.file) + self._print_lines(file_dict, + current_line, + result.line_nr, + result.file) current_line = result.line_nr self.print_result(result, file_dict)