summaryrefslogtreecommitdiffstats
path: root/Lib/_pyrepl/console.py
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2024-05-05 19:32:23 (GMT)
committerGitHub <noreply@github.com>2024-05-05 19:32:23 (GMT)
commitf27f8c790af1233d499b795af1c0d1b36aaecaf5 (patch)
tree22c502c6382512fafbb63e3020c8462e5400d4df /Lib/_pyrepl/console.py
parent40cc809902304f60c6e1c933191dd4d64e570e28 (diff)
downloadcpython-f27f8c790af1233d499b795af1c0d1b36aaecaf5.zip
cpython-f27f8c790af1233d499b795af1c0d1b36aaecaf5.tar.gz
cpython-f27f8c790af1233d499b795af1c0d1b36aaecaf5.tar.bz2
gh-111201: A new Python REPL (GH-111567)
Co-authored-by: Łukasz Langa <lukasz@langa.pl> Co-authored-by: Marta Gómez Macías <mgmacias@google.com> Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Diffstat (limited to 'Lib/_pyrepl/console.py')
-rw-r--r--Lib/_pyrepl/console.py112
1 files changed, 112 insertions, 0 deletions
diff --git a/Lib/_pyrepl/console.py b/Lib/_pyrepl/console.py
new file mode 100644
index 0000000..d7e86e7
--- /dev/null
+++ b/Lib/_pyrepl/console.py
@@ -0,0 +1,112 @@
+# Copyright 2000-2004 Michael Hudson-Doyle <micahel@gmail.com>
+#
+# All Rights Reserved
+#
+#
+# Permission to use, copy, modify, and distribute this software and
+# its documentation for any purpose is hereby granted without fee,
+# provided that the above copyright notice appear in all copies and
+# that both that copyright notice and this permission notice appear in
+# supporting documentation.
+#
+# THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
+# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
+# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+from __future__ import annotations
+
+from abc import ABC, abstractmethod
+from dataclasses import dataclass, field
+
+
+@dataclass
+class Event:
+ evt: str
+ data: str
+ raw: bytes = b""
+
+
+@dataclass
+class Console(ABC):
+ screen: list[str] = field(default_factory=list)
+ height: int = 25
+ width: int = 80
+
+ @abstractmethod
+ def refresh(self, screen: list[str], xy: tuple[int, int]) -> None: ...
+
+ @abstractmethod
+ def prepare(self) -> None: ...
+
+ @abstractmethod
+ def restore(self) -> None: ...
+
+ @abstractmethod
+ def move_cursor(self, x: int, y: int) -> None: ...
+
+ @abstractmethod
+ def set_cursor_vis(self, visible: bool) -> None: ...
+
+ @abstractmethod
+ def getheightwidth(self) -> tuple[int, int]:
+ """Return (height, width) where height and width are the height
+ and width of the terminal window in characters."""
+ ...
+
+ @abstractmethod
+ def get_event(self, block: bool = True) -> Event | None:
+ """Return an Event instance. Returns None if |block| is false
+ and there is no event pending, otherwise waits for the
+ completion of an event."""
+ ...
+
+ @abstractmethod
+ def push_char(self, char: int | bytes) -> None:
+ """
+ Push a character to the console event queue.
+ """
+ ...
+
+ @abstractmethod
+ def beep(self) -> None: ...
+
+ @abstractmethod
+ def clear(self) -> None:
+ """Wipe the screen"""
+ ...
+
+ @abstractmethod
+ def finish(self) -> None:
+ """Move the cursor to the end of the display and otherwise get
+ ready for end. XXX could be merged with restore? Hmm."""
+ ...
+
+ @abstractmethod
+ def flushoutput(self) -> None:
+ """Flush all output to the screen (assuming there's some
+ buffering going on somewhere)."""
+ ...
+
+ @abstractmethod
+ def forgetinput(self) -> None:
+ """Forget all pending, but not yet processed input."""
+ ...
+
+ @abstractmethod
+ def getpending(self) -> Event:
+ """Return the characters that have been typed but not yet
+ processed."""
+ ...
+
+ @abstractmethod
+ def wait(self) -> None:
+ """Wait for an event."""
+ ...
+
+ @abstractmethod
+ def repaint(self) -> None:
+ ...