Ansi handler
ansi_handler ¶
Handle basic logging with color via ANSI commands.
Will call into win32 commands as needed when needed
CONSOLE_SCREEN_BUFFER_INFO ¶
Win32Console ¶
A simple wrapper around the few methods calls to windows.
GetConsoleScreenBufferInfo
staticmethod
¶
GetConsoleScreenBufferInfo(
stream_id: int = STDOUT,
) -> CONSOLE_SCREEN_BUFFER_INFO
Returns the console screen buffer info object.
SetConsoleTextAttribute
staticmethod
¶
SetConsoleTextAttribute(stream_id: int, attrs: int) -> bool
Sets the console text attribute.
WinColor ¶
Enum representing Windows Console colors.
AnsiColor ¶
Defines the different codes for the ansi colors.
ColoredFormatter ¶
ColoredStreamHandler ¶
Class for logging in Color..
__init__ ¶
__init__(
stream: Optional[IO] = None,
strip: Optional[str] = None,
convert: Optional[str] = None,
) -> ColoredStreamHandler
Inits a Colored Stream Handler.
handle ¶
handle(record: logging.LogRecord) -> bool
Conditionally emit the specified logging record.
Emission depends on filters which may have been added to the handler. Wrap the actual emission of the record with acquisition/release of the I/O thread lock. Returns whether the filter passed the record for emission.
get_win32_calls ¶
get_win32_calls() -> dict
Returns a dict for converting ANSI Colors to Windows Colors.
set_foreground ¶
set_foreground(
fore: Optional[int] = None,
light: bool = False,
on_stderr: bool = False,
) -> None
Does the win32 call to set the foreground.
set_background ¶
set_background(
back: Optional[int] = None,
light: bool = False,
on_stderr: bool = False,
) -> None
Does the win32 call to see the background.
set_console ¶
set_console(
attrs: Optional[int] = None, on_stderr: bool = False
) -> None
Does the win32 call to set the console text attribute.
write_and_convert ¶
write_and_convert(text: str) -> None
Write the given text to the strip stripping and converting ANSI.
write_plain_text ¶
write_plain_text(
text: str,
start: Optional[int] = None,
end: Optional[int] = None,
) -> None
Writes plain text to our stream.
convert_ansi ¶
convert_ansi(paramstring: str, command: str) -> None
Converts an ANSI command to a win32 command.
extract_params ¶
extract_params(command: str, paramstring: str) -> tuple
Extracts the parameters in the ANSI command.
call_win32 ¶
call_win32(command: str, params: list) -> None
Calls the win32 apis set_foreground and set_background.
emit ¶
emit(record: logging.LogRecord) -> None
Logging.handler method we are overriding to emit a record.
SetConsoleTextAttribute ¶
SetConsoleTextAttribute() -> None
Create blank lambda for when on unix / linux.
get_ansi_string ¶
get_ansi_string(color: AnsiColor = AnsiColor.RESET) -> str
Returns the string formatted ANSI command for the specific color.