Skip to content

Commit

Permalink
keys: move common defintions to _base_key file
Browse files Browse the repository at this point in the history
  • Loading branch information
Cube707 committed Aug 13, 2022
1 parent 10a7998 commit 2661999
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 71 deletions.
34 changes: 34 additions & 0 deletions readchar/_base_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# common
LF = "\x0a"
CR = "\x0d"
SPACE = "\x20"
ESC = "\x1b"
TAB = "\x09"

# CTRL
CTRL_A = "\x01"
CTRL_B = "\x02"
CTRL_C = "\x03"
CTRL_D = "\x04"
CTRL_E = "\x05"
CTRL_F = "\x06"
CTRL_G = "\x07"
CTRL_H = "\x08"
CTRL_I = TAB
CTRL_J = LF
CTRL_K = "\x0b"
CTRL_L = "\x0c"
CTRL_M = CR
CTRL_N = "\x0e"
CTRL_O = "\x0f"
CTRL_P = "\x10"
CTRL_Q = "\x11"
CTRL_R = "\x12"
CTRL_S = "\x13"
CTRL_T = "\x14"
CTRL_U = "\x15"
CTRL_V = "\x16"
CTRL_W = "\x17"
CTRL_X = "\x18"
CTRL_Y = "\x19"
CTRL_Z = "\x1a"
43 changes: 8 additions & 35 deletions readchar/_posix_key.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,8 @@
from ._base_key import *


# common
LF = "\x0a"
CR = "\x0d"
ENTER = LF
BACKSPACE = "\x7f"
SPACE = "\x20"
ESC = "\x1b"
TAB = "\x09"

# CTRL
CTRL_A = "\x01"
CTRL_B = "\x02"
CTRL_C = "\x03"
CTRL_D = "\x04"
CTRL_E = "\x05"
CTRL_F = "\x06"
CTRL_G = "\x07"
CTRL_H = "\x08"
CTRL_I = TAB
CTRL_J = LF
CTRL_K = "\x0b"
CTRL_L = "\x0c"
CTRL_M = CR
CTRL_N = "\x0e"
CTRL_O = "\x0f"
CTRL_P = "\x10"
CTRL_Q = "\x11"
CTRL_R = "\x12"
CTRL_S = "\x13"
CTRL_T = "\x14"
CTRL_U = "\x15"
CTRL_V = "\x16"
CTRL_W = "\x17"
CTRL_X = "\x18"
CTRL_Y = "\x19"
CTRL_Z = "\x1a"

# cursors
UP = "\x1b\x5b\x41"
Expand All @@ -44,7 +13,6 @@
# navigation keys
INSERT = "\x1b\x5b\x32\x7e"
SUPR = "\x1b\x5b\x33\x7e"
DELETE = SUPR
HOME = "\x1b\x5b\x48"
END = "\x1b\x5b\x46"
PAGE_UP = "\x1b\x5b\x35\x7e"
Expand Down Expand Up @@ -75,3 +43,8 @@

# CTRL+ALT+_
CTRL_ALT_A = "\x1b\x01"


# aliases
ENTER = LF
DELETE = SUPR
45 changes: 9 additions & 36 deletions readchar/_win_key.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,5 @@
# common
LF = "\x0a"
CR = "\x0d"
ENTER = CR
BACKSPACE = "\x08"
SPACE = "\x20"
ESC = "\x1b"
TAB = "\x09"
from ._base_key import *

# CTRL
CTRL_A = "\x01"
CTRL_B = "\x02"
CTRL_C = "\x03"
CTRL_D = "\x04"
CTRL_E = "\x05"
CTRL_F = "\x06"
CTRL_G = "\x07"
CTRL_H = BACKSPACE
CTRL_I = TAB
CTRL_J = LF
CTRL_K = "\x0b"
CTRL_L = "\x0c"
CTRL_M = CR
CTRL_N = "\x0e"
CTRL_O = "\x0f"
CTRL_P = "\x10"
CTRL_Q = "\x11"
CTRL_R = "\x12"
CTRL_S = "\x13"
CTRL_T = "\x14"
CTRL_U = "\x15"
CTRL_V = "\x16"
CTRL_W = "\x17"
CTRL_X = "\x18"
CTRL_Y = "\x19"
CTRL_Z = "\x1a"

# Windows uses scan codes for extended characters. This dictionary
# translates the second half of the scan codes of special Keys
Expand All @@ -44,6 +10,9 @@
# or
# https://www.freepascal.org/docs-html/rtl/keyboard/kbdscancode.html

# common
BACKSPACE = "\x08"

# cursors
UP = "\x00\x48"
DOWN = "\x00\x50"
Expand All @@ -53,7 +22,6 @@
# navigation keys
INSERT = "\x00\x52"
SUPR = "\x00\x53"
DELETE = SUPR
HOME = "\x00\x47"
END = "\x00\x4f"
PAGE_UP = "\x00\x49"
Expand Down Expand Up @@ -82,3 +50,8 @@
# CTRL_ALT_[A-Z],
# CTRL_ALT_SUPR,
# CTRL-F1


# aliases
ENTER = CR
DELETE = SUPR
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ exclude =
show-source = true
statistics = true
count = true
per-file-ignores =
readchar/*_key.py:F403,F405

[tool.coverage.run]
omit = tests/*
Expand Down

0 comments on commit 2661999

Please sign in to comment.