Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
1061d22
Windows repl support
DinoV May 17, 2024
fa0f538
Arrow key support
DinoV May 18, 2024
6f35100
Make backspace clear char
DinoV May 18, 2024
7772787
Fix missing newline after input
DinoV May 18, 2024
aced5ae
Make insert work
DinoV May 18, 2024
fa3815f
Fix delete in middle
DinoV May 18, 2024
b30b105
Fix crash on invalid command key
DinoV May 18, 2024
df262c4
More fixes
DinoV May 20, 2024
6e57316
Colorize
DinoV May 20, 2024
18ecc2e
Use constants
DinoV May 20, 2024
60525eb
Use UnicodeChar
DinoV May 21, 2024
af79a17
Simplify
DinoV May 21, 2024
5f99256
Fix scrolling on input which is longer than screen/scrollback
DinoV May 21, 2024
bdff535
fix pager typo and refactor some unused branches (#41)
tonybaloney May 20, 2024
88d64f5
Implement screen clear for Windows (#42)
tonybaloney May 20, 2024
8a74306
Fix word wrap not being enabled in Windows Terminal
DinoV May 21, 2024
38e9c58
Fix culmitive errors in wrapping as lines proceed
DinoV May 21, 2024
9cddace
Fix issues with inputs longer than a single line
DinoV May 22, 2024
fc4efee
Resize WIP
DinoV May 23, 2024
564e6e1
set compat based on Windows build version
tonybaloney May 24, 2024
3ae4316
use escape sequence for clearing screen and setting cursor position
tonybaloney May 24, 2024
5bb02a2
Remove unused imports
tonybaloney May 24, 2024
500761e
Windows repl support
DinoV May 17, 2024
98f16b9
Arrow key support
DinoV May 18, 2024
911a76a
Make backspace clear char
DinoV May 18, 2024
77f1c42
Fix missing newline after input
DinoV May 18, 2024
243817d
Make insert work
DinoV May 18, 2024
25f51b4
Fix delete in middle
DinoV May 18, 2024
5242239
Fix crash on invalid command key
DinoV May 18, 2024
febe424
More fixes
DinoV May 20, 2024
756ac47
Colorize
DinoV May 20, 2024
50fd4c9
Use constants
DinoV May 20, 2024
ff46d66
Use UnicodeChar
DinoV May 21, 2024
fbb9f84
Simplify
DinoV May 21, 2024
683f5f6
Fix scrolling on input which is longer than screen/scrollback
DinoV May 21, 2024
2c524b8
fix pager typo and refactor some unused branches (#41)
tonybaloney May 20, 2024
44ce57b
Implement screen clear for Windows (#42)
tonybaloney May 20, 2024
5ecc8cd
Fix word wrap not being enabled in Windows Terminal
DinoV May 21, 2024
5bb90c7
Fix issues with inputs longer than a single line
DinoV May 22, 2024
35557dd
Resize WIP
DinoV May 23, 2024
e04699f
Use vt100 scrolling to avoid race conditions on resize
DinoV May 24, 2024
6230400
More win api cleanup
DinoV May 24, 2024
70a9a31
Code cleanup
DinoV May 24, 2024
4adfe77
Reformat
DinoV May 24, 2024
9c00bd1
Annotations
DinoV May 24, 2024
dc7ec86
Update news
DinoV May 24, 2024
79a3fb9
Update history
DinoV May 24, 2024
3e4fe55
Initial test cases
DinoV May 25, 2024
38800e7
📜🤖 Added by blurb_it.
blurb-it[bot] May 25, 2024
b3f7092
Fix mypy and formatting issues
DinoV May 25, 2024
a589321
More mypy fixes
DinoV May 25, 2024
9a34d8a
More MyPy
DinoV May 25, 2024
f8a9176
More MyPy fixes
DinoV May 25, 2024
ce77202
More mypy fixes, name changes in WindowsConsole
DinoV May 26, 2024
6d8e7f5
Fix up ignores
DinoV May 26, 2024
bbbb296
Avoid kernel32 on non-Windows platforms
DinoV May 26, 2024
d064124
Formatting
DinoV May 26, 2024
f244a0e
Merge remote-tracking branch 'dinov/winrepl' into winrepl_control
tonybaloney May 26, 2024
3d526ba
roll back other merge
tonybaloney May 26, 2024
b1f5688
Merge pull request #1 from tonybaloney/winrepl_control
DinoV May 29, 2024
1146dbb
Catch more specific comment, avoid typing, fix comment
DinoV May 29, 2024
972e7ec
Ignore type error on return of Any
DinoV May 29, 2024
1d300e4
Merge branch 'main' of https://github.com/python/cpython into winrepl
DinoV May 29, 2024
d783dae
Don't import traceback on exception
DinoV May 29, 2024
d1289af
Remove one more TYPE_CHECKING
DinoV May 29, 2024
db191a2
Update Lib/test/test_pyrepl/test_windows_console.py
ambv May 30, 2024
fba84aa
Use _WindowsConsoleIO for output
DinoV May 31, 2024
42e3e8e
Merge branch 'winrepl' of github.com:DinoV/cpython into winrepl
DinoV May 31, 2024
63d854e
Remove get_abs_positon
DinoV May 31, 2024
513a148
Fix tests on windows
DinoV May 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix mypy and formatting issues
  • Loading branch information
DinoV committed May 25, 2024
commit b3f7092525cb4c68858b98a8d32ab6d6154d5c44
6 changes: 3 additions & 3 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ New Features
A Better Interactive Interpreter
--------------------------------

On Unix-like systems like Linux or macOS as well as Windows, Python now
uses a new :term:`interactive` shell. When the user starts the
:term:`REPL` from an interactive terminal the interactive shell now
On Unix-like systems like Linux or macOS as well as Windows, Python now
uses a new :term:`interactive` shell. When the user starts the
:term:`REPL` from an interactive terminal the interactive shell now
supports the following new features:

* Colorized prompts.
Expand Down
39 changes: 29 additions & 10 deletions Lib/_pyrepl/windows_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,26 @@
WCHAR,
SHORT,
)
from ctypes import Structure, POINTER, Union, WinDLL
from ctypes import Structure, POINTER, Union
from ctypes import windll
from typing import TYPE_CHECKING
Comment thread
AlexWaygood marked this conversation as resolved.
Outdated
from .utils import wlen

try:
from ctypes import GetLastError, WinError, WinDLL, windll
except:
# Keep MyPy happy off Windows
from ctypes import CDLL as WinDLL, cdll as windll

def GetLastError() -> int:
return 42

class WinError(OSError):
def __init__(self, err: int|None, descr: str|None = None) -> None:
self.err = err
self.descr = descr


if TYPE_CHECKING:
from typing import IO

Expand Down Expand Up @@ -117,6 +132,10 @@ def __init__(
else:
self.output_fd = f_out.fileno()

self.screen: List[str] = []
self.width = 80
self.height = 25
self.__offset = 0
self.event_queue: deque[Event] = deque()

def refresh(self, screen: list[str], c_xy: tuple[int, int]) -> None:
Expand Down Expand Up @@ -251,25 +270,25 @@ def scroll(
if not ScrollConsoleScreenBuffer(
OutHandle, scroll_rect, None, destination_origin, fill_info
):
raise ctypes.WinError(ctypes.GetLastError())
raise WinError(GetLastError())

def __hide_cursor(self) -> None:
info = CONSOLE_CURSOR_INFO()
if not GetConsoleCursorInfo(OutHandle, info):
raise ctypes.WinError(ctypes.GetLastError())
raise WinError(GetLastError())

info.bVisible = False
if not SetConsoleCursorInfo(OutHandle, info):
raise ctypes.WinError(ctypes.GetLastError())
raise WinError(GetLastError())

def __show_cursor(self) -> None:
info = CONSOLE_CURSOR_INFO()
if not GetConsoleCursorInfo(OutHandle, info):
raise ctypes.WinError(ctypes.GetLastError())
raise WinError(GetLastError())

info.bVisible = True
if not SetConsoleCursorInfo(OutHandle, info):
raise ctypes.WinError(ctypes.GetLastError())
raise WinError(GetLastError())

def __write(self, text: str) -> None:
print(repr(text))
Expand All @@ -279,7 +298,7 @@ def __write(self, text: str) -> None:
def screen_xy(self) -> tuple[int, int]:
info = CONSOLE_SCREEN_BUFFER_INFO()
if not GetConsoleScreenBufferInfo(OutHandle, info):
raise ctypes.WinError(ctypes.GetLastError())
raise WinError(GetLastError())
return info.dwCursorPosition.X, info.dwCursorPosition.Y

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝: This is relative to the origin of the buffer, not of the viewport. is this supposed to be viewport relative in the unix version?


def erase_to_end(self) -> None:
Expand Down Expand Up @@ -340,7 +359,7 @@ def getheightwidth(self) -> tuple[int, int]:
and width of the terminal window in characters."""
info = CONSOLE_SCREEN_BUFFER_INFO()
if not GetConsoleScreenBufferInfo(OutHandle, info):
raise ctypes.WinError(ctypes.GetLastError())
raise WinError(GetLastError())
return (
info.srWindow.Bottom - info.srWindow.Top + 1,
info.srWindow.Right - info.srWindow.Left + 1,
Expand All @@ -349,15 +368,15 @@ def getheightwidth(self) -> tuple[int, int]:
def getscrollbacksize(self) -> int:
info = CONSOLE_SCREEN_BUFFER_INFO()
if not GetConsoleScreenBufferInfo(OutHandle, info):
raise ctypes.WinError(ctypes.GetLastError())
raise WinError(GetLastError())

return info.srWindow.Bottom

def __read_input(self) -> INPUT_RECORD | None:
rec = INPUT_RECORD()
read = DWORD()
if not ReadConsoleInput(InHandle, rec, 1, read):
raise ctypes.WinError(ctypes.GetLastError())
raise WinError(GetLastError())

if read.value == 0:
return None
Expand Down
27 changes: 9 additions & 18 deletions Lib/test/test_pyrepl/test_windows_console.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import itertools
import sys
import unittest
from Lib._pyrepl.windows_console import ERASE_IN_LINE
from _pyrepl.console import Event, Console
from _pyrepl.windows_console import (
MOVE_LEFT,
MOVE_RIGHT,
MOVE_UP,
MOVE_DOWN,
ERASE_IN_LINE,
)
from _pyrepl.windows_console import MOVE_LEFT, MOVE_RIGHT, MOVE_UP, MOVE_DOWN, ERASE_IN_LINE
from functools import partial
from typing import Iterable
from unittest import TestCase, main
Expand All @@ -23,7 +16,6 @@
except ImportError:
pass


@patch("os.write")
@unittest.skipIf(sys.platform != "win32", "No Unix event queue on Windows")
Comment thread
ambv marked this conversation as resolved.
Outdated
class WindowsConsoleTests(TestCase):
Expand All @@ -46,16 +38,16 @@ def console(self, events, **kwargs) -> Console:

def handle_events(self, events: Iterable[Event], **kwargs):
return handle_all_events(events, partial(self.console, **kwargs))

def handle_events_narrow(self, events):
return self.handle_events(events, width=5)

def handle_events_short(self, events):
return self.handle_events(events, height=1)

def handle_events_height_3(self, events):
return self.handle_events(events, height=3)

def test_simple_addition(self, _os_write):
code = "12+34"
events = code_to_events(code)
Expand Down Expand Up @@ -130,8 +122,8 @@ def same_console(events):
prepare_console=same_console,
)

_os_write.assert_any_call(ANY, b"456\\")
_os_write.assert_any_call(ANY, b"789\\")
_os_write.assert_any_call(ANY, b'456\\')
_os_write.assert_any_call(ANY, b'789\\')

con.restore()

Expand Down Expand Up @@ -323,10 +315,9 @@ def move_left(self, cols=1):

def move_right(self, cols=1):
return MOVE_RIGHT.format(cols).encode("utf8")

def erase_in_line(self):
return ERASE_IN_LINE.encode("utf8")


if __name__ == "__main__":
unittest.main()
unittest.main()