Skip to content

Commit 5df7652

Browse files
miss-islingtonGabrielvMarinhoblurb-it[bot]vstinner
authored
[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 0b20bff) 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>
1 parent 3da4e09 commit 5df7652

File tree

7 files changed

+11
-15
lines changed

7 files changed

+11
-15
lines changed

Lib/_pyrepl/reader.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ def update_screen(self) -> None:
644644

645645
def refresh(self) -> None:
646646
"""Recalculate and refresh the screen."""
647+
self.console.height, self.console.width = self.console.getheightwidth()
647648
# this call sets up self.cxy, so call it first.
648649
self.screen = self.calc_screen()
649650
self.console.refresh(self.screen, self.cxy)

Lib/_pyrepl/unix_console.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,6 @@ def __move_tall(self, x, y):
776776
self.__write_code(self._cup, y - self.__offset, x)
777777

778778
def __sigwinch(self, signum, frame):
779-
self.height, self.width = self.getheightwidth()
780779
self.event_queue.insert(Event("resize", None))
781780

782781
def __hide_cursor(self):

Lib/test/test_pyrepl/support.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ def prepare_console(events: Iterable[Event], **kwargs) -> MagicMock | Console:
8888
console.get_event.side_effect = events
8989
console.height = 100
9090
console.width = 80
91+
console.getheightwidth = MagicMock(side_effect=lambda: (console.height, console.width))
92+
9193
for key, val in kwargs.items():
9294
setattr(console, key, val)
9395
return console

Lib/test/test_pyrepl/test_reader.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ def _prepare_console(events):
228228
console.get_event.side_effect = events
229229
console.height = 100
230230
console.width = 80
231+
console.getheightwidth = MagicMock(side_effect=lambda: (console.height, console.width))
231232
console.input_hook = input_hook
232233
return console
233234

Lib/test/test_pyrepl/test_unix_console.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,7 @@ def test_resize_bigger_on_multiline_function(self, _os_write):
250250
events = itertools.chain(code_to_events(code))
251251
reader, console = handle_events_short_unix_console(events)
252252

253-
console.height = 2
254-
console.getheightwidth = MagicMock(lambda _: (2, 80))
253+
console.getheightwidth = MagicMock(side_effect=lambda: (2, 80))
255254

256255
def same_reader(_):
257256
return reader
@@ -286,8 +285,7 @@ def test_resize_smaller_on_multiline_function(self, _os_write):
286285
events = itertools.chain(code_to_events(code))
287286
reader, console = handle_events_unix_console_height_3(events)
288287

289-
console.height = 1
290-
console.getheightwidth = MagicMock(lambda _: (1, 80))
288+
console.getheightwidth = MagicMock(side_effect=lambda: (1, 80))
291289

292290
def same_reader(_):
293291
return reader

Lib/test/test_pyrepl/test_windows_console.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ def test_resize_wider(self):
115115
events = code_to_events(code)
116116
reader, console = self.handle_events_narrow(events)
117117

118-
console.height = 20
119-
console.width = 80
120-
console.getheightwidth = MagicMock(lambda _: (20, 80))
118+
console.getheightwidth = MagicMock(side_effect=lambda: (20, 80))
121119

122120
def same_reader(_):
123121
return reader
@@ -143,9 +141,7 @@ def test_resize_narrower(self):
143141
events = code_to_events(code)
144142
reader, console = self.handle_events(events)
145143

146-
console.height = 20
147-
console.width = 4
148-
console.getheightwidth = MagicMock(lambda _: (20, 4))
144+
console.getheightwidth = MagicMock(side_effect=lambda: (20, 4))
149145

150146
def same_reader(_):
151147
return reader
@@ -278,8 +274,7 @@ def test_resize_bigger_on_multiline_function(self):
278274
events = itertools.chain(code_to_events(code))
279275
reader, console = self.handle_events_short(events)
280276

281-
console.height = 2
282-
console.getheightwidth = MagicMock(lambda _: (2, 80))
277+
console.getheightwidth = MagicMock(side_effect=lambda: (2, 80))
283278

284279
def same_reader(_):
285280
return reader
@@ -316,8 +311,7 @@ def test_resize_smaller_on_multiline_function(self):
316311
events = itertools.chain(code_to_events(code))
317312
reader, console = self.handle_events_height_3(events)
318313

319-
console.height = 1
320-
console.getheightwidth = MagicMock(lambda _: (1, 80))
314+
console.getheightwidth = MagicMock(side_effect=lambda: (1, 80))
321315

322316
def same_reader(_):
323317
return reader
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix incorrect REPL height and width tracking on console window resize on Windows.

0 commit comments

Comments
 (0)