@@ -2107,13 +2107,14 @@ def test_ctrl_d_single_line_end_no_newline(self):
21072107 self .assertEqual ("hello" , "" .join (reader .buffer ))
21082108
21092109
2110- @skipUnless (sys .platform == "win32" , "Windows console VT behavior only" )
2111- class TestWindowsConsoleVtEolWrap (TestCase ):
2110+ @skipUnless (sys .platform == "win32" , "Windows console behavior only" )
2111+ class TestWindowsConsoleEolWrap (TestCase ):
21122112 """
2113- When a line exactly fills the terminal width, VT terminals differ on whether
2114- the cursor immediately wraps to the next row. In VT mode we must synchronize
2115- our logical cursor position with the real console cursor.
2113+ When a line exactly fills the terminal width, Windows consoles differ on
2114+ whether the cursor immediately wraps to the next row (depends on host/ mode).
2115+ We must synchronize our logical cursor position with the real console cursor.
21162116 """
2117+
21172118 def _make_console_like (self , * , width : int , offset : int , vt : bool ):
21182119 from _pyrepl import windows_console as wc
21192120
@@ -2135,45 +2136,40 @@ def _make_console_like(self, *, width: int, offset: int, vt: bool):
21352136
21362137 return con , wc
21372138
2138- def test_vt_exact_width_line_did_wrap (self ):
2139- # Terminal wrapped to next row: posxy should become (0, y+1).
2139+ def _run_exact_width_case (self , * , vt : bool , did_wrap : bool ):
21402140 width = 10
21412141 y = 3
2142- con , wc = self ._make_console_like (width = width , offset = 0 , vt = True )
2142+ con , wc = self ._make_console_like (width = width , offset = 0 , vt = vt )
21432143
21442144 def fake_gcsbi (_h , info ):
2145- info .dwCursorPosition .X = 0
2146- # Visible window top = 0, cursor now on next visible row
21472145 info .srWindow .Top = 0
2148- info .dwCursorPosition .Y = y + 1
2149- return True
2150-
2151- with patch .object (wc , "GetConsoleScreenBufferInfo" , side_effect = fake_gcsbi ), \
2152- patch .object (wc , "OutHandle" , 1 ):
2153- old = ""
2154- new = "a" * width
2155- wc .WindowsConsole ._WindowsConsole__write_changed_line (con , y , old , new , 0 )
2156- self .assertEqual (con .posxy , (0 , y + 1 ))
2157- self .assertNotIn ((0 , y + 1 ), [c .args for c in con ._move_relative .mock_calls ])
2158-
2159- def test_vt_exact_width_line_did_not_wrap (self ):
2160- # Terminal did NOT wrap yet: posxy should stay at (width, y).
2161- width = 10
2162- y = 3
2163- con , wc = self ._make_console_like (width = width , offset = 0 , vt = True )
2164-
2165- def fake_gcsbi (_h , info ):
2166- info .dwCursorPosition .X = width
2167- info .srWindow .Top = 0
2168- # Cursor remains on the same visible row
2169- info .dwCursorPosition .Y = y
2146+ if did_wrap :
2147+ info .dwCursorPosition .X = 0
2148+ info .dwCursorPosition .Y = y + 1
2149+ else :
2150+ info .dwCursorPosition .X = width
2151+ info .dwCursorPosition .Y = y
21702152 return True
21712153
21722154 with patch .object (wc , "GetConsoleScreenBufferInfo" , side_effect = fake_gcsbi ), \
2173- patch .object (wc , "OutHandle" , 1 ):
2155+ patch .object (wc , "OutHandle" , 1 ):
21742156 old = ""
21752157 new = "a" * width
21762158 wc .WindowsConsole ._WindowsConsole__write_changed_line (con , y , old , new , 0 )
21772159
2178- self .assertEqual (con .posxy , (width , y ))
2179- self .assertNotIn ((0 , y + 1 ), [c .args for c in con ._move_relative .mock_calls ])
2160+ if did_wrap :
2161+ self .assertEqual (con .posxy , (0 , y + 1 ))
2162+ self .assertNotIn ((0 , y + 1 ), [c .args for c in con ._move_relative .mock_calls ])
2163+ else :
2164+ self .assertEqual (con .posxy , (width , y ))
2165+ self .assertNotIn ((0 , y + 1 ), [c .args for c in con ._move_relative .mock_calls ])
2166+
2167+ def test_exact_width_line_did_wrap_vt_and_legacy (self ):
2168+ for vt in (True , False ):
2169+ with self .subTest (vt = vt ):
2170+ self ._run_exact_width_case (vt = vt , did_wrap = True )
2171+
2172+ def test_exact_width_line_did_not_wrap_vt_and_legacy (self ):
2173+ for vt in (True , False ):
2174+ with self .subTest (vt = vt ):
2175+ self ._run_exact_width_case (vt = vt , did_wrap = False )
0 commit comments