Skip to content

Fix console output on Windows #3179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions seleniumbase/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion seleniumbase/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.31.5"
__version__ = "4.31.6"
14 changes: 14 additions & 0 deletions seleniumbase/console_scripts/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)


Expand Down
6 changes: 6 additions & 0 deletions seleniumbase/fixtures/shared_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Shared utility methods"""
import colorama
import os
import platform
import sys
Expand Down Expand Up @@ -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
Expand Down