File tree Expand file tree Collapse file tree 2 files changed +10
-13
lines changed Expand file tree Collapse file tree 2 files changed +10
-13
lines changed Original file line number Diff line number Diff line change 11from __future__ import annotations
22
33import re
4- import sys
54from typing import Any , Generator , Iterable
65
76from typing_extensions import Final
4039_re_extended_key : Final = re .compile (r"\x1b\[(?:(\d+)(?:;(\d+))?)?([u~ABCDEFHPQRS])" )
4140
4241
43- WINDOWS = sys .platform == "win32"
44-
4542
4643class XTermParser (Parser [Message ]):
4744 _re_sgr_mouse = re .compile (r"\x1b\[<(\d+);(\d+);(\d+)([Mm])" )
4845
49- def __init__ (self , debug : bool = False , windows : bool = WINDOWS ) -> None :
50- self .windows = windows
46+ def __init__ (self , debug : bool = False ) -> None :
5147 self .last_x = 0
5248 self .last_y = 0
5349 self ._debug_log_file = open ("keys.log" , "at" ) if debug else None
@@ -186,9 +182,8 @@ def send_escape() -> None:
186182 reissue_sequence_as_keys (sequence [1 :])
187183
188184 while True :
189- try :
190- timeout = None if self .windows else constants .ESCAPE_DELAY
191- new_character = yield read1 (timeout )
185+ try :
186+ new_character = yield read1 (constants .ESCAPE_DELAY )
192187 except ParseTimeout :
193188 send_escape ()
194189 break
@@ -198,9 +193,6 @@ def send_escape() -> None:
198193
199194 if new_character == ESC :
200195 send_escape ()
201- if self .windows and len (sequence ) == 1 :
202- # In Windows two escapes are sent when pressing the escape key
203- break
204196 sequence = character
205197 continue
206198 else :
Original file line number Diff line number Diff line change 1212from .._xterm_parser import XTermParser
1313from ..events import Event , Resize
1414from ..geometry import Size
15+ from .. import constants
1516
1617if TYPE_CHECKING :
1718 from ..app import App
@@ -226,7 +227,7 @@ def __init__(
226227
227228 def run (self ) -> None :
228229 exit_requested = self .exit_event .is_set
229- parser = XTermParser ()
230+ parser = XTermParser (debug = constants . DEBUG )
230231
231232 try :
232233 read_count = wintypes .DWORD (0 )
@@ -243,8 +244,12 @@ def run(self) -> None:
243244 append_key = keys .append
244245
245246 while not exit_requested ():
247+
248+ for event in parser .tick ():
249+ self .process_event (event )
250+
246251 # Wait for new events
247- if wait_for_handles ([hIn ], 200 ) is None :
252+ if wait_for_handles ([hIn ], 100 ) is None :
248253 # No new events
249254 continue
250255
You can’t perform that action at this time.
0 commit comments