[3.14] gh-146458: Fix REPL height and width tracking on resize (GH-146459) (#148232)

gh-146458: Fix REPL height and width tracking on resize (GH-146459)
(cherry picked from commit 0b20bff386)

Co-authored-by: Gabriel Volles Marinho <147559808+GabrielvMarinho@users.noreply.github.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Miss Islington (bot) 2026-04-07 23:37:46 +02:00 committed by GitHub
parent 3da4e0910c
commit 5df7652859
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 11 additions and 15 deletions

View file

@ -644,6 +644,7 @@ def update_screen(self) -> None:
def refresh(self) -> None:
"""Recalculate and refresh the screen."""
self.console.height, self.console.width = self.console.getheightwidth()
# this call sets up self.cxy, so call it first.
self.screen = self.calc_screen()
self.console.refresh(self.screen, self.cxy)

View file

@ -776,7 +776,6 @@ def __move_tall(self, x, y):
self.__write_code(self._cup, y - self.__offset, x)
def __sigwinch(self, signum, frame):
self.height, self.width = self.getheightwidth()
self.event_queue.insert(Event("resize", None))
def __hide_cursor(self):

View file

@ -88,6 +88,8 @@ def prepare_console(events: Iterable[Event], **kwargs) -> MagicMock | Console:
console.get_event.side_effect = events
console.height = 100
console.width = 80
console.getheightwidth = MagicMock(side_effect=lambda: (console.height, console.width))
for key, val in kwargs.items():
setattr(console, key, val)
return console

View file

@ -228,6 +228,7 @@ def _prepare_console(events):
console.get_event.side_effect = events
console.height = 100
console.width = 80
console.getheightwidth = MagicMock(side_effect=lambda: (console.height, console.width))
console.input_hook = input_hook
return console

View file

@ -250,8 +250,7 @@ def test_resize_bigger_on_multiline_function(self, _os_write):
events = itertools.chain(code_to_events(code))
reader, console = handle_events_short_unix_console(events)
console.height = 2
console.getheightwidth = MagicMock(lambda _: (2, 80))
console.getheightwidth = MagicMock(side_effect=lambda: (2, 80))
def same_reader(_):
return reader
@ -286,8 +285,7 @@ def test_resize_smaller_on_multiline_function(self, _os_write):
events = itertools.chain(code_to_events(code))
reader, console = handle_events_unix_console_height_3(events)
console.height = 1
console.getheightwidth = MagicMock(lambda _: (1, 80))
console.getheightwidth = MagicMock(side_effect=lambda: (1, 80))
def same_reader(_):
return reader

View file

@ -115,9 +115,7 @@ def test_resize_wider(self):
events = code_to_events(code)
reader, console = self.handle_events_narrow(events)
console.height = 20
console.width = 80
console.getheightwidth = MagicMock(lambda _: (20, 80))
console.getheightwidth = MagicMock(side_effect=lambda: (20, 80))
def same_reader(_):
return reader
@ -143,9 +141,7 @@ def test_resize_narrower(self):
events = code_to_events(code)
reader, console = self.handle_events(events)
console.height = 20
console.width = 4
console.getheightwidth = MagicMock(lambda _: (20, 4))
console.getheightwidth = MagicMock(side_effect=lambda: (20, 4))
def same_reader(_):
return reader
@ -278,8 +274,7 @@ def test_resize_bigger_on_multiline_function(self):
events = itertools.chain(code_to_events(code))
reader, console = self.handle_events_short(events)
console.height = 2
console.getheightwidth = MagicMock(lambda _: (2, 80))
console.getheightwidth = MagicMock(side_effect=lambda: (2, 80))
def same_reader(_):
return reader
@ -316,8 +311,7 @@ def test_resize_smaller_on_multiline_function(self):
events = itertools.chain(code_to_events(code))
reader, console = self.handle_events_height_3(events)
console.height = 1
console.getheightwidth = MagicMock(lambda _: (1, 80))
console.getheightwidth = MagicMock(side_effect=lambda: (1, 80))
def same_reader(_):
return reader

View file

@ -0,0 +1 @@
Fix incorrect REPL height and width tracking on console window resize on Windows.