def test_load_unload(self): """ Load/Unload DLL without raising an error """ # Make sure we're not already loaded self.assertFalse(ansicon.loaded()) # Test print print('\n') print(u'\x1b[32m UNLOADED \x1b[m') # Load without error ansicon.load() self.assertTrue(ansicon.loaded()) # Test print print(u'\x1b[32m LOADED \x1b[m') # Make sure loading again doesn't throw an error ansicon.load() # unload without error ansicon.unload() self.assertFalse(ansicon.loaded()) # Test print print(u'\x1b[32m UNLOADED \x1b[m') # Make sure unloading again doesn't throw an error ansicon.unload()
def get_term(fd, fallback=True): # pylint: disable=invalid-name """ Attempt to determine and enable terminal If fallback is True, the fallback will be enabled when no other terminal can be determined """ # First try TERM term = os.environ.get('TERM', None) if term is None: # See if ansicon is enabled if os.environ.get('ANSICON', None): term = 'ansicon' # See if Windows Terminal is being used elif os.environ.get('WT_SESSION', None): term = 'vtwin10' # See if the version of Windows supports VTMODE elif VTMODE_SUPPORTED: try: filehandle = msvcrt.get_osfhandle(fd) mode = get_console_mode(filehandle) except OSError: term = 'unknown' else: atexit.register(flush_and_set_console, fd, mode) set_console_mode(filehandle, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING) term = 'vtwin10' # Currently falling back to Ansicon for older versions of Windows elif fallback: import ansicon # pylint: disable=import-error,import-outside-toplevel ansicon.load() try: filehandle = msvcrt.get_osfhandle(fd) mode = get_console_mode(filehandle) except OSError: term = 'unknown' else: atexit.register(flush_and_set_console, fd, mode) set_console_mode(filehandle, mode ^ ENABLE_WRAP_AT_EOL_OUTPUT) term = 'ansicon' else: term = 'unknown' return term
def test_unload_fail(self): """ Raise an Error when operation fails """ # Load and capture handle ansicon.load() old_dll = ansicon._ANSICON.dll # pylint: disable=protected-access # Unload ansicon.unload() # Force failure with old handle ansicon._ANSICON.dll = old_dll # pylint: disable=protected-access with self.assertRaises(WindowsError): # pylint: disable=undefined-variable ansicon.unload()
def __init__(self, kind=None, stream=None, force_styling=False): if stream is None: stream = sys.__stdout__ try: stream_fd = (stream.fileno() if hasattr(stream, 'fileno') and callable(stream.fileno) else None) except io.UnsupportedOperation: stream_fd = None self.stream = stream self.stream_fd = stream_fd self.stream_fh = msvcrt.get_osfhandle(self.stream_fd) # Use built-in virtual terminal processing for Windows 10.0.10586 and newer if tuple(int(num) for num in platform.version().split('.')) >= (10, 0, 10586): enable_vt_mode(self.stream_fh) else: # Use ansicon for older versions of Windows import ansicon # pylint: disable=import-error ansicon.load()
import sys import re import os import ffmpeg import enlighten from .utils import get_bitdepth if sys.platform == 'win32': import wexpect as expect # patch windows consloe for scale correctly characters import ansicon ansicon.load() else: import pexpect as expect __version__ = '0.1.10' pattern_duration = re.compile('duration[ \t\r]?:[ \t\r]?(.+?),[ \t\r]?start', re.IGNORECASE) pattern_progress = re.compile('time=(.+?)[ \t\r]?bitrate', re.IGNORECASE) BAR_FMT = u'{desc}{desc_pad}{percentage:3.0f}%|{bar}| {count:{len_total}.1f}/{total:.1f} ' + \ u'[{elapsed}<{eta}, {rate:.2f}{unit_pad}{unit}/s]' COUNTER_FMT = u'{desc}{desc_pad}{count:.1f} {unit}{unit_pad}' + \ u'[{elapsed}, {rate:.2f}{unit_pad}{unit}/s]{fill}' CONVERT_COMMAND_10Bits = 'ffmpeg -progress pipe:1 -i "{source}" -map 0 -map -v -map V -c:v libx265 -x265-params crf=26:profile=main10 -c:a aac -y "{dest}"' CONVERT_COMMAND = 'ffmpeg -progress pipe:1 -i "{source}" -map 0 -map -v -map V -c:v libx265 -crf 26 -c:a aac -y "{dest}"' def convert_file(source: str, dest: str): stream = ffmpeg.input(source)
def opçoes(self): ansicon.load() print(f'\033[1;32m\nAcertar : {dinheiros[self.rodada][0]}') print(f'\033[1;31mParar : {dinheiros[self.rodada][1]}') print(f'\033[1;31mErrar : {dinheiros[self.rodada][2]}') ansicon.unload()
def get_term(fd, fallback=True): # pylint: disable=invalid-name """ Args: fd(int): Python file descriptor fallback(bool): Use fallback terminal type if type can not be determined Returns: str: Terminal type Attempts to determine and enable the current terminal type The current logic is: - If TERM is defined in the environment, the value is returned - Else, if ANSICON is defined in the environment, ``'ansicon'`` is returned - Else, if virtual terminal mode is natively supported, it is enabled and ``'vtwin10'`` is returned - Else, if ``fallback`` is ``True``, Ansicon is loaded, and ``'ansicon'`` is returned - If no other conditions are satisfied, ``'unknown'`` is returned This logic may change in the future as additional terminal types are added. """ # First try TERM term = os.environ.get('TERM', None) if term is None: # See if ansicon is enabled if os.environ.get('ANSICON', None): term = 'ansicon' # See if Windows Terminal is being used elif os.environ.get('WT_SESSION', None): term = 'vtwin10' # See if the version of Windows supports VTMODE elif VTMODE_SUPPORTED: try: filehandle = msvcrt.get_osfhandle(fd) mode = get_console_mode(filehandle) except OSError: term = 'unknown' else: atexit.register(flush_and_set_console, fd, mode) # pylint: disable=unsupported-binary-operation set_console_mode(filehandle, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING) term = 'vtwin10' # Currently falling back to Ansicon for older versions of Windows elif fallback: import ansicon # pylint: disable=import-error,import-outside-toplevel ansicon.load() try: filehandle = msvcrt.get_osfhandle(fd) mode = get_console_mode(filehandle) except OSError: term = 'unknown' else: atexit.register(flush_and_set_console, fd, mode) set_console_mode(filehandle, mode ^ ENABLE_WRAP_AT_EOL_OUTPUT) term = 'ansicon' else: term = 'unknown' return term