Skip to content

Commit 2661999

Browse files
committed
keys: move common defintions to _base_key file
1 parent 10a7998 commit 2661999

File tree

4 files changed

+53
-71
lines changed

4 files changed

+53
-71
lines changed

readchar/_base_key.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# common
2+
LF = "\x0a"
3+
CR = "\x0d"
4+
SPACE = "\x20"
5+
ESC = "\x1b"
6+
TAB = "\x09"
7+
8+
# CTRL
9+
CTRL_A = "\x01"
10+
CTRL_B = "\x02"
11+
CTRL_C = "\x03"
12+
CTRL_D = "\x04"
13+
CTRL_E = "\x05"
14+
CTRL_F = "\x06"
15+
CTRL_G = "\x07"
16+
CTRL_H = "\x08"
17+
CTRL_I = TAB
18+
CTRL_J = LF
19+
CTRL_K = "\x0b"
20+
CTRL_L = "\x0c"
21+
CTRL_M = CR
22+
CTRL_N = "\x0e"
23+
CTRL_O = "\x0f"
24+
CTRL_P = "\x10"
25+
CTRL_Q = "\x11"
26+
CTRL_R = "\x12"
27+
CTRL_S = "\x13"
28+
CTRL_T = "\x14"
29+
CTRL_U = "\x15"
30+
CTRL_V = "\x16"
31+
CTRL_W = "\x17"
32+
CTRL_X = "\x18"
33+
CTRL_Y = "\x19"
34+
CTRL_Z = "\x1a"

readchar/_posix_key.py

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,8 @@
1+
from ._base_key import *
2+
3+
14
# common
2-
LF = "\x0a"
3-
CR = "\x0d"
4-
ENTER = LF
55
BACKSPACE = "\x7f"
6-
SPACE = "\x20"
7-
ESC = "\x1b"
8-
TAB = "\x09"
9-
10-
# CTRL
11-
CTRL_A = "\x01"
12-
CTRL_B = "\x02"
13-
CTRL_C = "\x03"
14-
CTRL_D = "\x04"
15-
CTRL_E = "\x05"
16-
CTRL_F = "\x06"
17-
CTRL_G = "\x07"
18-
CTRL_H = "\x08"
19-
CTRL_I = TAB
20-
CTRL_J = LF
21-
CTRL_K = "\x0b"
22-
CTRL_L = "\x0c"
23-
CTRL_M = CR
24-
CTRL_N = "\x0e"
25-
CTRL_O = "\x0f"
26-
CTRL_P = "\x10"
27-
CTRL_Q = "\x11"
28-
CTRL_R = "\x12"
29-
CTRL_S = "\x13"
30-
CTRL_T = "\x14"
31-
CTRL_U = "\x15"
32-
CTRL_V = "\x16"
33-
CTRL_W = "\x17"
34-
CTRL_X = "\x18"
35-
CTRL_Y = "\x19"
36-
CTRL_Z = "\x1a"
376

387
# cursors
398
UP = "\x1b\x5b\x41"
@@ -44,7 +13,6 @@
4413
# navigation keys
4514
INSERT = "\x1b\x5b\x32\x7e"
4615
SUPR = "\x1b\x5b\x33\x7e"
47-
DELETE = SUPR
4816
HOME = "\x1b\x5b\x48"
4917
END = "\x1b\x5b\x46"
5018
PAGE_UP = "\x1b\x5b\x35\x7e"
@@ -75,3 +43,8 @@
7543

7644
# CTRL+ALT+_
7745
CTRL_ALT_A = "\x1b\x01"
46+
47+
48+
# aliases
49+
ENTER = LF
50+
DELETE = SUPR

readchar/_win_key.py

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,5 @@
1-
# common
2-
LF = "\x0a"
3-
CR = "\x0d"
4-
ENTER = CR
5-
BACKSPACE = "\x08"
6-
SPACE = "\x20"
7-
ESC = "\x1b"
8-
TAB = "\x09"
1+
from ._base_key import *
92

10-
# CTRL
11-
CTRL_A = "\x01"
12-
CTRL_B = "\x02"
13-
CTRL_C = "\x03"
14-
CTRL_D = "\x04"
15-
CTRL_E = "\x05"
16-
CTRL_F = "\x06"
17-
CTRL_G = "\x07"
18-
CTRL_H = BACKSPACE
19-
CTRL_I = TAB
20-
CTRL_J = LF
21-
CTRL_K = "\x0b"
22-
CTRL_L = "\x0c"
23-
CTRL_M = CR
24-
CTRL_N = "\x0e"
25-
CTRL_O = "\x0f"
26-
CTRL_P = "\x10"
27-
CTRL_Q = "\x11"
28-
CTRL_R = "\x12"
29-
CTRL_S = "\x13"
30-
CTRL_T = "\x14"
31-
CTRL_U = "\x15"
32-
CTRL_V = "\x16"
33-
CTRL_W = "\x17"
34-
CTRL_X = "\x18"
35-
CTRL_Y = "\x19"
36-
CTRL_Z = "\x1a"
373

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

13+
# common
14+
BACKSPACE = "\x08"
15+
4716
# cursors
4817
UP = "\x00\x48"
4918
DOWN = "\x00\x50"
@@ -53,7 +22,6 @@
5322
# navigation keys
5423
INSERT = "\x00\x52"
5524
SUPR = "\x00\x53"
56-
DELETE = SUPR
5725
HOME = "\x00\x47"
5826
END = "\x00\x4f"
5927
PAGE_UP = "\x00\x49"
@@ -82,3 +50,8 @@
8250
# CTRL_ALT_[A-Z],
8351
# CTRL_ALT_SUPR,
8452
# CTRL-F1
53+
54+
55+
# aliases
56+
ENTER = CR
57+
DELETE = SUPR

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ exclude =
6767
show-source = true
6868
statistics = true
6969
count = true
70+
per-file-ignores =
71+
readchar/*_key.py:F403,F405
7072

7173
[tool.coverage.run]
7274
omit = tests/*

0 commit comments

Comments
 (0)