Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit559c547

Browse files
committed
fix: refresh line-by-line instead of clearing entire screen
1 parent1b7c1b8 commit559c547

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

‎Lib/_pyrepl/console.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def __init__(
7171
self.output_fd=f_out.fileno()
7272

7373
@abstractmethod
74-
defrefresh(self,screen:list[str],xy:tuple[int,int])->None: ...
74+
defrefresh(self,screen:list[str],xy:tuple[int,int],clear_to_end:bool=False)->None: ...
7575

7676
@abstractmethod
7777
defprepare(self)->None: ...
@@ -82,6 +82,9 @@ def restore(self) -> None: ...
8282
@abstractmethod
8383
defmove_cursor(self,x:int,y:int)->None: ...
8484

85+
@abstractmethod
86+
defreset_cursor(self)->None: ...
87+
8588
@abstractmethod
8689
defset_cursor_vis(self,visible:bool)->None: ...
8790

‎Lib/_pyrepl/reader.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,17 @@ def refresh(self) -> None:
641641
self.console.refresh(self.screen,self.cxy)
642642
self.dirty=False
643643

644+
defhandle_resize(self)->None:
645+
"""Handle a resize event."""
646+
self.console.height,self.console.width=self.console.getheightwidth()
647+
self.console.reset_cursor()
648+
ns=len(self.console.screen)* ["\000"*self.console.width]
649+
self.console.screen=ns
650+
651+
self.screen=self.calc_screen()
652+
self.console.refresh(self.screen,self.cxy,clear_to_end=True)
653+
self.dirty=True
654+
644655
defdo_cmd(self,cmd:tuple[str,list[str]])->None:
645656
"""`cmd` is a tuple of "event_name" and "event", which in the current
646657
implementation is always just the "buffer" which happens to be a list
@@ -716,9 +727,7 @@ def handle1(self, block: bool = True) -> bool:
716727
elifevent.evt=="scroll":
717728
self.refresh()
718729
elifevent.evt=="resize":
719-
self.console.height,self.console.width=self.console.getheightwidth()
720-
self.console.clear()
721-
self.refresh()
730+
self.handle_resize()
722731
else:
723732
translate=False
724733

‎Lib/_pyrepl/unix_console.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ def _my_getstr(cap: str, optional: bool = False) -> bytes | None:
190190
self._dch1=_my_getstr("dch1",optional=True)
191191
self._dch=_my_getstr("dch",optional=True)
192192
self._el=_my_getstr("el")
193+
self._ed=_my_getstr("ed")
193194
self._hpa=_my_getstr("hpa",optional=True)
194195
self._ich=_my_getstr("ich",optional=True)
195196
self._ich1=_my_getstr("ich1",optional=True)
@@ -223,7 +224,7 @@ def change_encoding(self, encoding: str) -> None:
223224
"""
224225
self.encoding=encoding
225226

226-
defrefresh(self,screen,c_xy):
227+
defrefresh(self,screen,c_xy,clear_to_end=False):
227228
"""
228229
Refresh the console screen.
229230
@@ -301,6 +302,12 @@ def refresh(self, screen, c_xy):
301302
self.__write_code(self._el)
302303
y+=1
303304

305+
ifclear_to_end:
306+
self.__move(wlen(newscr[-1]),len(newscr)-1+self.__offset)
307+
self.posxy=wlen(newscr[-1]),len(newscr)-1+self.__offset
308+
self.__write_code(self._ed)
309+
self.flushoutput()
310+
304311
self.__show_cursor()
305312

306313
self.screen=screen.copy()
@@ -322,6 +329,10 @@ def move_cursor(self, x, y):
322329
self.posxy=x,y
323330
self.flushoutput()
324331

332+
defreset_cursor(self)->None:
333+
self.posxy=0,self.__offset
334+
self.__write_code(self._cup,0,0)
335+
325336
defprepare(self):
326337
"""
327338
Prepare the console for input/output operations.

‎Lib/_pyrepl/windows_console.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def __init__(self, err: int | None, descr: str | None = None) -> None:
111111
MOVE_UP="\x1b[{}A"
112112
MOVE_DOWN="\x1b[{}B"
113113
CLEAR="\x1b[H\x1b[J"
114+
HOME="\x1b[H"
114115

115116
# State of control keys: https://learn.microsoft.com/en-us/windows/console/key-event-record-str
116117
ALT_ACTIVE=0x01|0x02
@@ -171,7 +172,7 @@ def __init__(
171172
# Console I/O is redirected, fallback...
172173
self.out=None
173174

174-
defrefresh(self,screen:list[str],c_xy:tuple[int,int])->None:
175+
defrefresh(self,screen:list[str],c_xy:tuple[int,int],clear_to_end:bool=False)->None:
175176
"""
176177
Refresh the console screen.
177178
@@ -237,6 +238,12 @@ def refresh(self, screen: list[str], c_xy: tuple[int, int]) -> None:
237238
self._erase_to_end()
238239
y+=1
239240

241+
ifclear_to_end:
242+
self._move_relative(wlen(newscr[-1]),self.__offset+len(newscr)-1)
243+
self.posxy=wlen(newscr[-1]),self.__offset+len(newscr)-1
244+
self.__write(b"\x1b[J")
245+
self.flushoutput()
246+
240247
self._show_cursor()
241248

242249
self.screen=screen
@@ -398,6 +405,10 @@ def move_cursor(self, x: int, y: int) -> None:
398405
self._move_relative(x,y)
399406
self.posxy=x,y
400407

408+
defreset_cursor(self)->None:
409+
self.posxy=0,self.__offset
410+
self.__write(HOME)
411+
401412
defset_cursor_vis(self,visible:bool)->None:
402413
ifvisible:
403414
self._show_cursor()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp