From 313f16f3de5fbd1aaaf6f03ff875a548e093e58d Mon Sep 17 00:00:00 2001 From: mecaneer23 Date: Sun, 10 Dec 2023 17:43:53 -0600 Subject: [PATCH] format: add documentation and remove unused variables --- src/clipboard.py | 22 ++++++++-------------- todo.py | 45 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 16 deletions(-) diff --git a/src/clipboard.py b/src/clipboard.py index 695dcb6..3e78ed5 100644 --- a/src/clipboard.py +++ b/src/clipboard.py @@ -19,14 +19,18 @@ from src.cursor_movement import cursor_down from src.get_args import FILENAME from src.io import update_file -from src.utils import set_header + + +def copy_todo(todos: list[Todo], selected: Cursor, copied_todo: Todo) -> None: + copied_todo.call_init(todos[int(selected)].text) + if CLIPBOARD_EXISTS: + copy(todos[int(selected)].display_text) # pyright: ignore def todo_from_clipboard( - stdscr: Any, todos: list[Todo], selected: int, copied_todo: Todo + todos: list[Todo], selected: int, copied_todo: Todo ) -> list[Todo]: if not CLIPBOARD_EXISTS: - set_header(stdscr, "Clipboard functionality not available") return todos todo = paste() # pyright: ignore if copied_todo.display_text == todo: @@ -38,21 +42,11 @@ def todo_from_clipboard( return todos -def copy_todo( - stdscr: Any, todos: list[Todo], selected: Cursor, copied_todo: Todo -) -> None: - if not CLIPBOARD_EXISTS: - set_header(stdscr, "Clipboard functionality not available") - return - copy(todos[int(selected)].display_text) # pyright: ignore - copied_todo.call_init(todos[int(selected)].text) - - def paste_todo( stdscr: Any, todos: list[Todo], selected: int, copied_todo: Todo ) -> tuple[list[Todo], int]: temp = todos.copy() - todos = todo_from_clipboard(stdscr, todos, selected, copied_todo) + todos = todo_from_clipboard(todos, selected, copied_todo) stdscr.clear() if temp != todos: selected = cursor_down(selected, len(todos)) diff --git a/todo.py b/todo.py index 71c587e..6bfd49c 100755 --- a/todo.py +++ b/todo.py @@ -258,7 +258,7 @@ def handle_delete_todo( stdscr: Any, todos: list[Todo], selected: Cursor, copied_todo: Todo ) -> list[Todo]: if len(todos) > 0 and CLIPBOARD_EXISTS: - copy_todo(stdscr, todos, selected, copied_todo) + copy_todo(todos, selected, copied_todo) return selected.todo_set_to(delete_todo(stdscr, todos, selected)) @@ -450,6 +450,47 @@ def update_modified_time( def main(stdscr: Any) -> int: + """ + The main function for Ndo. Mainly provides keybindings + for the various functions. + + ------- + + Directory of main() variables: + + todos: + main list of Todo objects - initialized with + contents of `FILENAME` + + selected: + main Cursor object for tracking position + within the list of Todo objects. Initialized at 0 + + sublist_top: + Only used in print_todos() to keep track of relative + position and ensure the list renders correctly + + history: + UndoRedo object, stores history for calls to undo/redo + + single_line_state: + Used to insert multiple Todos simultaneously whenever + necessary. This is a "global" object that stores state. + + copied_todo: + A Todo which stores metadata about a todo, such as + color and indentation level. Used for copy/paste + operations. + + edits: + int, used to indicate whether the file was newly + created and modified or not, determines whether + to delete file in quit_program() + + file_modified_time: + Last time of file modification. Used to determine + when to overwrite the save file. + """ init() todos = file_string_to_todos(read_file(FILENAME)) selected = Cursor(0) @@ -497,7 +538,7 @@ def main(stdscr: Any) -> int: Key.p: (handle_paste, "stdscr, todos, selected, copied_todo"), Key.s: (handle_sort_menu, "stdscr, todos, selected"), Key.u: (handle_undo, "selected, history"), - Key.y: (copy_todo, "stdscr, todos, selected, copied_todo"), + Key.y: (copy_todo, "todos, selected, copied_todo"), Key.down: (handle_cursor_down, "todos, selected"), Key.up: (handle_cursor_up, "todos, selected"), Key.delete: (toggle_todo_note, "todos, selected"),