summaryrefslogtreecommitdiffstats
path: root/Lib/_pyrepl/console.py
diff options
context:
space:
mode:
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: ...