Skip to content

Commit

Permalink
refactor: add leading underscore to private functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mecaneer23 committed Dec 31, 2023
1 parent 3fedb8c commit e875bea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/md_to_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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)]
Expand All @@ -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)
20 changes: 10 additions & 10 deletions src/print_todos.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
T = TypeVar("T")


def get_bullet(indentation_level: int) -> str:
def _get_bullet(indentation_level: int) -> str:
symbols = (
"•",
"◦",
Expand Down Expand Up @@ -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",
"",
Expand All @@ -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,
Expand All @@ -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),
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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:
Expand All @@ -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):
Expand Down

0 comments on commit e875bea

Please sign in to comment.