Skip to content

Commit

Permalink
refactor: use existing key definitions rather than redefining constants
Browse files Browse the repository at this point in the history
  • Loading branch information
mecaneer23 committed Jun 11, 2024
1 parent 16fdd1b commit ec21458
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/acurses.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from time import time as now
from typing import Any, Callable, TypeVar, overload

from src.keys import Key

try:
from termios import TCSADRAIN, tcgetattr, tcsetattr # type: ignore
from tty import setcbreak # type: ignore
Expand Down Expand Up @@ -66,16 +68,15 @@ def _write(string: str) -> int:

_ANSI_RESET = "\033[0m"

# Key names for the values of this dict can be found in src.keys
_KEYPAD_KEYS: dict[str, set[int]] = {
"27-91-65": {259},
"27-91-66": {258},
"27-91-67": {261},
"27-91-68": {260},
"27-91-51-126": {330},
"27-91-53-126": {339}, # page up
"27-91-54-126": {338}, # page down
"27-91-90": {353},
"27-91-65": {Key.up},
"27-91-66": {Key.down},
"27-91-67": {Key.right},
"27-91-68": {Key.left},
"27-91-51-126": {Key.delete},
"27-91-53-126": {Key.page_up},
"27-91-54-126": {Key.page_down},
"27-91-90": {Key.shift_tab},
}
_SHORT_TIME_SECONDS = 0.01

Expand Down
4 changes: 4 additions & 0 deletions src/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ class Key:
backspace_ = 127
down = 258
up = 259
left = 260
right = 261
backspace__ = 263
delete = 330
page_down = 338
page_up = 339
shift_tab_windows = 351
shift_tab = 353
alt_j_windows = 426
Expand Down

0 comments on commit ec21458

Please sign in to comment.