Coding style
- Rename Editor -> TextEditor - Rename IDE -> TextFilesEditor
This commit is contained in:
parent
fb8b796172
commit
47e303aa3b
3 changed files with 22 additions and 22 deletions
|
|
@ -140,10 +140,10 @@ def overlay_list(bg_list, fg_list, index):
|
||||||
class DiffEditor:
|
class DiffEditor:
|
||||||
|
|
||||||
def __init__(self, left_path, right_path):
|
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.load(left_path)
|
||||||
self.left_editor.view_widget.is_left_scrollbar = True
|
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.right_editor.load(right_path)
|
||||||
self.show_sub_highlights = True
|
self.show_sub_highlights = True
|
||||||
self.previous_term_code = None
|
self.previous_term_code = None
|
||||||
|
|
@ -389,7 +389,7 @@ def check_arguments():
|
||||||
def main():
|
def main():
|
||||||
path_a, path_b = check_arguments()
|
path_a, path_b = check_arguments()
|
||||||
if path_b is None:
|
if path_b is None:
|
||||||
editor_ = editor.Editor(path_a)
|
editor_ = editor.TextEditor(path_a)
|
||||||
editor_.load(path_a)
|
editor_.load(path_a)
|
||||||
else:
|
else:
|
||||||
editor_ = DiffEditor(path_a, path_b)
|
editor_ = DiffEditor(path_a, path_b)
|
||||||
|
|
|
||||||
|
|
@ -346,7 +346,7 @@ def change_action(func):
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
class Editor:
|
class TextEditor:
|
||||||
|
|
||||||
TAB_SIZE = 4
|
TAB_SIZE = 4
|
||||||
THEMES = [pygments.styles.get_style_by_name(style)
|
THEMES = [pygments.styles.get_style_by_name(style)
|
||||||
|
|
@ -619,16 +619,16 @@ class Editor:
|
||||||
return "\n"
|
return "\n"
|
||||||
|
|
||||||
def next_word(self):
|
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()
|
self.cursor_right()
|
||||||
while self._current_character() in Editor.WORD_CHARS:
|
while self._current_character() in TextEditor.WORD_CHARS:
|
||||||
self.cursor_right()
|
self.cursor_right()
|
||||||
|
|
||||||
def previous_word(self):
|
def previous_word(self):
|
||||||
self.cursor_left()
|
self.cursor_left()
|
||||||
while self._current_character() not in Editor.WORD_CHARS:
|
while self._current_character() not in TextEditor.WORD_CHARS:
|
||||||
self.cursor_left()
|
self.cursor_left()
|
||||||
while self._current_character() in Editor.WORD_CHARS:
|
while self._current_character() in TextEditor.WORD_CHARS:
|
||||||
self.cursor_left()
|
self.cursor_left()
|
||||||
self.cursor_right()
|
self.cursor_right()
|
||||||
|
|
||||||
|
|
@ -752,7 +752,7 @@ class Editor:
|
||||||
|
|
||||||
def cycle_syntax_highlighting(self):
|
def cycle_syntax_highlighting(self):
|
||||||
self.theme_index += 1
|
self.theme_index += 1
|
||||||
if self.theme_index == len(Editor.THEMES):
|
if self.theme_index == len(TextEditor.THEMES):
|
||||||
self.theme_index = 0
|
self.theme_index = 0
|
||||||
theme = self.THEMES[self.theme_index]
|
theme = self.THEMES[self.theme_index]
|
||||||
self.text_widget.theme = theme
|
self.text_widget.theme = theme
|
||||||
|
|
@ -800,18 +800,18 @@ class Editor:
|
||||||
|
|
||||||
@change_action
|
@change_action
|
||||||
def indent(self):
|
def indent(self):
|
||||||
indent_ = " " * Editor.TAB_SIZE
|
indent_ = " " * TextEditor.TAB_SIZE
|
||||||
for line_num in self._work_lines():
|
for line_num in self._work_lines():
|
||||||
if self.text_widget[line_num].strip() == "":
|
if self.text_widget[line_num].strip() == "":
|
||||||
self.text_widget[line_num] = ""
|
self.text_widget[line_num] = ""
|
||||||
continue
|
continue
|
||||||
self.text_widget[line_num] = indent_ + self.text_widget[line_num]
|
self.text_widget[line_num] = indent_ + self.text_widget[line_num]
|
||||||
if self.cursor_y == line_num:
|
if self.cursor_y == line_num:
|
||||||
self.cursor_x += Editor.TAB_SIZE
|
self.cursor_x += TextEditor.TAB_SIZE
|
||||||
|
|
||||||
@change_action
|
@change_action
|
||||||
def dedent(self):
|
def dedent(self):
|
||||||
indent_ = " " * Editor.TAB_SIZE
|
indent_ = " " * TextEditor.TAB_SIZE
|
||||||
line_nums = self._work_lines()
|
line_nums = self._work_lines()
|
||||||
if not all(self.text_widget[line_num].startswith(indent_)
|
if not all(self.text_widget[line_num].startswith(indent_)
|
||||||
or self.text_widget[line_num].strip() == "" for line_num in line_nums):
|
or self.text_widget[line_num].strip() == "" for line_num in line_nums):
|
||||||
|
|
@ -819,11 +819,11 @@ class Editor:
|
||||||
return
|
return
|
||||||
for line_num in line_nums:
|
for line_num in line_nums:
|
||||||
if self.cursor_y == line_num:
|
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() == "":
|
if self.text_widget[line_num].strip() == "":
|
||||||
self.text_widget[line_num] = ""
|
self.text_widget[line_num] = ""
|
||||||
continue
|
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):
|
def abort_command(self):
|
||||||
self.mark = None
|
self.mark = None
|
||||||
|
|
@ -853,8 +853,8 @@ class Editor:
|
||||||
if self.parts_widget is not None:
|
if self.parts_widget is not None:
|
||||||
self.parts_widget.on_keyboard_input(term_code)
|
self.parts_widget.on_keyboard_input(term_code)
|
||||||
return
|
return
|
||||||
if action := (Editor.KEY_MAP.get((self.previous_term_code, term_code))
|
if action := (TextEditor.KEY_MAP.get((self.previous_term_code, term_code))
|
||||||
or Editor.KEY_MAP.get(term_code)):
|
or TextEditor.KEY_MAP.get(term_code)):
|
||||||
if action.__name__ == "wrapper":
|
if action.__name__ == "wrapper":
|
||||||
self.add_to_history()
|
self.add_to_history()
|
||||||
try:
|
try:
|
||||||
|
|
@ -984,7 +984,7 @@ class FileBrowser:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
class IDE:
|
class TextFilesEditor:
|
||||||
|
|
||||||
def __init__(self, paths):
|
def __init__(self, paths):
|
||||||
self.paths = paths
|
self.paths = paths
|
||||||
|
|
@ -994,7 +994,7 @@ class IDE:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@functools.cache
|
@functools.cache
|
||||||
def get_editor(path):
|
def get_editor(path):
|
||||||
editor = Editor()
|
editor = TextEditor()
|
||||||
editor.load(path)
|
editor.load(path)
|
||||||
return editor
|
return editor
|
||||||
|
|
||||||
|
|
@ -1044,8 +1044,8 @@ class IDE:
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
ide = IDE(sys.argv[1:])
|
editor = TextFilesEditor(sys.argv[1:])
|
||||||
asyncio.run(fill3.tui("IDE", ide))
|
asyncio.run(fill3.tui("Text Editor", editor))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
|
|
@ -90,10 +90,10 @@ class ExpandTabsTestCase(unittest.TestCase):
|
||||||
self.assertEqual(editor.expandtabs("c\na♓\tb"), "c\na♓ b")
|
self.assertEqual(editor.expandtabs("c\na♓\tb"), "c\na♓ b")
|
||||||
|
|
||||||
|
|
||||||
class EditorTestCase(unittest.TestCase):
|
class TextEditorTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.editor = editor.Editor()
|
self.editor = editor.TextEditor()
|
||||||
|
|
||||||
def _assert_editor(self, expected_text, expected_cursor_position):
|
def _assert_editor(self, expected_text, expected_cursor_position):
|
||||||
cursor_x, cursor_y = expected_cursor_position
|
cursor_x, cursor_y = expected_cursor_position
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue