mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-01 11:06:04 +08:00
mavsdk_tests: split up Python script
Otherwise, the script will get a tangled mess.
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import re
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
def supports_color():
|
||||
"""Returns True if the running system's terminal supports color.
|
||||
|
||||
From https://stackoverflow.com/a/22254892/8548472
|
||||
"""
|
||||
plat = sys.platform
|
||||
supported_platform = plat != 'Pocket PC' and (plat != 'win32' or
|
||||
'ANSICON' in os.environ)
|
||||
# isatty is not always implemented, #6223.
|
||||
is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
|
||||
return supported_platform and is_a_tty
|
||||
|
||||
|
||||
if supports_color():
|
||||
class color:
|
||||
PURPLE = '\033[95m'
|
||||
CYAN = '\033[96m'
|
||||
DARKCYAN = '\033[36m'
|
||||
BLUE = '\033[94m'
|
||||
GREEN = '\033[92m'
|
||||
YELLOW = '\033[93m'
|
||||
RED = '\033[91m'
|
||||
BOLD = '\033[1m'
|
||||
UNDERLINE = '\033[4m'
|
||||
END = '\033[0m'
|
||||
else:
|
||||
class color:
|
||||
PURPLE = ''
|
||||
CYAN = ''
|
||||
DARKCYAN = ''
|
||||
BLUE = ''
|
||||
GREEN = ''
|
||||
YELLOW = ''
|
||||
RED = ''
|
||||
BOLD = ''
|
||||
UNDERLINE = ''
|
||||
END = ''
|
||||
|
||||
|
||||
def remove_color(text):
|
||||
"""Remove ANSI and xterm256 color codes.
|
||||
|
||||
From https://stackoverflow.com/a/30500866/8548472
|
||||
"""
|
||||
return re.sub(r'\x1b(\[.*?[@-~]|\].*?(\x07|\x1b\\))', '', text)
|
||||
Reference in New Issue
Block a user