Skip to content

Commit c5c3814

Browse files
authored
Merge pull request #3179 from seleniumbase/fix-console-output-on-windows
Fix console output on Windows
2 parents f9e4f64 + 0e6c736 commit c5c3814

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

seleniumbase/__init__.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@
2222

2323
with suppress(Exception):
2424
import colorama
25+
26+
with suppress(Exception):
2527
import pdbp # (Pdb+) --- Python Debugger Plus
2628

27-
is_windows = shared_utils.is_windows()
2829
with suppress(Exception):
29-
if is_windows and hasattr(colorama, "just_fix_windows_console"):
30-
colorama.just_fix_windows_console()
31-
elif not shared_utils.is_linux():
32-
colorama.init(autoreset=True)
30+
shared_utils.fix_colorama_if_windows()
31+
colorama.init(autoreset=True)
3332

3433
if sys.version_info[0] < 3 and "pdbp" in locals():
3534
# With Python3, "import pdbp" is all you need

seleniumbase/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.31.5"
2+
__version__ = "4.31.6"

seleniumbase/console_scripts/run.py

+14
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import colorama
4242
import sys
4343
import time
44+
from contextlib import suppress
4445
from seleniumbase.config import settings
4546
from seleniumbase.fixtures import constants
4647
from seleniumbase.fixtures import shared_utils
@@ -99,6 +100,7 @@ def show_basic_usage():
99100
sc += '│ * For info on all commands => "sbase --help" │\n'
100101
sc += "╰──────────────────────────────────────────────────╯"
101102
sc += ""
103+
bordered_sc = sc
102104
if "linux" not in sys.platform:
103105
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
104106
c2 = colorama.Fore.BLUE + colorama.Back.LIGHTGREEN_EX
@@ -110,6 +112,18 @@ def show_basic_usage():
110112
sc = sc.replace("[COMMAND]", c3 + "[COMMAND]" + cr)
111113
sc = sc.replace("--help", c4 + "--help" + cr)
112114
sc = sc.replace("help", c4 + "help" + cr)
115+
with suppress(Exception):
116+
print(sc)
117+
return
118+
sc = bordered_sc.replace("╮\n", "")
119+
sc = sc.replace("╭", "").replace("╮", "").replace("│", "")
120+
sc = sc.replace("╰", "").replace("╯", "").replace("─", "")
121+
if "linux" not in sys.platform:
122+
sc = sc.replace("seleniumbase", c1 + "selenium" + c2 + "base" + cr)
123+
sc = sc.replace("sbase", c1 + "s" + c2 + "base" + cr)
124+
sc = sc.replace("[COMMAND]", c3 + "[COMMAND]" + cr)
125+
sc = sc.replace("--help", c4 + "--help" + cr)
126+
sc = sc.replace("help", c4 + "help" + cr)
113127
print(sc)
114128

115129

seleniumbase/fixtures/shared_utils.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Shared utility methods"""
2+
import colorama
23
import os
34
import platform
45
import sys
@@ -67,6 +68,11 @@ def get_terminal_width():
6768
return width
6869

6970

71+
def fix_colorama_if_windows():
72+
if is_windows():
73+
colorama.just_fix_windows_console()
74+
75+
7076
def format_exc(exception, message):
7177
"""Formats an exception message to make the output cleaner."""
7278
from selenium.common.exceptions import ElementNotVisibleException

0 commit comments

Comments
 (0)