當前位置: 首頁>>代碼示例>>Python>>正文


Python colorama.init方法代碼示例

本文整理匯總了Python中colorama.init方法的典型用法代碼示例。如果您正苦於以下問題:Python colorama.init方法的具體用法?Python colorama.init怎麽用?Python colorama.init使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在colorama的用法示例。


在下文中一共展示了colorama.init方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import colorama [as 別名]
# 或者: from colorama import init [as 別名]
def __init__(self, **kwargs):
        """Setup the initial set of output stream functions."""

        # Begins intercepting output and converting ANSI characters to win32 as applicable
        colorama.init()

        # Refactor this as an Output class
        self.__dict__['redirectErr'] = OutputRedirect(sys.stderr, self.handlePrint, LOG_TYPES[Level.VERBOSE])
        self.__dict__['redirectOut'] = OutputRedirect(sys.stdout, self.handlePrint, LOG_TYPES[Level.VERBOSE])

        # by default, dont steal output and print to console
        self.stealStdio(False)
        self.logToConsole(True)

        # Setattr wraps the output objects in a
        # decorator that allows this class to intercept their output, This dict holds the
        # original objects.
        self.__dict__['outputMappings'] = {}

        for name, func in six.iteritems(kwargs):
            setattr(self, name, func) 
開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:23,代碼來源:output.py

示例2: exe

# 需要導入模塊: import colorama [as 別名]
# 或者: from colorama import init [as 別名]
def exe(cmd, params):
    """This function runs after preprocessing of code. It actually executes commands with subprocess

    :param cmd: command to be executed with subprocess
    :param params: parameters passed before ` character, i.e. p`echo 1 which means print result of execution
    :return: result of execution. It may be either Result or InteractiveResult
    """

    global _colorama_intialized
    if _is_colorama_enabled() and not _colorama_intialized:
        _colorama_intialized = True
        colorama.init()

    if config.PRINT_ALL_COMMANDS:
        if _is_colorama_enabled():
            _print_stdout(Fore.GREEN + '>>> ' + cmd + Style.RESET_ALL)
        else:
            _print_stdout('>>> ' + cmd)

    if _is_param_set(params, _PARAM_INTERACTIVE):
        return _create_interactive_result(cmd, params)
    else:
        return _create_result(cmd, params) 
開發者ID:lamerman,項目名稱:shellpy,代碼行數:25,代碼來源:core.py

示例3: main

# 需要導入模塊: import colorama [as 別名]
# 或者: from colorama import init [as 別名]
def main() -> None:
    colorama.init()
    start_time = datetime.now()
    loop = asyncio.get_event_loop()

    tasks = [
        loop.create_task(get_outputs(host_info, COMMANDS))
        for host_info in HOSTS.items()
    ]

    loop.run_until_complete(asyncio.wait(tasks))

    for hostname, task in zip(HOSTS, tasks):
        outputs = task.result()
        print(f"Device {hostname}")
        for command, output in zip(COMMANDS, outputs):
            print(f"===== Output from command {command} =====")
            print(f"{output}\n")
        print(f"=" * 80)

    exec_time = (datetime.now() - start_time).total_seconds()
    print(colorama.Fore.GREEN + f"Summary: it took {exec_time:,.2f} seconds to run") 
開發者ID:dmfigol,項目名稱:network-programmability-stream,代碼行數:24,代碼來源:netdev-async.py

示例4: __init__

# 需要導入模塊: import colorama [as 別名]
# 或者: from colorama import init [as 別名]
def __init__(self, _args):
        """Initialize Class properties.

        Args:
            _args (namespace): The argparser args Namespace.
        """
        self.args = _args

        # properties
        self.app_path = os.getcwd()
        self.exit_code = 0
        self.ij = InstallJson()
        self.lj = LayoutJson()
        self.permutations = Permutations()
        self.tj = TcexJson()

        # initialize colorama
        c.init(autoreset=True, strip=False) 
開發者ID:ThreatConnect-Inc,項目名稱:tcex,代碼行數:20,代碼來源:bin.py

示例5: __init__

# 需要導入模塊: import colorama [as 別名]
# 或者: from colorama import init [as 別名]
def __init__(self, color=False, caching=False, reset=False):
        if color:
            colorama.init()
            cmd.Cmd.__init__(self, stdout=colorama.initialise.wrapped_stdout)
        else:
            cmd.Cmd.__init__(self)

        if platform.system() == "Windows":
            self.use_rawinput = False

        self.color = color
        self.caching = caching
        self.reset = reset

        self.fe = None
        self.repl = None
        self.tokenizer = Tokenizer()

        self.__intro()
        self.__set_prompt_path() 
