From 16fdd1b4c2e5577201ad8c8e2d9bc561c22b3908 Mon Sep 17 00:00:00 2001 From: Mecaneer23 <74385377+Mecaneer23@users.noreply.github.com> Date: Mon, 10 Jun 2024 18:55:14 -0500 Subject: [PATCH] fix: arrow keys in acurses when get_todo box is open, update todos --- src/acurses.py | 18 ++++++++++++++---- todo.txt | 5 +++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/acurses.py b/src/acurses.py index 06f7c59..4c4c4b4 100644 --- a/src/acurses.py +++ b/src/acurses.py @@ -67,7 +67,7 @@ def _write(string: str) -> int: _ANSI_RESET = "\033[0m" # Key names for the values of this dict can be found in src.keys -_SPECIAL_KEYS: dict[str, set[int]] = { +_KEYPAD_KEYS: dict[str, set[int]] = { "27-91-65": {259}, "27-91-66": {258}, "27-91-67": {261}, @@ -135,6 +135,8 @@ def __init__( self._stored_keys: Queue[int] = Queue() + self._keypad: bool = False + def getch(self) -> int: """ Get a character. Note that the integer returned @@ -163,9 +165,8 @@ def getch(self) -> int: if char not in current: current.append(char) chars = tuple(current) - for key in ({} if not _GETCH.is_blocking() else _SPECIAL_KEYS).get( - "-".join(map(str, chars)), chars - ): + keys = _KEYPAD_KEYS if _GETCH.is_blocking() and self._keypad else {} + for key in keys.get("-".join(map(str, chars)), chars): self._stored_keys.put(key) return self._stored_keys.get() @@ -305,6 +306,15 @@ def timeout(self, delay: int) -> None: """ raise NotImplementedError("timeout") + def keypad(self, flag: bool = False) -> None: + """ + If flag is True, escape sequences generated by some + keys (keypad, function keys) will be interpreted by + curses. If flag is False, escape sequences will be + left as is in the input stream. + """ + self._keypad = flag + def use_default_colors() -> None: """Allow using default colors. Not yet implemented.""" diff --git a/todo.txt b/todo.txt index 3c8e288..18631ba 100644 --- a/todo.txt +++ b/todo.txt @@ -9,6 +9,7 @@ -b in _updates_cursor if pos + count > len(todos) IndexOutOfBounds error -b how can we save folded state when todos are pulled from file and list is recreated? - refactor: simplify redundancy between _get_display_string and _print_todo (strikethrough) -- fix: arrow keys in acurses when get_todo box is open - fix: reimplement acurses support for windows -- fix: if holding down a key in acurses, make sure it doesn't stay pressed longer than it should (i.e. holding j key) \ No newline at end of file +- fix: if holding down a key in acurses, make sure it doesn't stay pressed longer than it should (i.e. holding j key) +- feat!: migrate get_todo from keypad(0) to keypad(1) using a large dict similar to the one in main() in todo.py +- fix: artifacting when using arrow keys in acurses with keypad off (namely when get_todo box is open) \ No newline at end of file