summaryrefslogtreecommitdiffstats
path: root/Lib/_pyrepl/console.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-05-31 15:18:28 (GMT)
committerGitHub <noreply@github.com>2024-05-31 15:18:28 (GMT)
commitd6faac6d1f825405398158272286aaed94eb51fc (patch)
tree3b06fc114183c3185556756f3d36172f2b06fc08 /Lib/_pyrepl/console.py
parent6e57bd01e00d40dfe7c9344d0b528d9059b1fa93 (diff)
downloadcpython-d6faac6d1f825405398158272286aaed94eb51fc.zip
cpython-d6faac6d1f825405398158272286aaed94eb51fc.tar.gz
cpython-d6faac6d1f825405398158272286aaed94eb51fc.tar.bz2
[3.13] gh-111201: Support pyrepl on Windows (GH-119559) (GH-119850)
(cherry picked from commit 0d07182821fad7b95a043d006f1ce13a2d22edcb) Co-authored-by: Dino Viehland <dinoviehland@gmail.com> Co-authored-by: Anthony Shaw <anthony.p.shaw@gmail.com> Co-authored-by: Ɓukasz Langa <lukasz@langa.pl>
Diffstat (limited to 'Lib/_pyrepl/console.py')
-rw-r--r--Lib/_pyrepl/console.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/Lib/_pyrepl/console.py b/Lib/_pyrepl/console.py
index d7e86e7..fcabf78 100644
--- a/Lib/_pyrepl/console.py
+++ b/Lib/_pyrepl/console.py
@@ -19,10 +19,18 @@
from __future__ import annotations
+import sys
+
from abc import ABC, abstractmethod
from dataclasses import dataclass, field
+TYPE_CHECKING = False
+
+if TYPE_CHECKING:
+ from typing import IO
+
+
@dataclass
class Event:
evt: str
@@ -36,6 +44,25 @@ class Console(ABC):
height: int = 25
width: int = 80
+ def __init__(
+ self,
+ f_in: IO[bytes] | int = 0,
+ f_out: IO[bytes] | int = 1,
+ term: str = "",
+ encoding: str = "",
+ ):
+ self.encoding = encoding or sys.getdefaultencoding()
+
+ if isinstance(f_in, int):
+ self.input_fd = f_in
+ else:
+ self.input_fd = f_in.fileno()
+
+ if isinstance(f_out, int):
+ self.output_fd = f_out
+ else:
+ self.output_fd = f_out.fileno()
+
@abstractmethod
def refresh(self, screen: list[str], xy: tuple[int, int]) -> None: ...
@@ -108,5 +135,4 @@ class Console(ABC):
...
@abstractmethod
- def repaint(self) -> None:
- ...
+ def repaint(self) -> None: ...