開發者ID:wendlers,項目名稱:mpfshell,代碼行數:22,代碼來源:mpfshell.py

示例6: user_test

# 需要導入模塊: import colorama [as 別名]
# 或者: from colorama import init [as 別名]
def user_test(
    senna_path="",
    sent="",
    dep_model="",
    batch=False,
    stp_dir="",
    init=False,
    env=False,
    env_path="",
):

    if init:

        download_files()

    main(senna_path, sent, dep_model, batch, stp_dir) 
開發者ID:jawahar273,項目名稱:practNLPTools-lite,代碼行數:18,代碼來源:cli.py

示例7: cprint

# 需要導入模塊: import colorama [as 別名]
# 或者: from colorama import init [as 別名]
def cprint(type, msg, reset):
    colorama.init()
    message = {
        "action": Fore.YELLOW,
        "positive": Fore.GREEN + Style.BRIGHT,
        "info": Fore.YELLOW,
        "reset": Style.RESET_ALL,
        "red": Fore.RED,
        "white": Fore.WHITE,
        "green": Fore.GREEN,
        "yellow": Fore.YELLOW
    }
    style = message.get(type.lower())

    if type == "error":
        print("{0}\n[*] Error: {1}".format(Fore.RED + Style.BRIGHT, Style.RESET_ALL + Fore.WHITE + msg))
    else:
        print(style + msg, end="")
    if (reset == 1):
        print(Style.RESET_ALL) 
開發者ID:superhedgy,項目名稱:AttackSurfaceMapper,代碼行數:22,代碼來源:subhunter.py

示例8: cprint

# 需要導入模塊: import colorama [as 別名]
# 或者: from colorama import init [as 別名]
def cprint(type, msg, reset):
    colorama.init()
    message = {
        "action": Fore.YELLOW,
        "positive": Fore.GREEN + Style.BRIGHT,
        "info": Fore.YELLOW,
        "reset": Style.RESET_ALL,
        "red": Fore.RED,
        "white": Fore.WHITE,
        "green": Fore.GREEN,
        "yellow": Fore.YELLOW
    }
    style = message.get(type.lower())


# A resolver wrapper around dnslib.py 
開發者ID:superhedgy,項目名稱:AttackSurfaceMapper,代碼行數:18,代碼來源:subbrute.py

示例9: cprint

# 需要導入模塊: import colorama [as 別名]
# 或者: from colorama import init [as 別名]
def cprint(type, msg, reset):
    colorama.init()
    message = {
        "action": Fore.YELLOW,
        "positive": Fore.GREEN + Style.BRIGHT,
        "info": Fore.YELLOW,
        "reset": Style.RESET_ALL,
        "red": Fore.RED,
        "white": Fore.WHITE,
        "green": Fore.GREEN,
        "yellow": Fore.YELLOW
    }
    style = message.get(type.lower())

    if type == "error":
        print("{0}\n[*] Error: {1}".format(Fore.RED + Style.BRIGHT, Style.RESET_ALL + Fore.WHITE + msg))
    else:
        print(style + msg, end="")
    if reset == 1:
        print(Style.RESET_ALL)


# Print Results Function - 
開發者ID:superhedgy,項目名稱:AttackSurfaceMapper,代碼行數:25,代碼來源:asm.py

示例10: configure_loggers

# 需要導入模塊: import colorama [as 別名]
# 或者: from colorama import init [as 別名]
def configure_loggers():
    # first off, configure defaults
    # to enable the use of the logger
    # even before the init was executed.
    logger_config = copy.deepcopy(LOGGER)
    _configure_defaults(logger_config)

    if env.is_initialized():
        # init was already called
        # use the configuration file.
        _configure_from_file(logger_config)
    _set_loggers_verbosity(logger_config)
    logging.config.dictConfig(logger_config)

    global _lgr
    _lgr = logging.getLogger('cloudify.cli.main')

    # configuring events/logs loggers
    # (this will also affect local workflow loggers, which don't use
    # the get_events_logger method of this module)
    if is_use_colors():
        logs.EVENT_CLASS = ColorfulEvent
        # refactor this elsewhere if colorama is further used in CLI
        colorama.init(autoreset=True) 
開發者ID:cloudify-cosmo,項目名稱:cloudify-cli,代碼行數:26,代碼來源:logger.py

示例11: set_mode

