Skip to content

Commit af26eec

Browse files
authored
Implement flushing in Windows VT100 input (#2001)
1 parent c435303 commit af26eec

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/prompt_toolkit/input/win32.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,11 @@ def detach(self) -> ContextManager[None]:
104104
def read_keys(self) -> list[KeyPress]:
105105
return list(self.console_input_reader.read())
106106

107-
def flush(self) -> None:
108-
pass
107+
def flush_keys(self) -> None:
108+
if self._use_virtual_terminal_input:
109+
return self.console_input_reader.flush_keys()
110+
else:
111+
return []
109112

110113
@property
111114
def closed(self) -> bool:
@@ -640,6 +643,20 @@ def read(self) -> Iterable[KeyPress]:
640643
self._buffer = []
641644
return result
642645

646+
def flush_keys(self) -> list[KeyPress]:
647+
"""
648+
Flush pending keys and return them.
649+
(Used for flushing the 'escape' key.)
650+
"""
651+
# Flush all pending keys. (This is most important to flush the vt100
652+
# 'Escape' key early when nothing else follows.)
653+
self._vt100_parser.flush()
654+
655+
# Return result.
656+
result = self._buffer
657+
self._buffer = []
658+
return result
659+
643660
def _get_keys(
644661
self, read: DWORD, input_records: Array[INPUT_RECORD]
645662
) -> Iterator[str]:

0 commit comments

Comments
 (0)