From 3fb258b8dbb01fd351aa2f3f3c9871155f191664 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Mon, 7 Oct 2024 00:19:43 -0400 Subject: [PATCH 1/2] Fix console output on Windows --- seleniumbase/__init__.py | 9 ++++----- seleniumbase/console_scripts/run.py | 14 ++++++++++++++ seleniumbase/fixtures/shared_utils.py | 6 ++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/seleniumbase/__init__.py b/seleniumbase/__init__.py index a57a5b5df9d..59f564c3fb6 100644 --- a/seleniumbase/__init__.py +++ b/seleniumbase/__init__.py @@ -22,14 +22,13 @@ with suppress(Exception): import colorama + +with suppress(Exception): import pdbp # (Pdb+) --- Python Debugger Plus -is_windows = shared_utils.is_windows() with suppress(Exception): - if is_windows and hasattr(colorama, "just_fix_windows_console"): - colorama.just_fix_windows_console() - elif not shared_utils.is_linux(): - colorama.init(autoreset=True) + shared_utils.fix_colorama_if_windows() + colorama.init(autoreset=True) if sys.version_info[0] < 3 and "pdbp" in locals(): # With Python3, "import pdbp" is all you need diff --git a/seleniumbase/console_scripts/run.py b/seleniumbase/console_scripts/run.py index f8809f3dd92..57c15cb041d 100644 --- a/seleniumbase/console_scripts/run.py +++ b/seleniumbase/console_scripts/run.py @@ -41,6 +41,7 @@ import colorama import sys import time +from contextlib import suppress from seleniumbase.config import settings from seleniumbase.fixtures import constants from seleniumbase.fixtures import shared_utils @@ -99,6 +100,7 @@ def show_basic_usage(): sc += '│ * For info on all commands => "sbase --help" │\n' sc += "╰──────────────────────────────────────────────────╯" sc += "" + bordered_sc = sc if "linux" not in sys.platform: c1 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX c2 = colorama.Fore.BLUE + colorama.Back.LIGHTGREEN_EX @@ -110,6 +112,18 @@ def show_basic_usage(): sc = sc.replace("[COMMAND]", c3 + "[COMMAND]" + cr) sc = sc.replace("--help", c4 + "--help" + cr) sc = sc.replace("help", c4 + "help" + cr) + with suppress(Exception): + print(sc) + return + sc = bordered_sc.replace("╮\n", "") + sc = sc.replace("╭", "").replace("╮", "").replace("│", "") + sc = sc.replace("╰", "").replace("╯", "").replace("─", "") + if "linux" not in sys.platform: + sc = sc.replace("seleniumbase", c1 + "selenium" + c2 + "base" + cr) + sc = sc.replace("sbase", c1 + "s" + c2 + "base" + cr) + sc = sc.replace("[COMMAND]", c3 + "[COMMAND]" + cr) + sc = sc.replace("--help", c4 + "--help" + cr) + sc = sc.replace("help", c4 + "help" + cr) print(sc) diff --git a/seleniumbase/fixtures/shared_utils.py b/seleniumbase/fixtures/shared_utils.py index 578d2bab6c1..98092da4c1a 100644 --- a/seleniumbase/fixtures/shared_utils.py +++ b/seleniumbase/fixtures/shared_utils.py @@ -1,4 +1,5 @@ """Shared utility methods""" +import colorama import os import platform import sys @@ -67,6 +68,11 @@ def get_terminal_width(): return width +def fix_colorama_if_windows(): + if is_windows(): + colorama.just_fix_windows_console() + + def format_exc(exception, message): """Formats an exception message to make the output cleaner.""" from selenium.common.exceptions import ElementNotVisibleException From 0e6c7360257a55b93a6a030ccfa11f8f1007d30a Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Mon, 7 Oct 2024 00:20:00 -0400 Subject: [PATCH 2/2] Version 4.31.6 --- seleniumbase/__version__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seleniumbase/__version__.py b/seleniumbase/__version__.py index f5085aaef2b..4104caa2cc4 100755 --- a/seleniumbase/__version__.py +++ b/seleniumbase/__version__.py @@ -1,2 +1,2 @@ # seleniumbase package -__version__ = "4.31.5" +__version__ = "4.31.6"