|
27 | 27 | import select
|
28 | 28 | import signal
|
29 | 29 | import struct
|
30 |
| -import sys |
31 | 30 | import termios
|
32 | 31 | import time
|
33 | 32 | from fcntl import ioctl
|
@@ -206,7 +205,7 @@ def change_encoding(self, encoding: str) -> None:
|
206 | 205 | """
|
207 | 206 | self.encoding = encoding
|
208 | 207 |
|
209 |
| - def refresh(self, screen, c_xy): |
| 208 | + def refresh(self, screen, c_xy, scroll=True): |
210 | 209 | """
|
211 | 210 | Refresh the console screen.
|
212 | 211 |
|
@@ -248,22 +247,23 @@ def refresh(self, screen, c_xy):
|
248 | 247 | newscr = screen[offset : offset + height]
|
249 | 248 |
|
250 | 249 | # use hardware scrolling if we have it.
|
251 |
| - if old_offset > offset and self._ri: |
252 |
| - self.__hide_cursor() |
253 |
| - self.__write_code(self._cup, 0, 0) |
254 |
| - self.__posxy = 0, old_offset |
255 |
| - for i in range(old_offset - offset): |
256 |
| - self.__write_code(self._ri) |
257 |
| - oldscr.pop(-1) |
258 |
| - oldscr.insert(0, "") |
259 |
| - elif old_offset < offset and self._ind: |
260 |
| - self.__hide_cursor() |
261 |
| - self.__write_code(self._cup, self.height - 1, 0) |
262 |
| - self.__posxy = 0, old_offset + self.height - 1 |
263 |
| - for i in range(offset - old_offset): |
264 |
| - self.__write_code(self._ind) |
265 |
| - oldscr.pop(0) |
266 |
| - oldscr.append("") |
| 250 | + if scroll: |
| 251 | + if old_offset > offset and self._ri: |
| 252 | + self.__hide_cursor() |
| 253 | + self.__write_code(self._cup, 0, 0) |
| 254 | + self.__posxy = 0, old_offset |
| 255 | + for i in range(old_offset - offset): |
| 256 | + self.__write_code(self._ri) |
| 257 | + oldscr.pop(-1) |
| 258 | + oldscr.insert(0, "") |
| 259 | + elif old_offset < offset and self._ind: |
| 260 | + self.__hide_cursor() |
| 261 | + self.__write_code(self._cup, self.height - 1, 0) |
| 262 | + self.__posxy = 0, old_offset + self.height - 1 |
| 263 | + for i in range(offset - old_offset): |
| 264 | + self.__write_code(self._ind) |
| 265 | + oldscr.pop(0) |
| 266 | + oldscr.append("") |
267 | 267 |
|
268 | 268 | self.__offset = offset
|
269 | 269 |
|
@@ -310,14 +310,13 @@ def prepare(self):
|
310 | 310 | """
|
311 | 311 | self.__svtermstate = tcgetattr(self.input_fd)
|
312 | 312 | raw = self.__svtermstate.copy()
|
313 |
| - raw.iflag &= ~(termios.BRKINT | termios.INPCK | termios.ISTRIP | termios.IXON) |
| 313 | + raw.iflag &= ~(termios.INPCK | termios.ISTRIP | termios.IXON) |
314 | 314 | raw.oflag &= ~(termios.OPOST)
|
315 | 315 | raw.cflag &= ~(termios.CSIZE | termios.PARENB)
|
316 | 316 | raw.cflag |= termios.CS8
|
317 |
| - raw.lflag &= ~( |
318 |
| - termios.ICANON | termios.ECHO | termios.IEXTEN | (termios.ISIG * 1) |
319 |
| - ) |
320 |
| - raw.cc[termios.VMIN] = 1 |
| 317 | + raw.iflag |= termios.BRKINT |
| 318 | + raw.lflag &= ~(termios.ICANON | termios.ECHO | termios.IEXTEN) |
| 319 | + raw.lflag |= termios.ISIG |
321 | 320 | raw.cc[termios.VTIME] = 0
|
322 | 321 | tcsetattr(self.input_fd, termios.TCSADRAIN, raw)
|
323 | 322 |
|
@@ -370,10 +369,21 @@ def get_event(self, block: bool = True) -> Event | None:
|
370 | 369 | Returns:
|
371 | 370 | - Event: Event object from the event queue.
|
372 | 371 | """
|
| 372 | + if self.wait(timeout=0): |
| 373 | + try: |
| 374 | + chars = os.read(self.input_fd, 1024) |
| 375 | + for char in chars: |
| 376 | + self.push_char(char) |
| 377 | + except OSError as err: |
| 378 | + if err.errno == errno.EINTR: |
| 379 | + raise |
| 380 | + |
373 | 381 | while self.event_queue.empty():
|
374 | 382 | while True:
|
375 | 383 | try:
|
376 |
| - self.push_char(os.read(self.input_fd, 1)) |
| 384 | + chars = os.read(self.input_fd, 1024) |
| 385 | + for char in chars: |
| 386 | + self.push_char(char) |
377 | 387 | except OSError as err:
|
378 | 388 | if err.errno == errno.EINTR:
|
379 | 389 | if not self.event_queue.empty():
|
|
0 commit comments