Skip to content

Commit

Permalink
format: add documentation and remove unused variables
Browse files Browse the repository at this point in the history
  • Loading branch information
mecaneer23 committed Dec 10, 2023
1 parent 6a7fbd0 commit 313f16f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 16 deletions.
22 changes: 8 additions & 14 deletions src/clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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))
Expand Down
45 changes: 43 additions & 2 deletions todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"),
Expand Down

0 comments on commit 313f16f

Please sign in to comment.