From e875bea34eceef2c2a9785a4f771210808ad0cf3 Mon Sep 17 00:00:00 2001 From: mecaneer23 Date: Sun, 31 Dec 2023 15:21:20 -0600 Subject: [PATCH] refactor: add leading underscore to `private` functions --- src/md_to_py.py | 8 ++++---- src/print_todos.py | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/md_to_py.py b/src/md_to_py.py index 736bab0..6e5d8dc 100644 --- a/src/md_to_py.py +++ b/src/md_to_py.py @@ -3,7 +3,7 @@ from typing import Any -def to_lines_split( +def _to_lines_split( lines: list[str], remove: tuple[str, ...] ) -> tuple[int, list[list[str]]]: split: list[list[str]] = [[]] * len(lines) @@ -16,7 +16,7 @@ def to_lines_split( return column_count, split -def to_lines_join(split_lines: list[list[str]], columns: list[list[int]]) -> list[str]: +def _to_lines_join(split_lines: list[list[str]], columns: list[list[int]]) -> list[str]: joined_lines: list[str] = [""] * len(split_lines) for i, line in enumerate(split_lines): for j, char in enumerate(line): @@ -68,7 +68,7 @@ def md_table_to_lines( raise FileNotFoundError("Markdown file not found.") from err # Remove unwanted characters and split each line into a list of values - column_count, split_lines = to_lines_split(lines, remove) + column_count, split_lines = _to_lines_split(lines, remove) # Create lists of columns columns: list[list[Any]] = [[0, []] for _ in range(column_count)] @@ -82,4 +82,4 @@ def md_table_to_lines( split_lines[1] = ["-" * (length + 1) for length, _ in columns] # Join the lines together into a list of formatted strings - return to_lines_join(split_lines, columns) + return _to_lines_join(split_lines, columns) diff --git a/src/print_todos.py b/src/print_todos.py index a6c28ac..62ba7c3 100644 --- a/src/print_todos.py +++ b/src/print_todos.py @@ -24,7 +24,7 @@ T = TypeVar("T") -def get_bullet(indentation_level: int) -> str: +def _get_bullet(indentation_level: int) -> str: symbols = ( "•", "◦", @@ -58,7 +58,7 @@ def make_printable_sublist( return lst[start:end], cursor - start, start -def info_message(stdscr: Any, height: int, width: int) -> None: +def _info_message(stdscr: Any, height: int, width: int) -> None: text = ( "Ndo - an ncurses todo application", "", @@ -71,17 +71,17 @@ def info_message(stdscr: Any, height: int, width: int) -> None: stdscr.addstr(height // 3 + i, (width - maxlen) // 2, line.center(maxlen)) -def get_height_width(stdscr: Any | None, length: int) -> tuple[int, int]: +def _get_height_width(stdscr: Any | None, length: int) -> tuple[int, int]: if stdscr is None: return 0, 0 height, width = stdscr.getmaxyx() if length == 0: - info_message(stdscr, height, width) + _info_message(stdscr, height, width) raise RuntimeError("No todos to display") return height, width -def get_display_string( +def _get_display_string( todos: Todos, position: int, relative: int, @@ -96,7 +96,7 @@ def get_display_string( Chunk(True, todo.indent_level * " "), Chunk(not todo.is_empty() and not SIMPLE_BOXES, todo.get_box()), Chunk(not todo.is_empty() and SIMPLE_BOXES, todo.get_simple_box()), - Chunk(not todo.has_box() and BULLETS, f"{get_bullet(todo.indent_level)} "), + Chunk(not todo.has_box() and BULLETS, f"{_get_bullet(todo.indent_level)} "), Chunk(ENUMERATE and not RELATIVE_ENUMERATE, f"{todos.index(todo) + 1}. "), Chunk(RELATIVE_ENUMERATE, f"{relative + 1}. "), Chunk(True, todo.display_text), @@ -107,7 +107,7 @@ def get_display_string( ].ljust(width - 1, " ") -def print_todo( +def _print_todo( stdscr: Any, todo: Todo, display_string: str, position: int, highlight: range ) -> None: counter = 0 @@ -144,7 +144,7 @@ def print_todos( stdscr: Any, todos: Todos, selected: Cursor, prev_start: int = 0 ) -> int: try: - height, width = get_height_width(stdscr, len(todos)) + height, width = _get_height_width(stdscr, len(todos)) except RuntimeError: return 0 new_todos, temp_selected, prev_start = make_printable_sublist( @@ -155,7 +155,7 @@ def print_todos( [*range(temp_selected - 1, -1, -1), int(selected), *range(0, len(new_todos))], enumerate(new_todos), ): - display_string = get_display_string( + display_string = _get_display_string( todos, position, relative, highlight, (height, width) ) if stdscr is None: @@ -177,7 +177,7 @@ def print_todos( + "\u001b[0m" ) continue - print_todo(stdscr, todo, display_string, position, highlight) + _print_todo(stdscr, todo, display_string, position, highlight) if stdscr is None: return 0 for position in range(height - len(new_todos) - 1):