Skip to content

Commit

Permalink
fix: arrow keys in acurses when get_todo box is open, update todos
Browse files Browse the repository at this point in the history
  • Loading branch information
mecaneer23 committed Jun 10, 2024
1 parent 0b6687a commit 16fdd1b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
18 changes: 14 additions & 4 deletions src/acurses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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."""
Expand Down
5 changes: 3 additions & 2 deletions todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- 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)

0 comments on commit 16fdd1b

Please sign in to comment.