# 需要導入模塊: import colorama [as 別名]
# 或者: from colorama import init [as 別名]
def set_mode(self, mode):
    """Set the mode of the worker.

    The mode SCRIPT_MODE should be used if this Worker is a driver that is being
    run as a Python script or interactively in a shell. It will print
    information about task failures.

    The mode WORKER_MODE should be used if this Worker is not a driver. It will
    not print information about tasks.

    The mode PYTHON_MODE should be used if this Worker is a driver and if you
    want to run the driver in a manner equivalent to serial Python for debugging
    purposes. It will not send remote function calls to the scheduler and will
    insead execute them in a blocking fashion.

    The mode SILENT_MODE should be used only during testing. It does not print
    any information about errors because some of the tests intentionally fail.

    args:
      mode: One of SCRIPT_MODE, WORKER_MODE, PYTHON_MODE, and SILENT_MODE.
    """
    self.mode = mode
    colorama.init() 
開發者ID:ray-project,項目名稱:ray-legacy,代碼行數:25,代碼來源:worker.py

示例12: run_function_on_all_workers

# 需要導入模塊: import colorama [as 別名]
# 或者: from colorama import init [as 別名]
def run_function_on_all_workers(self, function):
    """Run arbitrary code on all of the workers.

    This function will first be run on the driver, and then it will be exported
    to all of the workers to be run. It will also be run on any new workers that
    register later. If ray.init has not been called yet, then cache the function
    and export it later.

    Args:
      function (Callable): The function to run on all of the workers. It should
        not take any arguments. If it returns anything, its return values will
        not be used.
    """
    if self.mode not in [None, raylib.SCRIPT_MODE, raylib.SILENT_MODE, raylib.PYTHON_MODE]:
      raise Exception("run_function_on_all_workers can only be called on a driver.")
    # First run the function on the driver.
    function(self)
    # If ray.init has not been called yet, then cache the function and export it
    # when connect is called. Otherwise, run the function on all workers.
    if self.mode is None:
      self.cached_functions_to_run.append(function)
    else:
      self.export_function_to_run_on_all_workers(function) 
開發者ID:ray-project,項目名稱:ray-legacy,代碼行數:25,代碼來源:worker.py

示例13: message

# 需要導入模塊: import colorama [as 別名]
# 或者: from colorama import init [as 別名]
def message(
    *tokens: Token,
    end: str = "\n",
    sep: str = " ",
    fileobj: FileObj = sys.stdout,
    update_title: bool = False
) -> None:
    """ Helper method for error, warning, info, debug

    """
    if using_colorama():
        global _INITIALIZED
        if not _INITIALIZED:
            colorama.init()
            _INITIALIZED = True
    with_color, without_color = process_tokens(tokens, end=end, sep=sep)
    if CONFIG["record"]:
        _MESSAGES.append(without_color)
    if update_title and with_color:
        write_title_string(without_color, fileobj)
    to_write = with_color if config_color(fileobj) else without_color
    write_and_flush(fileobj, to_write) 
開發者ID:TankerHQ,項目名稱:python-cli-ui,代碼行數:24,代碼來源:__init__.py

示例14: init_logger

# 需要導入模塊: import colorama [as 別名]
# 或者: from colorama import init [as 別名]
def init_logger(log_requests=False):
    """ Initialize the logger """

    logger = logging.getLogger(__name__.split(".")[0])
    for handler in logger.handlers:  # pragma: no cover
        logger.removeHandler(handler)

    if os.name == "nt" and "colorama" in sys.modules:  # pragma: no cover
        colorama.init()

    formatter = coloredlogs.ColoredFormatter(fmt="%(asctime)s: %(message)s")
    handler = logging.StreamHandler(stream=sys.stdout)
    handler.setLevel(logging.DEBUG)
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    logger.setLevel(logging.DEBUG)
    logger.propagate = False

    if log_requests:
        requests.packages.urllib3.add_stderr_logger() 
開發者ID:SFDO-Tooling,項目名稱:CumulusCI,代碼行數:22,代碼來源:logger.py

示例15: main

# 需要導入模塊: import colorama [as 別名]
# 或者: from colorama import init [as 別名]
def main():
    link_data = parse_yaml()
    colorama.init()
    start_time = datetime.now()
    banner()
    user_name = parse_args()
    if not user_name:
        print_usage()
        exit(1)
    print_username(user_name)
    print_delimiter()

    for group, data in link_data.items():
        print_title(group)
        threads = []
        for site, url in data.items():
            t = Thread(target=run_thread, args=[url, site, user_name])
            t.start()
            threads.append(t)
        [th.join() for th in threads]
        print_separator()

    complete_time = datetime.now() - start_time
    print_exec_time(complete_time)
    print_finish() 
開發者ID:0xknown,項目名稱:Search4,代碼行數:27,代碼來源:search4.py


注:本文中的colorama.init方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。