Skip to content

Commit b37e315

Browse files
committed
readkey(): handle CTRL+C
1 parent b8f9748 commit b37e315

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

readchar/_posix_read.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ def readkey() -> str:
2626

2727
c1 = readchar()
2828

29+
if c1 == "\x03":
30+
raise KeyboardInterrupt
31+
2932
if c1 != "\x1B":
3033
return c1
3134

readchar/_win_read.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ def readkey() -> str:
1515

1616
ch = readchar()
1717

18+
if ch == "\x03":
19+
raise KeyboardInterrupt
20+
1821
# if it is a normal character:
1922
if ch not in "\x00\xe0":
2023
return ch

0 commit comments

Comments
 (0)