Skip to content

Commit

Permalink
refactor: add trailing commas to satisfy ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
mecaneer23 committed Apr 14, 2024
1 parent cc696a0 commit ef3c9e3
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 45 deletions.
10 changes: 8 additions & 2 deletions src/acurses.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ def getmaxyx(self) -> tuple[int, int]:

def _clear_buffer(self, attr: int = -1) -> None:
self.addstr(
self._stored_y, self._stored_x, "".join(self._buffer), self._stored_attr
self._stored_y,
self._stored_x,
"".join(self._buffer),
self._stored_attr,
)
if attr != -1:
self._stored_attr = attr
Expand Down Expand Up @@ -235,7 +238,10 @@ def color_pair(pair_number: int) -> int:


def newwin(
nlines: int, ncols: int, begin_y: int = 0, begin_x: int = 0
nlines: int,
ncols: int,
begin_y: int = 0,
begin_x: int = 0,
) -> _CursesWindow:
"""
Return a new window, whose left-upper corner is at (begin_y, begin_x),
Expand Down
15 changes: 12 additions & 3 deletions src/clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@


def copy_todo(
stdscr: curses.window, todos: Todos, selected: Cursor, copied_todo: Todo
stdscr: curses.window,
todos: Todos,
selected: Cursor,
copied_todo: Todo,
) -> None:
"""
Set `copied_todo` to be a duplicate of the first selected Todo.
Expand All @@ -42,7 +45,10 @@ def copy_todo(


def _todo_from_clipboard(
stdscr: curses.window, todos: Todos, selected: int, copied_todo: Todo
stdscr: curses.window,
todos: Todos,
selected: int,
copied_todo: Todo,
) -> Todos:
"""Retrieve copied_todo and insert into todo list"""
if not CLIPBOARD_EXISTS:
Expand All @@ -65,7 +71,10 @@ def _todo_from_clipboard(


def paste_todo(
stdscr: curses.window, todos: Todos, selected: Cursor, copied_todo: Todo
stdscr: curses.window,
todos: Todos,
selected: Cursor,
copied_todo: Todo,
) -> Todos:
"""Paste a todo from copied_todo or clipboard if available"""
temp = todos.copy()
Expand Down
3 changes: 2 additions & 1 deletion src/get_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

class GuiType(Enum):
"""Specifiy a GUI type, (curses default tui, ansi custom tui, tkinter gui)"""

CURSES = "curses"
ANSI = "ansi"
TKINTER = "tkinter"
Expand Down Expand Up @@ -74,7 +75,7 @@ def _get_args() -> TypedNamespace:
CONTROLS_END_INDEX,
str(_DEFAULT_HELP_FILE),
frozenset({"<kbd>", "</kbd>"}),
)
),
),
)
parser.add_argument(
Expand Down
30 changes: 23 additions & 7 deletions src/get_todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ class _EditString(NamedTuple):


def hline(
win: curses.window, y_loc: int, x_loc: int, char: str | int, width: int
win: curses.window,
y_loc: int,
x_loc: int,
char: str | int,
width: int,
) -> None:
"""
Display a horizontal line starting at (y_loc, x_loc)
Expand All @@ -49,7 +53,7 @@ def _ensure_valid(win: curses.window) -> None:
if win.getmaxyx()[0] < 3:
raise ValueError(
"Window is too short, it won't be able to\
display the minimum 1 line of text."
display the minimum 1 line of text.",
)
if win.getmaxyx()[0] > 3:
raise NotImplementedError("Multiline text editing is not supported")
Expand Down Expand Up @@ -164,7 +168,11 @@ def _handle_toggle_note_todo(stdscr: curses.window, todo: Todo) -> None:


def _handle_indent_dedent(
stdscr: curses.window, todo: Todo, action: str, chars: _Chars, position: int
stdscr: curses.window,
todo: Todo,
action: str,
chars: _Chars,
position: int,
) -> _EditString:
if action == "indent":
todo.indent()
Expand All @@ -184,7 +192,9 @@ def _handle_end(chars: _Chars) -> _EditString:


def _passthrough(
stdscr: curses.window, edit_string: _EditString, key_name: str
stdscr: curses.window,
edit_string: _EditString,
key_name: str,
) -> _EditString:
alert(stdscr, f"Key `{key_name}` is not supported")
return edit_string
Expand Down Expand Up @@ -300,7 +310,10 @@ def _get_chars_position(


def _set_once(
mode: SingleLineModeImpl, chars: _Chars, position: int, color: Color
mode: SingleLineModeImpl,
chars: _Chars,
position: int,
color: Color,
) -> str:
mode.set_once()
string = "".join(chars)
Expand Down Expand Up @@ -374,7 +387,7 @@ def get_todo(
while True:
if len(chars) + 1 >= win.getmaxyx()[1] - 1:
return todo.set_display_text(
_set_once(mode, chars, position, todo.get_color())
_set_once(mode, chars, position, todo.get_color()),
)
if position == len(chars):
win.addch(1, len(chars) + 1, "█")
Expand All @@ -392,7 +405,10 @@ def get_todo(
mode.toggle()
break
next_step = _get_chars_position(
input_char, (stdscr, win), (chars, position, todo), mode
input_char,
(stdscr, win),
(chars, position, todo),
mode,
)
if next_step is None:
return original
Expand Down
17 changes: 10 additions & 7 deletions src/md_to_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@


def _get_column_widths(
row: str, delimiter: str = "|", strip_spaces: bool = True
row: str,
delimiter: str = "|",
strip_spaces: bool = True,
) -> list[int]:
"""
Return a list of column widths. Columns are determined by a delimiter
Expand All @@ -25,7 +27,7 @@ def _get_column_widths(

if len(delimiter) != 1:
raise ValueError(
f"`delimiter` must be one character, is {len(delimiter)} characters"
f"`delimiter` must be one character, is {len(delimiter)} characters",
)
if delimiter == " ":
raise ValueError("`delimiter` cannot be a space")
Expand Down Expand Up @@ -70,7 +72,7 @@ def _pad_columns(row: str, widths: tuple[int, ...] | int, delimiter: str = "|")

if len(delimiter) != 1:
raise ValueError(
f"`delimiter` must be one character, is {len(delimiter)} characters"
f"`delimiter` must be one character, is {len(delimiter)} characters",
)
if delimiter == " ":
raise ValueError("`delimiter` cannot be a space")
Expand All @@ -80,7 +82,7 @@ def _pad_columns(row: str, widths: tuple[int, ...] | int, delimiter: str = "|")
if isinstance(widths, tuple) and len(widths) != column_count:
raise ValueError(
"`widths` cannot be a tuple of arbitrary length. "
f"Is {len(widths)}, should be {column_count}."
f"Is {len(widths)}, should be {column_count}.",
)

if isinstance(widths, int):
Expand All @@ -103,11 +105,12 @@ def _pad_columns(row: str, widths: tuple[int, ...] | int, delimiter: str = "|")
if widths[column] < non_space_len:
raise ValueError(
f"Width of column `{column}` cannot be less than "
f"{non_space_len}, is {widths[column]}"
f"{non_space_len}, is {widths[column]}",
)
change_amount = widths[column] - non_space_len
for index in range(
prev_delimiter_index, prev_delimiter_index + non_space_len + 1
prev_delimiter_index,
prev_delimiter_index + non_space_len + 1,
):
new_row += row[index]
new_row += " " * change_amount
Expand Down Expand Up @@ -226,7 +229,7 @@ def md_table_to_lines(
map(
lambda iterable: max(iterable) + 2,
zip(*_exclusive_map(_get_column_widths, lines, exclude=frozenset({1}))),
)
),
)

for i, _ in enumerate(lines):
Expand Down
21 changes: 16 additions & 5 deletions src/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@


def _simple_scroll_keybinds(
win: curses.window, cursor: int, len_lines: int, len_new_lines: int
win: curses.window,
cursor: int,
len_lines: int,
len_new_lines: int,
) -> int:
try:
key = win.getch()
Expand All @@ -53,7 +56,8 @@ def _simple_scroll_keybinds(


def _get_move_options(
len_list: int, additional_options: dict[int, Callable[[int], int]]
len_list: int,
additional_options: dict[int, Callable[[int], int]],
) -> dict[int, Callable[[int], int]]:
defaults: dict[int, Callable[[int], int]] = {
Key.k: lambda cursor: cursor - 1,
Expand Down Expand Up @@ -89,7 +93,10 @@ def help_menu(parent_win: curses.window) -> None:
hline(win, 2, 0, curses.ACS_HLINE, win.getmaxyx()[1])
while True:
new_lines, _, _ = make_printable_sublist(
win.getmaxyx()[0] - 4, lines[2:], cursor, 0
win.getmaxyx()[0] - 4,
lines[2:],
cursor,
0,
)
for i, line in enumerate(new_lines):
win.addstr(i + 3, 1, line)
Expand All @@ -115,14 +122,18 @@ def magnify_menu(stdscr: curses.window, todos: Todos, selected: Cursor) -> None:
stdscr.clear()
set_header(stdscr, "Magnifying...")
lines = big( # pyright: ignore
todos[int(selected)].get_display_text(), width=stdscr.getmaxyx()[1]
todos[int(selected)].get_display_text(),
width=stdscr.getmaxyx()[1],
).split("\n")
lines.append("")
lines = [line.ljust(stdscr.getmaxyx()[1] - 2) for line in lines]
cursor = 0
while True:
new_lines, _, _ = make_printable_sublist(
stdscr.getmaxyx()[0] - 2, lines, cursor, 0
stdscr.getmaxyx()[0] - 2,
lines,
cursor,
0,
)
for i, line in enumerate(new_lines):
stdscr.addstr(i + 1, 1, line)
Expand Down
36 changes: 29 additions & 7 deletions src/print_todos.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ def _get_display_string( # pylint: disable=too-many-arguments


def _is_within_strikethrough_range(
counter: int, todo: Todo, display_string: str, window_width: int
counter: int,
todo: Todo,
display_string: str,
window_width: int,
) -> bool:
# make sure to test with -s and -sx
# issue lies with Alacritty terminal
Expand Down Expand Up @@ -213,7 +216,10 @@ def _print_todo(
STRIKETHROUGH
and todo.is_toggled()
and _is_within_strikethrough_range(
counter, todo, display_string, stdscr.getmaxyx()[1]
counter,
todo,
display_string,
stdscr.getmaxyx()[1],
)
):
stdscr.addch(print_position + 1, counter, "\u0336")
Expand All @@ -234,7 +240,10 @@ def _color_to_ansi(color: int) -> str:


def print_todos(
stdscr: curses.window | None, todos: Todos, selected: Cursor, prev_start: int = 0
stdscr: curses.window | None,
todos: Todos,
selected: Cursor,
prev_start: int = 0,
) -> int:
"""
Output list of Todo objects to a curses stdscr or stdout.
Expand All @@ -248,7 +257,10 @@ def print_todos(
except RuntimeError:
return 0
new_todos, temp_selected, prev_start = make_printable_sublist(
height - 1, list(todos), int(selected), prev_start=prev_start
height - 1,
list(todos),
int(selected),
prev_start=prev_start,
)
highlight = range(temp_selected, len(selected) + temp_selected)
print_position = -1
Expand All @@ -261,16 +273,26 @@ def print_todos(
print(
_color_to_ansi(todo.get_color().as_int())
+ _get_display_string(
Todos(new_todos), position, relative, range(0), width, True
)
Todos(new_todos),
position,
relative,
range(0),
width,
True,
),
)
continue
if not todo.is_folded() or DEBUG_FOLD:
_print_todo(
stdscr,
todo,
_get_display_string(
Todos(new_todos), position, relative, highlight, width, False
Todos(new_todos),
position,
relative,
highlight,
width,
False,
),
(position, print_position),
highlight,
Expand Down
17 changes: 13 additions & 4 deletions src/tcurses.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class _CursesWindow: # pylint: disable=too-many-instance-attributes
def _updates_screen(func: Callable[..., None]) -> Callable[..., None]:
@wraps(func)
def _inner(
self: "_CursesWindow", *args: list[Any], **kwargs: dict[Any, Any]
self: "_CursesWindow",
*args: list[Any],
**kwargs: dict[Any, Any],
) -> None:
screen.configure(state="normal")
func(self, *args, **kwargs)
Expand Down Expand Up @@ -49,7 +51,8 @@ def __del__(self):
root.bind("<Key>", stdscr._handle_key)

def _handle_key( # pylint: disable=too-many-return-statements
self, event: "Event[Any]"
self,
event: "Event[Any]",
) -> None:
if self.has_key.get() or event.keysym.endswith(("_R", "_L")):
return
Expand Down Expand Up @@ -172,7 +175,10 @@ def addch(self, y: int, x: int, char: str, attr: int = 0) -> None:
or len(self.buffer) + self.stored_x >= self.width
):
self.addstr(
self.stored_y, self.stored_x, "".join(self.buffer), self.stored_attr
self.stored_y,
self.stored_x,
"".join(self.buffer),
self.stored_attr,
)
self.stored_attr = attr
self.buffer.clear()
Expand Down Expand Up @@ -293,7 +299,10 @@ def color_pair(pair_number: int) -> int:


def newwin(
nlines: int, ncols: int, begin_y: int = 0, begin_x: int = 0
nlines: int,
ncols: int,
begin_y: int = 0,
begin_x: int = 0,
) -> _CursesWindow:
"""
Return a new window, whose left-upper corner is at (begin_y, begin_x),
Expand Down
Loading

0 comments on commit ef3c9e3

Please sign in to comment.