Skip to content

Commit 0b20bff

Browse files
GabrielvMarinhoblurb-it[bot]vstinner
authored
gh-146458: Fix REPL height and width tracking on resize (#146459)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 957b2cc commit 0b20bff

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
@@ -651,6 +651,7 @@ def update_screen(self) -> None:
651651

652652
def refresh(self) -> None:
653653
"""Recalculate and refresh the screen."""
654+
self.console.height, self.console.width = self.console.getheightwidth()
654655
# this call sets up self.cxy, so call it first.
655656
self.screen = self.calc_screen()
656657
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
@@ -129,9 +129,7 @@ def test_resize_wider(self):
129129
events = code_to_events(code)
130130
reader, console = self.handle_events_narrow(events)
131131

132-
console.height = 20
133-
console.width = 80
134-
console.getheightwidth = MagicMock(lambda _: (20, 80))
132+
console.getheightwidth = MagicMock(side_effect=lambda: (20, 80))
135133

136134
def same_reader(_):
137135
return reader
@@ -157,9 +155,7 @@ def test_resize_narrower(self):
157155
events = code_to_events(code)
158156
reader, console = self.handle_events(events)
159157

160-
console.height = 20
161-
console.width = 4
162-
console.getheightwidth = MagicMock(lambda _: (20, 4))
158+
console.getheightwidth = MagicMock(side_effect=lambda: (20, 4))
163159

164160
def same_reader(_):
165161
return reader
@@ -292,8 +288,7 @@ def test_resize_bigger_on_multiline_function(self):
292288
events = itertools.chain(code_to_events(code))
293289
reader, console = self.handle_events_short(events)
294290

295-
console.height = 2
296-
console.getheightwidth = MagicMock(lambda _: (2, 80))
291+
console.getheightwidth = MagicMock(side_effect=lambda: (2, 80))
297292

298293
def same_reader(_):
299294
return reader
@@ -330,8 +325,7 @@ def test_resize_smaller_on_multiline_function(self):
330325
events = itertools.chain(code_to_events(code))
331326
reader, console = self.handle_events_height_3(events)
332327

333-
console.height = 1
334-
console.getheightwidth = MagicMock(lambda _: (1, 80))
328+
console.getheightwidth = MagicMock(side_effect=lambda: (1, 80))
335329

336330
def same_reader(_):
337331
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)