diff --git a/stubs/colorama/METADATA.toml b/stubs/colorama/METADATA.toml new file mode 100644 index 000000000..337e55f69 --- /dev/null +++ b/stubs/colorama/METADATA.toml @@ -0,0 +1,2 @@ +version = "0.4" +python2 = true \ No newline at end of file diff --git a/stubs/colorama/colorama/__init__.pyi b/stubs/colorama/colorama/__init__.pyi new file mode 100644 index 000000000..1fc778d8a --- /dev/null +++ b/stubs/colorama/colorama/__init__.pyi @@ -0,0 +1,3 @@ +from .ansi import Back as Back, Cursor as Cursor, Fore as Fore, Style as Style +from .ansitowin32 import AnsiToWin32 as AnsiToWin32 +from .initialise import colorama_text as colorama_text, deinit as deinit, init as init, reinit as reinit diff --git a/stubs/colorama/colorama/ansi.pyi b/stubs/colorama/colorama/ansi.pyi new file mode 100644 index 000000000..7224a7a81 --- /dev/null +++ b/stubs/colorama/colorama/ansi.pyi @@ -0,0 +1,69 @@ +CSI: str +OSC: str +BEL: str + +def code_to_chars(code: int) -> str: ... +def set_title(title: str) -> str: ... +def clear_screen(mode: int = ...) -> str: ... +def clear_line(mode: int = ...) -> str: ... + +class AnsiCodes: + def __init__(self) -> None: ... + +class AnsiCursor: + def UP(self, n: int = ...) -> str: ... + def DOWN(self, n: int = ...) -> str: ... + def FORWARD(self, n: int = ...) -> str: ... + def BACK(self, n: int = ...) -> str: ... + def POS(self, x: int = ..., y: int = ...) -> str: ... + +# All attributes in the following classes are string in instances and int in the class. +# We use str since that is the common case for users. +class AnsiFore(AnsiCodes): + BLACK: str = ... + RED: str = ... + GREEN: str = ... + YELLOW: str = ... + BLUE: str = ... + MAGENTA: str = ... + CYAN: str = ... + WHITE: str = ... + RESET: str = ... + LIGHTBLACK_EX: str = ... + LIGHTRED_EX: str = ... + LIGHTGREEN_EX: str = ... + LIGHTYELLOW_EX: str = ... + LIGHTBLUE_EX: str = ... + LIGHTMAGENTA_EX: str = ... + LIGHTCYAN_EX: str = ... + LIGHTWHITE_EX: str = ... + +class AnsiBack(AnsiCodes): + BLACK: str = ... + RED: str = ... + GREEN: str = ... + YELLOW: str = ... + BLUE: str = ... + MAGENTA: str = ... + CYAN: str = ... + WHITE: str = ... + RESET: str = ... + LIGHTBLACK_EX: str = ... + LIGHTRED_EX: str = ... + LIGHTGREEN_EX: str = ... + LIGHTYELLOW_EX: str = ... + LIGHTBLUE_EX: str = ... + LIGHTMAGENTA_EX: str = ... + LIGHTCYAN_EX: str = ... + LIGHTWHITE_EX: str = ... + +class AnsiStyle(AnsiCodes): + BRIGHT: str = ... + DIM: str = ... + NORMAL: str = ... + RESET_ALL: str = ... + +Fore: AnsiFore +Back: AnsiBack +Style: AnsiStyle +Cursor: AnsiCursor diff --git a/stubs/colorama/colorama/ansitowin32.pyi b/stubs/colorama/colorama/ansitowin32.pyi new file mode 100644 index 000000000..5006b08ab --- /dev/null +++ b/stubs/colorama/colorama/ansitowin32.pyi @@ -0,0 +1,47 @@ +import sys +from _typeshed import SupportsWrite +from typing import Any, Callable, Dict, Optional, Pattern, Sequence, TextIO, Tuple, Union + +if sys.platform == "win32": + from .winterm import WinTerm + + winterm: WinTerm +else: + winterm: None + +class StreamWrapper: + def __init__(self, wrapped: TextIO, converter: SupportsWrite[str]) -> None: ... + def __getattr__(self, name: str) -> Any: ... + def __enter__(self, *args: object, **kwargs: object) -> TextIO: ... + def __exit__(self, *args: Any, **kwargs: Any) -> None: ... + def write(self, text: str) -> None: ... + def isatty(self) -> bool: ... + @property + def closed(self) -> bool: ... + +_WinTermCall = Callable[[Optional[int], bool, bool], None] +_WinTermCallDict = Dict[int, Union[Tuple[_WinTermCall], Tuple[_WinTermCall, int], Tuple[_WinTermCall, int, bool]]] + +class AnsiToWin32: + ANSI_CSI_RE: Pattern[str] = ... + ANSI_OSC_RE: Pattern[str] = ... + wrapped: TextIO = ... + autoreset: bool = ... + stream: StreamWrapper = ... + strip: bool = ... + convert: bool = ... + win32_calls: _WinTermCallDict = ... + on_stderr: bool = ... + def __init__( + self, wrapped: TextIO, convert: Optional[bool] = ..., strip: Optional[bool] = ..., autoreset: bool = ... + ) -> None: ... + def should_wrap(self) -> bool: ... + def get_win32_calls(self) -> _WinTermCallDict: ... + def write(self, text: str) -> None: ... + def reset_all(self) -> None: ... + def write_and_convert(self, text: str) -> None: ... + def write_plain_text(self, text: str, start: int, end: int) -> None: ... + def convert_ansi(self, paramstring: str, command: str) -> None: ... + def extract_params(self, command: str, paramstring: str) -> Tuple[int, ...]: ... + def call_win32(self, command: str, params: Sequence[int]) -> None: ... + def convert_osc(self, text: str) -> str: ... diff --git a/stubs/colorama/colorama/initialise.pyi b/stubs/colorama/colorama/initialise.pyi new file mode 100644 index 000000000..4f7d7427c --- /dev/null +++ b/stubs/colorama/colorama/initialise.pyi @@ -0,0 +1,18 @@ +from typing import Any, ContextManager, Optional, TextIO, Union + +from .ansitowin32 import StreamWrapper + +orig_stdout: Optional[TextIO] +orig_stderr: Optional[TextIO] +wrapped_stdout: Union[TextIO, StreamWrapper] +wrapped_stderr: Union[TextIO, StreamWrapper] +atexit_done: bool + +def reset_all() -> None: ... +def init(autoreset: bool = ..., convert: Optional[bool] = ..., strip: Optional[bool] = ..., wrap: bool = ...) -> None: ... +def deinit() -> None: ... +def colorama_text(*args: Any, **kwargs: Any) -> ContextManager[None]: ... +def reinit() -> None: ... +def wrap_stream( + stream: TextIO, convert: Optional[bool], strip: Optional[bool], autoreset: bool, wrap: bool +) -> Union[TextIO, StreamWrapper]: ... diff --git a/stubs/colorama/colorama/win32.pyi b/stubs/colorama/colorama/win32.pyi new file mode 100644 index 000000000..37e6a0b99 --- /dev/null +++ b/stubs/colorama/colorama/win32.pyi @@ -0,0 +1,31 @@ +import sys +from typing import Callable +from typing_extensions import Literal + +STDOUT: Literal[-11] +STDERR: Literal[-12] + +if sys.platform == "win32": + from ctypes import LibraryLoader, Structure, WinDLL, wintypes + + windll: LibraryLoader[WinDLL] + COORD = wintypes._COORD + class CONSOLE_SCREEN_BUFFER_INFO(Structure): + dwSize: COORD + dwCursorPosition: COORD + wAttributes: wintypes.WORD + srWindow: wintypes.SMALL_RECT + dwMaximumWindowSize: COORD + def __str__(self) -> str: ... + def winapi_test() -> bool: ... + def GetConsoleScreenBufferInfo(stream_id: int = ...) -> CONSOLE_SCREEN_BUFFER_INFO: ... + def SetConsoleTextAttribute(stream_id: int, attrs: wintypes.WORD) -> wintypes.BOOL: ... + def SetConsoleCursorPosition(stream_id: int, position: COORD, adjust: bool = ...) -> wintypes.BOOL: ... + def FillConsoleOutputCharacter(stream_id: int, char: str, length: int, start: COORD) -> int: ... + def FillConsoleOutputAttribute(stream_id: int, attr: int, length: int, start: COORD) -> wintypes.BOOL: ... + def SetConsoleTitle(title: str) -> wintypes.BOOL: ... + +else: + windll: None + SetConsoleTextAttribute: Callable[..., None] + winapi_test: Callable[..., None] diff --git a/stubs/colorama/colorama/winterm.pyi b/stubs/colorama/colorama/winterm.pyi new file mode 100644 index 000000000..0947d33f0 --- /dev/null +++ b/stubs/colorama/colorama/winterm.pyi @@ -0,0 +1,34 @@ +import sys + +if sys.platform == "win32": + from typing import Optional + + from . import win32 + class WinColor: + BLACK: int = ... + BLUE: int = ... + GREEN: int = ... + CYAN: int = ... + RED: int = ... + MAGENTA: int = ... + YELLOW: int = ... + GREY: int = ... + class WinStyle: + NORMAL: int = ... + BRIGHT: int = ... + BRIGHT_BACKGROUND: int = ... + class WinTerm: + def __init__(self) -> None: ... + def get_attrs(self) -> int: ... + def set_attrs(self, value: int) -> None: ... + def reset_all(self, on_stderr: Optional[bool] = ...) -> None: ... + def fore(self, fore: Optional[int] = ..., light: bool = ..., on_stderr: bool = ...) -> None: ... + def back(self, back: Optional[int] = ..., light: bool = ..., on_stderr: bool = ...) -> None: ... + def style(self, style: Optional[int] = ..., on_stderr: bool = ...) -> None: ... + def set_console(self, attrs: Optional[int] = ..., on_stderr: bool = ...) -> None: ... + def get_position(self, handle: int) -> win32.COORD: ... + def set_cursor_position(self, position: Optional[win32.COORD] = ..., on_stderr: bool = ...) -> None: ... + def cursor_adjust(self, x: int, y: int, on_stderr: bool = ...) -> None: ... + def erase_screen(self, mode: int = ..., on_stderr: bool = ...) -> None: ... + def erase_line(self, mode: int = ..., on_stderr: bool = ...) -> None: ... + def set_title(self, title: str) -> None: ...