From 47e303aa3b664fd6e48f95e72c1d71379be37b8b Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Sun, 12 Jun 2022 21:26:58 +1000 Subject: [PATCH] Coding style - Rename Editor -> TextEditor - Rename IDE -> TextFilesEditor --- diff_edit/__init__.py | 6 +++--- diff_edit/editor.py | 34 +++++++++++++++++----------------- tests/editor_test.py | 4 ++-- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/diff_edit/__init__.py b/diff_edit/__init__.py index 3e20247..0e2ab5e 100755 --- a/diff_edit/__init__.py +++ b/diff_edit/__init__.py @@ -140,10 +140,10 @@ def overlay_list(bg_list, fg_list, index): class DiffEditor: def __init__(self, left_path, right_path): - self.left_editor = editor.Editor(is_left_aligned=False) + self.left_editor = editor.TextEditor(is_left_aligned=False) self.left_editor.load(left_path) self.left_editor.view_widget.is_left_scrollbar = True - self.right_editor = editor.Editor() + self.right_editor = editor.TextEditor() self.right_editor.load(right_path) self.show_sub_highlights = True self.previous_term_code = None @@ -389,7 +389,7 @@ def check_arguments(): def main(): path_a, path_b = check_arguments() if path_b is None: - editor_ = editor.Editor(path_a) + editor_ = editor.TextEditor(path_a) editor_.load(path_a) else: editor_ = DiffEditor(path_a, path_b) diff --git a/diff_edit/editor.py b/diff_edit/editor.py index cb50b0a..44e53a0 100755 --- a/diff_edit/editor.py +++ b/diff_edit/editor.py @@ -346,7 +346,7 @@ def change_action(func): return wrapper -class Editor: +class TextEditor: TAB_SIZE = 4 THEMES = [pygments.styles.get_style_by_name(style) @@ -619,16 +619,16 @@ class Editor: return "\n" def next_word(self): - while self._current_character() not in Editor.WORD_CHARS: + while self._current_character() not in TextEditor.WORD_CHARS: self.cursor_right() - while self._current_character() in Editor.WORD_CHARS: + while self._current_character() in TextEditor.WORD_CHARS: self.cursor_right() def previous_word(self): self.cursor_left() - while self._current_character() not in Editor.WORD_CHARS: + while self._current_character() not in TextEditor.WORD_CHARS: self.cursor_left() - while self._current_character() in Editor.WORD_CHARS: + while self._current_character() in TextEditor.WORD_CHARS: self.cursor_left() self.cursor_right() @@ -752,7 +752,7 @@ class Editor: def cycle_syntax_highlighting(self): self.theme_index += 1 - if self.theme_index == len(Editor.THEMES): + if self.theme_index == len(TextEditor.THEMES): self.theme_index = 0 theme = self.THEMES[self.theme_index] self.text_widget.theme = theme @@ -800,18 +800,18 @@ class Editor: @change_action def indent(self): - indent_ = " " * Editor.TAB_SIZE + indent_ = " " * TextEditor.TAB_SIZE for line_num in self._work_lines(): if self.text_widget[line_num].strip() == "": self.text_widget[line_num] = "" continue self.text_widget[line_num] = indent_ + self.text_widget[line_num] if self.cursor_y == line_num: - self.cursor_x += Editor.TAB_SIZE + self.cursor_x += TextEditor.TAB_SIZE @change_action def dedent(self): - indent_ = " " * Editor.TAB_SIZE + indent_ = " " * TextEditor.TAB_SIZE line_nums = self._work_lines() if not all(self.text_widget[line_num].startswith(indent_) or self.text_widget[line_num].strip() == "" for line_num in line_nums): @@ -819,11 +819,11 @@ class Editor: return for line_num in line_nums: if self.cursor_y == line_num: - self.cursor_x = max(self.cursor_x - Editor.TAB_SIZE, 0) + self.cursor_x = max(self.cursor_x - TextEditor.TAB_SIZE, 0) if self.text_widget[line_num].strip() == "": self.text_widget[line_num] = "" continue - self.text_widget[line_num] = self.text_widget[line_num][Editor.TAB_SIZE:] + self.text_widget[line_num] = self.text_widget[line_num][TextEditor.TAB_SIZE:] def abort_command(self): self.mark = None @@ -853,8 +853,8 @@ class Editor: if self.parts_widget is not None: self.parts_widget.on_keyboard_input(term_code) return - if action := (Editor.KEY_MAP.get((self.previous_term_code, term_code)) - or Editor.KEY_MAP.get(term_code)): + if action := (TextEditor.KEY_MAP.get((self.previous_term_code, term_code)) + or TextEditor.KEY_MAP.get(term_code)): if action.__name__ == "wrapper": self.add_to_history() try: @@ -984,7 +984,7 @@ class FileBrowser: return result -class IDE: +class TextFilesEditor: def __init__(self, paths): self.paths = paths @@ -994,7 +994,7 @@ class IDE: @staticmethod @functools.cache def get_editor(path): - editor = Editor() + editor = TextEditor() editor.load(path) return editor @@ -1044,8 +1044,8 @@ class IDE: def main(): - ide = IDE(sys.argv[1:]) - asyncio.run(fill3.tui("IDE", ide)) + editor = TextFilesEditor(sys.argv[1:]) + asyncio.run(fill3.tui("Text Editor", editor)) if __name__ == "__main__": diff --git a/tests/editor_test.py b/tests/editor_test.py index 31e56a0..af01bcf 100755 --- a/tests/editor_test.py +++ b/tests/editor_test.py @@ -90,10 +90,10 @@ class ExpandTabsTestCase(unittest.TestCase): self.assertEqual(editor.expandtabs("c\na♓\tb"), "c\na♓ b") -class EditorTestCase(unittest.TestCase): +class TextEditorTestCase(unittest.TestCase): def setUp(self): - self.editor = editor.Editor() + self.editor = editor.TextEditor() def _assert_editor(self, expected_text, expected_cursor_position): cursor_x, cursor_y = expected_cursor_position