Skip to content

Commit

Permalink
Merge pull request #3179 from seleniumbase/fix-console-output-on-windows
Browse files Browse the repository at this point in the history
Fix console output on Windows
  • Loading branch information
mdmintz authored Oct 7, 2024
2 parents f9e4f64 + 0e6c736 commit c5c3814
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
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

0 comments on commit c5c3814

Please sign in to comment.